KISSY.Editor.add("indent/support",function(){function o(e){this.type=e;this.indentCssProperty="margin-left";this.indentOffset=40;this.indentUnit="px"}function p(e){return e[0].nodeType==k.NODE_ELEMENT&&e._4e_name()=="li"}function v(e,a){for(var c=e.startContainer,b=e.endContainer;c&&!c.parent()._4e_equals(a);)c=c.parent();for(;b&&!b.parent()._4e_equals(a);)b=b.parent();if(c&&b){var d=c;c=[];for(var f=false;!f;){if(d._4e_equals(b))f=true;c.push(d);d=d.next()}if(!(c.length<1)){d=a._4e_parents(true);
for(b=0;b<d.length;b++)if(i[d[b]._4e_name()]){a=d[b];break}d=this.type=="indent"?1:-1;b=c[0];f=c[c.length-1];c={};var g=j.ListUtils.listToArray(a,c),w=g[f.data("listarray_index")].indent;for(b=b.data("listarray_index");b<=f.data("listarray_index");b++){g[b].indent+=d;var q=g[b].parent;g[b].parent=new r(q[0].ownerDocument.createElement(q._4e_name()))}for(b=f.data("listarray_index")+1;b<g.length&&g[b].indent>w;b++)g[b].indent+=d;f=j.ListUtils.arrayToList(g,c,null,"p",0);d=[];if(this.type=="outdent"){var n;
if((n=a.parent())&&n._4e_name()=="li"){g=f.listNode.childNodes;var h;for(b=g.length-1;b>=0;b--)if((h=new r(g[b]))&&h._4e_name()=="li")d.push(h)}}if(f){s.insertBefore(f.listNode,a);a._4e_remove()}if(d&&d.length)for(b=0;b<d.length;b++){for(f=h=d[b];(f=f.next())&&f._4e_name()in i;){x.ie&&!h._4e_first(function(t){return y(t)&&z(t)})&&h[0].appendChild(e.document.createTextNode("\u00a0"));h[0].appendChild(f[0])}s.insertAfter(h[0],n[0])}j.Utils.clearAllMarkers(c)}}}function u(e){var a=parseInt(e._4e_style(this.indentCssProperty),
10);if(isNaN(a))a=0;a+=(this.type=="indent"?1:-1)*this.indentOffset;if(a<0)return false;a=Math.max(a,0);a=Math.ceil(a/this.indentOffset)*this.indentOffset;e.css(this.indentCssProperty,a?a+this.indentUnit:"");e[0].style.cssText===""&&e.removeAttr("style");return true}var j=KISSY.Editor,i={ol:1,ul:1},l=KISSY,m=j.Walker,s=l.DOM,r=l.Node,x=l.UA,k=j.NODE,y=m.whitespaces(true),z=m.bookmark(false,true);l.augment(o,{exec:function(e){for(var a=(e=e.getSelection())&&e.getRanges()[0],c=a.startContainer,b=a.endContainer,
d=a.getCommonAncestor();d&&!(d[0].nodeType==k.NODE_ELEMENT&&i[d._4e_name()]);)d=d.parent();if(d&&c[0].nodeType==k.NODE_ELEMENT&&c._4e_name()in i){c=new m(a);c.evaluator=p;a.startContainer=c.next()}if(d&&b[0].nodeType==k.NODE_ELEMENT&&b._4e_name()in i){c=new m(a);c.evaluator=p;a.endContainer=c.previous()}b=e.createBookmarks(true);if(d){for(c=d._4e_first();c&&c._4e_name()!="li";)c=c.next();var f=a.startContainer;(c[0]==f[0]||c.contains(f))&&u.call(this,d)||v.call(this,a,d)}else{a=a.createIterator();
a.enforceRealBlocks=true;for(a.enlargeBr=true;d=a.getNextParagraph();)u.call(this,d)}e.selectBookmarks(b)}});j.IndentSupport={init:function(){this.indentCommand=new o(this.cfg.type)},offClick:function(){var e=this,a=e.editor;a.fire("save");setTimeout(function(){e.indentCommand.exec(a);a.fire("save");a.notifySelectionChange()},10)},selectionChange:function(e){if(this.cfg.type=="outdent"){var a=e.path,c=a.blockLimit;e=this.btn;if(a.contains(i))e.boff();else(a=a.block||c)&&a._4e_style(this.indentCommand.indentCssProperty)?
e.boff():e.disable()}}}},{attach:false});
