/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.2.0
build: nightly
*/
YUI.add("editor-para",function(F){var C=function(){C.superclass.constructor.apply(this,arguments);},B="host",D="body",A="nodeChange",E=D+" > p";F.extend(C,F.Base,{_fixFirstPara:function(){var G=this.get(B),I=G.getInstance(),H;I.one("body").setContent("<p>"+I.Selection.CURSOR+"</p>");H=new I.Selection();H.focusCursor(true,false);},_onNodeChange:function(L){var J=this.get(B),K=J.getInstance();switch(L.changedType){case"keydown":if(K.config.doc.childNodes.length<2){var G=K.config.doc.body.innerHTML;if(G&&G.length<5&&G.toLowerCase()=="<br>"){this._fixFirstPara();}}break;case"backspace-up":case"delete-up":var M=K.all(E),H,I;if(M.size()<2){I=K.one(D);if(M.item(0)){I=M.item(0);}if(K.Selection.getText(I)===""&&!I.test("p")){this._fixFirstPara();}else{if(I.test("p")&&I.get("innerHTML").length===0){L.changedEvent.halt();}}}break;}},_afterEditorReady:function(){var G=this.get(B),H=G.getInstance();if(H){H.Selection.filterBlocks();}},_afterContentChange:function(){var G=this.get(B),H=G.getInstance();if(H&&H.Selection){H.Selection.filterBlocks();}},_afterPaste:function(){var G=this.get(B),I=G.getInstance(),H=new I.Selection();H.setCursor();F.later(50,G,function(){I.Selection.filterBlocks();H.focusCursor(true,true);});},initializer:function(){var G=this.get(B);G.on(A,F.bind(this._onNodeChange,this));G.after("ready",F.bind(this._afterEditorReady,this));G.after("contentChange",F.bind(this._afterContentChange,this));G.after("dom:paste",F.bind(this._afterPaste,this));}},{NAME:"editorPara",NS:"editorPara",ATTRS:{host:{value:false}}});F.namespace("Plugin");F.Plugin.EditorPara=C;},"3.2.0",{skinnable:false,requires:["editor-base","selection"]});