KISSY.Editor.add("domiterator",function(n){function v(t){if(!(arguments.length<1)){this.range=t;this.forceBrBreak=j;this.enlargeBr=e;this.enforceRealBlocks=j;this._||(this._={})}}var e=true,j=false,o=KISSY,y=o.UA,r=n.Walker,s=n.Range,g=n.RANGE,p=n.NODE,w=n.ElementPath,q=o.Node,u=o.DOM,z=/^[\r\n\t ]*$/;o.augment(v,{getNextParagraph:function(t){var c,a,h,f,m;if(!this._.lastNode){a=this.range.clone();a.shrink(g.SHRINK_ELEMENT,e);a.enlarge(this.forceBrBreak||!this.enlargeBr?g.ENLARGE_LIST_ITEM_CONTENTS:
g.ENLARGE_BLOCK_CONTENTS);var d=new r(a),b=r.bookmark(e,e);d.evaluator=b;this._.nextNode=d.next();d=new r(a);d.evaluator=b;d=d.previous();this._.lastNode=d._4e_nextSourceNode(e);if(this._.lastNode&&this._.lastNode[0].nodeType==p.NODE_TEXT&&!o.trim(this._.lastNode[0].nodeValue)&&this._.lastNode.parent()._4e_isBlockBoundary()){b=new s(a.document);b.moveToPosition(this._.lastNode,g.POSITION_AFTER_END);if(b.checkEndOfBlock()){b=new w(b.endContainer);this._.lastNode=(b.block||b.blockLimit)._4e_nextSourceNode(e)}}if(!this._.lastNode){this._.lastNode=
this._.docEndMarker=new q(a.document.createTextNode(""));u.insertAfter(this._.lastNode[0],d[0])}a=null}b=this._.nextNode;d=this._.lastNode;for(this._.nextNode=null;b;){var k=j,i=b[0].nodeType!=p.NODE_ELEMENT,x=j;if(i){if(b[0].nodeType==p.NODE_TEXT)if(z.test(b[0].nodeValue))i=j}else{var l=b._4e_name();if(b._4e_isBlockBoundary(this.forceBrBreak&&{br:1})){if(l=="br")i=e;else if(!a&&!b[0].childNodes.length&&l!="hr"){c=b;h=b._4e_equals(d);break}if(a){a.setEndAt(b,g.POSITION_BEFORE_START);if(l!="br")this._.nextNode=
b}k=e}else{if(b[0].firstChild){if(!a){a=new s(this.range.document);a.setStartAt(b,g.POSITION_BEFORE_START)}b=new q(b[0].firstChild);continue}i=e}}if(i&&!a){a=new s(this.range.document);a.setStartAt(b,g.POSITION_BEFORE_START)}h=(!k||i)&&b._4e_equals(d);if(a&&!k)for(;!b[0].nextSibling&&!h;){l=b.parent();if(l._4e_isBlockBoundary(this.forceBrBreak&&{br:1})){k=e;h||l._4e_equals(d);break}b=l;i=e;h=b._4e_equals(d);x=e}i&&a.setEndAt(b,g.POSITION_AFTER_END);b=b._4e_nextSourceNode(x,null,d);if((h=!b)||k&&a)break}if(!c){if(!a){this._.docEndMarker&&
this._.docEndMarker._4e_remove();return this._.nextNode=null}c=new w(a.startContainer);b=c.blockLimit;k={div:1,th:1,td:1};c=c.block;if((!c||!c[0])&&!this.enforceRealBlocks&&k[b._4e_name()]&&a.checkStartOfBlock()&&a.checkEndOfBlock())c=b;else if(!c||this.enforceRealBlocks&&c._4e_name()=="li"){c=new q(this.range.document.createElement(t||"p"));c[0].appendChild(a.extractContents());c._4e_trim();a.insertNode(c);f=m=e}else if(c._4e_name()!="li"){if(!a.checkStartOfBlock()||!a.checkEndOfBlock()){c=c._4e_clone(j);
c[0].appendChild(a.extractContents());c._4e_trim();m=a.splitBlock();f=!m.wasStartOfBlock;m=!m.wasEndOfBlock;a.insertNode(c)}}else if(!h)this._.nextNode=c._4e_equals(d)?null:a.getBoundaryNodes().endNode._4e_nextSourceNode(e,null,d)}if(f){a=new q(c[0].previousSibling);if(a[0]&&a[0].nodeType==p.NODE_ELEMENT)if(a._4e_name()=="br")a._4e_remove();else a[0].lastChild&&u._4e_name(a[0].lastChild)=="br"&&u._4e_remove(a[0].lastChild)}if(m){a=r.bookmark(j,e);f=new q(c[0].lastChild);if(f[0]&&f[0].nodeType==p.NODE_ELEMENT&&
f._4e_name()=="br")if(y.ie||f._4e_previous(a)||f._4e_next(a))f._4e_remove()}if(!this._.nextNode)this._.nextNode=h||c._4e_equals(d)?null:c._4e_nextSourceNode(e,null,d);return c}});s.prototype.createIterator=function(){return new v(this)}});
