/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/plugin/listUtils/index",function(o){var p={ol:1,ul:1},n=o.Node,f=o.DOM,r=o.UA,q={listToArray:function(b,m,g,j,l){if(!p[b.nodeName()])return[];j||(j=0);g||(g=[]);for(var k=0,c=b[0].childNodes.length;k<c;k++){var d=new n(b[0].childNodes[k]);if("li"==d.nodeName()){var h={parent:b,indent:j,element:d,contents:[]};l?h.grandparent=l:(h.grandparent=b.parent(),h.grandparent&&"li"==h.grandparent.nodeName()&&(h.grandparent=h.grandparent.parent()));m&&d._4e_setMarker(m,"listarray_index",g.length,
void 0);g.push(h);for(var a=0,e=d[0].childNodes.length,i;a<e;a++)i=new n(d[0].childNodes[a]),i[0].nodeType==f.ELEMENT_NODE&&p[i.nodeName()]?q.listToArray(i,m,g,j+1,h.grandparent):h.contents.push(i)}}return g},arrayToList:function(b,m,g,j){g||(g=0);if(!b||b.length<g+1)return null;for(var l=b[g].parent[0].ownerDocument,k=l.createDocumentFragment(),c=null,d=g,h=Math.max(b[g].indent,0),a=null;;){var e=b[d];if(e.indent==h){if(!c||b[d].parent.nodeName()!=c.nodeName())c=b[d].parent.clone(!1),k.appendChild(c[0]);
for(var a=c[0].appendChild(e.element.clone(!1)[0]),i=0;i<e.contents.length;i++)a.appendChild(e.contents[i].clone(!0)[0]);d++}else if(e.indent==Math.max(h,0)+1)d=q.arrayToList(b,null,d,j),a.appendChild(d.listNode),d=d.nextIndex;else if(-1==e.indent&&!g&&e.grandparent){p[e.grandparent.nodeName()]?a=e.element.clone(!1)[0]:"td"!=e.grandparent.nodeName()?(a=l.createElement(j),e.element._4e_copyAttributes(new n(a))):a=l.createDocumentFragment();for(i=0;i<e.contents.length;i++)c=e.contents[i].clone(!0),
a.nodeType==f.DOCUMENT_FRAGMENT_NODE&&e.element._4e_copyAttributes(new n(c)),a.appendChild(c[0]);a.nodeType==f.DOCUMENT_FRAGMENT_NODE&&d!=b.length-1&&(a.lastChild&&a.lastChild.nodeType==f.ELEMENT_NODE&&"_moz"==a.lastChild.getAttribute("type")&&f._4e_remove(a.lastChild),f._4e_appendBogus(a));a.nodeType==f.ELEMENT_NODE&&f.nodeName(a)==j&&a.firstChild&&(f._4e_trim(a),c=a.firstChild,c.nodeType==f.ELEMENT_NODE&&f._4e_isBlockBoundary(c)&&(c=l.createDocumentFragment(),f._4e_moveChildren(a,c),a=c));c=f.nodeName(a);
!r.ie&&("div"==c||"p"==c)&&f._4e_appendBogus(a);k.appendChild(a);c=null;d++}else return null;if(b.length<=d||Math.max(b[d].indent,0)<h)break}if(m)for(b=new n(k.firstChild);b&&b[0];)b[0].nodeType==f.ELEMENT_NODE&&b._4e_clearMarkers(m,!0),b=b._4e_nextSourceNode();return{listNode:k,nextIndex:d}}};return q},{requires:["editor"]});
