/*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("editor-para",function(a){var d=function(){d.superclass.constructor.apply(this,arguments);},k="host",f="body",c="nodeChange",j="parentNode",b=f+" > p",h="p",g="<br>",i="firstChild",e="li";a.extend(d,a.Plugin.EditorParaBase,{_onNodeChange:function(R){var F=this.get(k),q=F.getInstance(),x,D,C,T,O,H=q.EditorSelection.DEFAULT_BLOCK_TAG,z,o,s,P,v,l,G,M,u,N,V,S,J,B,A,Q=":last-child";switch(R.changedType){case"enter-up":var m=((this._lastPara)?this._lastPara:R.changedNode),U=m.one("br.yui-cursor");if(this._lastPara){delete this._lastPara;}if(U){if(U.previous()||U.next()){if(U.ancestor(h)){U.remove();}}}if(!m.test(H)){var E=m.ancestor(H);if(E){m=E;E=null;}}if(m.test(H)){var I=m.previous(),L,w,y=false;if(I){L=I.one(Q);while(!y){if(L){w=L.one(Q);if(w){L=w;}else{y=true;}}else{y=true;}}if(L){F.copyStyles(L,m);}}}break;case"enter":if(a.UA.webkit){if(R.changedEvent.shiftKey){F.execCommand("insertbr");R.changedEvent.preventDefault();}}if(R.changedNode.test("li")&&!a.UA.ie){x=q.EditorSelection.getText(R.changedNode);if(x===""){C=R.changedNode.ancestor("ol,ul");var K=C.getAttribute("dir");if(K!==""){K=' dir = "'+K+'"';}C=R.changedNode.ancestor(q.EditorSelection.BLOCKS);T=q.Node.create("<p"+K+">"+q.EditorSelection.CURSOR+"</p>");C.insert(T,"after");R.changedNode.remove();R.changedEvent.halt();O=new q.EditorSelection();O.selectNode(T,true,false);}}if(a.UA.gecko&&F.get("defaultblock")!=="p"){C=R.changedNode;if(!C.test(e)&&!C.ancestor(e)){if(!C.test(H)){C=C.ancestor(H);}T=q.Node.create("<"+H+"></"+H+">");C.insert(T,"after");O=new q.EditorSelection();if(O.anchorOffset){z=O.anchorNode.get("textContent");D=q.one(q.config.doc.createTextNode(z.substr(0,O.anchorOffset)));o=q.one(q.config.doc.createTextNode(z.substr(O.anchorOffset)));P=O.anchorNode;P.setContent("");l=P.cloneNode();l.append(o);G=false;u=P;while(!G){u=u.get(j);if(u&&!u.test(H)){M=u.cloneNode();M.set("innerHTML","");M.append(l);s=u.get("childNodes");var r=false;s.each(function(n){if(r){M.append(n);}if(n===P){r=true;}});P=u;l=M;}else{G=true;}}o=l;O.anchorNode.append(D);if(o){T.append(o);}}if(T.get(i)){T=T.get(i);}T.prepend(q.EditorSelection.CURSOR);O.focusCursor(true,true);x=q.EditorSelection.getText(T);if(x!==""){q.EditorSelection.cleanCursor();}R.changedEvent.preventDefault();}}break;case"keyup":if(a.UA.gecko){if(q.config.doc&&q.config.doc.body&&q.config.doc.body.innerHTML.length<20){if(!q.one(b)){this._fixFirstPara();}}}break;case"backspace-up":case"backspace-down":case"delete-up":if(!a.UA.ie){N=q.all(b);S=q.one(f);if(N.item(0)){S=N.item(0);}V=S.one("br");if(V){V.removeAttribute("id");V.removeAttribute("class");}D=q.EditorSelection.getText(S);D=D.replace(/ /g,"").replace(/\n/g,"");B=S.all("img");if(D.length===0&&!B.size()){if(!S.test(h)){this._fixFirstPara();}J=null;if(R.changedNode&&R.changedNode.test(h)){J=R.changedNode;}if(!J&&F._lastPara&&F._lastPara.inDoc()){J=F._lastPara;}if(J&&!J.test(h)){J=J.ancestor(h);}if(J){if(!J.previous()&&J.get(j)&&J.get(j).test(f)){R.changedEvent.frameEvent.halt();R.preventDefault();}}}if(a.UA.webkit){if(R.changedNode){R.preventDefault();S=R.changedNode;if(S.test("li")&&(!S.previous()&&!S.next())){x=S.get("innerHTML").replace(g,"");if(x===""){if(S.get(j)){S.get(j).replace(q.Node.create(g));R.changedEvent.frameEvent.halt();q.EditorSelection.filterBlocks();}}}}}}if(a.UA.gecko){T=R.changedNode;A=q.config.doc.createTextNode(" ");T.appendChild(A);T.removeChild(A);}break;}if(a.UA.gecko){if(R.changedNode&&!R.changedNode.test(H)){J=R.changedNode.ancestor(H);if(J){this._lastPara=J;}}}},initializer:function(){var l=this.get(k);if(l.editorBR){a.error("Can not plug EditorPara and EditorBR at the same time.");return;}l.on(c,a.bind(this._onNodeChange,this));}},{NAME:"editorPara",NS:"editorPara",ATTRS:{host:{value:false}}});a.namespace("Plugin");a.Plugin.EditorPara=d;},"3.5.1",{skinnable:false,requires:["editor-base"]});