]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/editor/editor-para-min.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / editor / editor-para-min.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 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.Base,{_fixFirstPara:function(){var L=this.get(K),N=L.getInstance(),M;N.one("body").set("innerHTML","<"+H+">"+N.Selection.CURSOR+"</"+H+">");var O=N.one(B);M=new N.Selection();M.selectNode(O,true,false);},_onNodeChange:function(u){var g=this.get(K),P=g.getInstance(),V,c,a,w,q,i=P.Selection.DEFAULT_BLOCK_TAG,X,N,R,r,T,L,h,m,S,o,y,v,k,Z,Y,s=":last-child";switch(u.changedType){case"enter-up":var M=((this._lastPara)?this._lastPara:u.changedNode),x=M.one("br.yui-cursor");if(this._lastPara){delete this._lastPara;}if(x){if(x.previous()||x.next()){x.remove();}}if(!M.test(i)){var f=M.ancestor(i);if(f){M=f;f=null;}}if(M.test(i)){var j=M.previous(),l,U,W=false;if(j){l=j.one(s);while(!W){if(l){U=l.one(s);if(U){l=U;}else{W=true;}}else{W=true;}}if(l){g.copyStyles(l,M);}}}break;case"enter":if(A.UA.webkit){if(u.changedEvent.shiftKey){g.execCommand("insertbr");u.changedEvent.preventDefault();}}if(A.UA.gecko&&g.get("defaultblock")!=="p"){a=u.changedNode;if(!a.test(E)&&!a.ancestor(E)){if(!a.test(i)){a=a.ancestor(i);}w=P.Node.create("<"+i+"></"+i+">");a.insert(w,"after");q=new P.Selection();if(q.anchorOffset){X=q.anchorNode.get("textContent");c=P.one(P.config.doc.createTextNode(X.substr(0,q.anchorOffset)));N=P.one(P.config.doc.createTextNode(X.substr(q.anchorOffset)));r=q.anchorNode;r.setContent("");L=r.cloneNode();L.append(N);h=false;S=r;while(!h){S=S.get(J);if(S&&!S.test(i)){m=S.cloneNode();m.set("innerHTML","");m.append(L);R=S.get("childNodes");var Q=false;R.each(function(b){if(Q){m.append(b);}if(b===r){Q=true;}});r=S;L=m;}else{h=true;}}N=L;q.anchorNode.append(c);if(N){w.append(N);}}if(w.get(I)){w=w.get(I);}w.prepend(P.Selection.CURSOR);q.focusCursor(true,true);V=P.Selection.getText(w);if(V!==""){P.Selection.cleanCursor();}u.changedEvent.preventDefault();}}break;case"keydown":if(P.config.doc.childNodes.length<2){var O=P.config.doc.body.innerHTML;if(O&&O.length<5&&O.toLowerCase()==G){this._fixFirstPara();}}break;case"backspace-up":case"backspace-down":case"delete-up":if(!A.UA.ie){o=P.all(B);v=P.one(F);if(o.item(0)){v=o.item(0);}y=v.one("br");if(y){y.removeAttribute("id");y.removeAttribute("class");}c=P.Selection.getText(v);c=c.replace(/ /g,"").replace(/\n/g,"");Z=v.all("img");if(c.length===0&&!Z.size()){if(!v.test(H)){this._fixFirstPara();}k=null;if(u.changedNode&&u.changedNode.test(H)){k=u.changedNode;}if(!k&&g._lastPara&&g._lastPara.inDoc()){k=g._lastPara;}if(k&&!k.test(H)){k=k.ancestor(H);}if(k){if(!k.previous()&&k.get(J)&&k.get(J).test(F)){u.changedEvent.frameEvent.halt();}}}if(A.UA.webkit){if(u.changedNode){v=u.changedNode;if(v.test("li")&&(!v.previous()&&!v.next())){V=v.get("innerHTML").replace(G,"");if(V===""){if(v.get(J)){v.get(J).replace(P.Node.create(G));u.changedEvent.frameEvent.halt();u.preventDefault();P.Selection.filterBlocks();}}}}}}if(A.UA.gecko){w=u.changedNode;Y=P.config.doc.createTextNode(" ");w.appendChild(Y);w.removeChild(Y);}break;}if(A.UA.gecko){if(u.changedNode&&!u.changedNode.test(i)){var k=u.changedNode.ancestor(i);if(k){this._lastPara=k;}}}},_afterEditorReady:function(){var M=this.get(K),N=M.getInstance(),L;if(N){N.Selection.filterBlocks();L=N.Selection.DEFAULT_BLOCK_TAG;B=F+" > "+L;H=L;}},_afterContentChange:function(){var L=this.get(K),M=L.getInstance();if(M&&M.Selection){M.Selection.filterBlocks();}},_afterPaste:function(){var L=this.get(K),N=L.getInstance(),M=new N.Selection();A.later(50,L,function(){N.Selection.filterBlocks();});},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));L.after("ready",A.bind(this._afterEditorReady,this));L.after("contentChange",A.bind(this._afterContentChange,this));if(A.Env.webkit){L.after("dom:paste",A.bind(this._afterPaste,this));}}},{NAME:"editorPara",NS:"editorPara",ATTRS:{host:{value:false}}});A.namespace("Plugin");A.Plugin.EditorPara=D;},"3.3.0",{requires:["node"],skinnable:false});