/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/core/domIterator",function(n){function o(f){1>arguments.length||(this.range=f,this.forceBrBreak=k,this.enlargeBr=e,this.enforceRealBlocks=k,this._||(this._={}))}var e=!0,k=!1,p=n.Editor,v=n.UA,s=p.Walker,t=p.Range,f=p.RANGE,u=p.ElementPath,r=n.Node,h=n.DOM,w=/^[\r\n\t ]*$/;n.augment(o,{getNextParagraph:function(p){var c,a,i,g,q;if(!this._.lastNode){a=this.range.clone();a.shrink(f.SHRINK_ELEMENT,e);a.enlarge(this.forceBrBreak||!this.enlargeBr?f.ENLARGE_LIST_ITEM_CONTENTS:f.ENLARGE_BLOCK_CONTENTS);
var d=new s(a),b=s.bookmark(e,e);d.evaluator=b;this._.nextNode=d.next();d=new s(a);d.evaluator=b;d=d.previous();this._.lastNode=d._4e_nextSourceNode(e);this._.lastNode&&this._.lastNode[0].nodeType==h.TEXT_NODE&&!n.trim(this._.lastNode[0].nodeValue)&&this._.lastNode.parent()._4e_isBlockBoundary()&&(b=new t(a.document),b.moveToPosition(this._.lastNode,f.POSITION_AFTER_END),b.checkEndOfBlock()&&(b=new u(b.endContainer),this._.lastNode=(b.block||b.blockLimit)._4e_nextSourceNode(e)));this._.lastNode||
(this._.lastNode=this._.docEndMarker=new r(a.document.createTextNode("")),h.insertAfter(this._.lastNode[0],d[0]));a=null}b=this._.nextNode;d=this._.lastNode;for(this._.nextNode=null;b;){var l=k,j=b[0].nodeType!=h.ELEMENT_NODE,o=k;if(j)b[0].nodeType==h.TEXT_NODE&&w.test(b[0].nodeValue)&&(j=k);else{var m=b.nodeName();if(b._4e_isBlockBoundary(this.forceBrBreak&&{br:1})){if("br"==m)j=e;else if(!a&&!b[0].childNodes.length&&"hr"!=m){c=b;i=b.equals(d);break}a&&(a.setEndAt(b,f.POSITION_BEFORE_START),"br"!=
m&&(this._.nextNode=b));l=e}else{if(b[0].firstChild){a||(a=new t(this.range.document),a.setStartAt(b,f.POSITION_BEFORE_START));b=new r(b[0].firstChild);continue}j=e}}j&&!a&&(a=new t(this.range.document),a.setStartAt(b,f.POSITION_BEFORE_START));i=(!l||j)&&b.equals(d);if(a&&!l)for(;!b[0].nextSibling&&!i;){m=b.parent();if(m._4e_isBlockBoundary(this.forceBrBreak&&{br:1})){l=e;i||m.equals(d);break}b=m;j=e;i=b.equals(d);o=e}j&&a.setEndAt(b,f.POSITION_AFTER_END);b=b._4e_nextSourceNode(o,null,d);if((i=!b)||
l&&a)break}if(!c){if(!a)return this._.docEndMarker&&this._.docEndMarker._4e_remove(),this._.nextNode=null;c=new u(a.startContainer);b=c.blockLimit;l={div:1,th:1,td:1};c=c.block;if((!c||!c[0])&&!this.enforceRealBlocks&&l[b.nodeName()]&&a.checkStartOfBlock()&&a.checkEndOfBlock())c=b;else if(!c||this.enforceRealBlocks&&"li"==c.nodeName())c=new r(this.range.document.createElement(p||"p")),c[0].appendChild(a.extractContents()),c._4e_trim(),a.insertNode(c),g=q=e;else if("li"!=c.nodeName()){if(!a.checkStartOfBlock()||
!a.checkEndOfBlock())c=c.clone(k),c[0].appendChild(a.extractContents()),c._4e_trim(),q=a.splitBlock(),g=!q.wasStartOfBlock,q=!q.wasEndOfBlock,a.insertNode(c)}else i||(this._.nextNode=c.equals(d)?null:a.getBoundaryNodes().endNode._4e_nextSourceNode(e,null,d))}g&&(a=new r(c[0].previousSibling),a[0]&&a[0].nodeType==h.ELEMENT_NODE&&("br"==a.nodeName()?a._4e_remove():a[0].lastChild&&"br"==h.nodeName(a[0].lastChild)&&h._4e_remove(a[0].lastChild)));q&&(a=s.bookmark(k,e),g=new r(c[0].lastChild),g[0]&&g[0].nodeType==
h.ELEMENT_NODE&&"br"==g.nodeName()&&(v.ie||g.prev(a,1)||g.next(a,1))&&g.remove());this._.nextNode||(this._.nextNode=i||c.equals(d)?null:c._4e_nextSourceNode(e,null,d));return c}});t.prototype.createIterator=function(){return new o(this)};return o},{requires:["./base","./range","./elementPath","./walker"]});
