exec-command-min.js revision e9d98301bba2688d778e2e872b62bdc992b526ea
YUI.add("exec-command",function(B){var A=function(){A.superclass.constructor.apply(this,arguments);};B.extend(A,B.Base,{_lastKey:null,_inst:null,command:function(F,E){var D=A.COMMANDS[F];if(D){return D.call(this,F,E);}else{return this._command(F,E);}},_command:function(F,E){var D=this.getInstance();try{try{D.config.doc.execCommand("styleWithCSS",null,1);}catch(I){try{D.config.doc.execCommand("useCSS",null,0);}catch(H){}}D.config.doc.execCommand(F,null,E);}catch(G){}},getInstance:function(){if(!this._inst){this._inst=this.get("host").getInstance();}return this._inst;},initializer:function(){B.mix(this.get("host"),{execCommand:function(E,D){return this.exec.command(E,D);},_execCommand:function(E,D){return this.exec._command(E,D);}});this.get("host").on("dom:keypress",B.bind(function(D){this._lastKey=D.keyCode;},this));}},{NAME:"execCommand",NS:"exec",ATTRS:{host:{value:false}},COMMANDS:{wrap:function(F,D){var E=this.getInstance();return(new E.Selection()).wrapContent(D);},inserthtml:function(F,D){var E=this.getInstance();if(E.Selection.hasCursor()||B.UA.ie){return(new E.Selection()).insertContent(D);}else{this._command("inserthtml",D);}},insertandfocus:function(H,E){var G=this.getInstance(),D,F;if(G.Selection.hasCursor()){E+=G.Selection.CURSOR;D=this.command("inserthtml",E);F=new G.Selection();F.focusCursor(true,true);}else{this.command("inserthtml",E);}return D;},insertbr:function(J){var I=this.getInstance(),H=new I.Selection(),D="<var>|</var>",E=null,G=(B.UA.webkit)?"span.Apple-style-span,var":"var";if(H._selection.pasteHTML){H._selection.pasteHTML(D);}else{this._command("inserthtml",D);}var F=function(L){var K=I.Node.create("<br>");L.insert(K,"before");return K;};I.all(G).each(function(M){var L=true;if(B.UA.webkit){L=false;if(M.get("innerHTML")==="|"){L=true;}}if(L){E=F(M);if((!E.previous()||!E.previous().test("br"))&&B.UA.gecko){var K=E.cloneNode();E.insert(K,"after");E=K;}M.remove();}});if(B.UA.webkit&&E){F(E);H.selectNode(E);}},insertimage:function(E,D){return this.command("inserthtml",'<img src="'+D+'">');},addclass:function(F,D){var E=this.getInstance();return(new E.Selection()).getSelected().addClass(D);},removeclass:function(F,D){var E=this.getInstance();return(new E.Selection()).getSelected().removeClass(D);},forecolor:function(F,G){var E=this.getInstance(),D=new E.Selection(),H;if(!B.UA.ie){this._command("useCSS",false);}if(E.Selection.hasCursor()){if(D.isCollapsed){if(D.anchorNode&&(D.anchorNode.get("innerHTML")==="&nbsp;")){D.anchorNode.setStyle("color",G);H=D.anchorNode;}else{H=this.command("inserthtml",'<span style="color: '+G+'">'+E.Selection.CURSOR+"</span>");D.focusCursor(true,true);}return H;}else{return this._command(F,G);}}else{this._command(F,G);}},backcolor:function(F,G){var E=this.getInstance(),D=new E.Selection(),H;if(B.UA.gecko||B.UA.opera){F="hilitecolor";}if(!B.UA.ie){this._command("useCSS",false);}if(E.Selection.hasCursor()){if(D.isCollapsed){if(D.anchorNode&&(D.anchorNode.get("innerHTML")==="&nbsp;")){D.anchorNode.setStyle("backgroundColor",G);H=D.anchorNode;}else{H=this.command("inserthtml",'<span style="background-color: '+G+'">'+E.Selection.CURSOR+"</span>");D.focusCursor(true,true);}return H;}else{return this._command(F,G);}}else{this._command(F,G);}},hilitecolor:function(){return A.COMMANDS.backcolor.apply(this,arguments);},fontname2:function(F,G){this._command("fontname",G);var E=this.getInstance(),D=new E.Selection();if(D.isCollapsed&&(this._lastKey!=32)){if(D.anchorNode.test("font")){D.anchorNode.set("face",G);}}},fontsize2:function(F,H){this._command("fontsize",H);var E=this.getInstance(),D=new E.Selection();if(D.isCollapsed&&D.anchorNode&&(this._lastKey!=32)){if(B.UA.webkit){if(D.anchorNode.getStyle("lineHeight")){D.anchorNode.setStyle("lineHeight","");}}if(D.anchorNode.test("font")){D.anchorNode.set("size",H);}else{if(B.UA.gecko){var G=D.anchorNode.ancestor(E.Selection.DEFAULT_BLOCK_TAG);if(G){G.setStyle("fontSize","");}}}}},insertunorderedlist:function(D){this.command("list","ul");},insertorderedlist:function(D){this.command("list","ol");},list:function(R,U){var F=this.getInstance(),H,Q="dir",E="yui3-touched",M,K,L,G,N,O,I,J,T,D,P=new F.Selection();R="insert"+((U==="ul")?"un":"")+"orderedlist";if(B.UA.ie&&!P.isCollapsed){K=P._selection;H=K.htmlText;L=F.Node.create(H);if(L.test(U)){G=K.item?K.item(0):K.parentElement();N=F.one(G);D=N.all("li");O="<div>";D.each(function(V){O+=V.get("innerHTML")+"<br>";});O+="</div>";I=F.Node.create(O);if(N.get("parentNode").test("div")){N=N.get("parentNode");}if(N&&N.hasAttribute(Q)){I.setAttribute(Q,N.getAttribute(Q));}N.replace(I);if(K.moveToElementText){K.moveToElementText(I._node);}K.select();}else{J=B.one(K.parentElement());if(!J.test(F.Selection.BLOCKS)){J=J.ancestor(F.Selection.BLOCKS);}if(J){if(J.hasAttribute(Q)){M=J.getAttribute(Q);}}H=H.split(/<br>/i);T="<"+U+' id="ie-list">';B.each(H,function(W){var V=F.Node.create(W);if(V.test("p")){if(V.hasAttribute(Q)){M=V.getAttribute(Q);}W=V.get("innerHTML");}T+="<li>"+W+"</li>";});T+="</"+U+">";K.pasteHTML(T);G=F.config.doc.getElementById("ie-list");G.id="";if(M){G.setAttribute(Q,M);}if(K.moveToElementText){K.moveToElementText(G);}K.select();}}else{if(B.UA.ie){J=F.one(P._selection.parentElement());if(J.test("p")){if(J&&J.hasAttribute(Q)){M=J.getAttribute(Q);}H=B.Selection.getText(J);if(H===""){var S="";if(M){S=' dir="'+M+'"';}T=F.Node.create(B.Lang.sub("<{tag}{dir}><li></li></{tag}>",{tag:U,dir:S}));J.replace(T);P.selectNode(T.one("li"));}}else{this._command(R,null);}}else{F.all(U).addClass(E);if(P.anchorNode.test(F.Selection.BLOCKS)){J=P.anchorNode;}else{J=P.anchorNode.ancestor(F.Selection.BLOCKS);}if(J&&J.hasAttribute(Q)){M=J.getAttribute(Q);}this._command(R,null);T=F.all(U);if(M){T.each(function(V){if(!V.hasClass(E)){V.setAttribute(Q,M);}});}T.removeClass(E);}}},justify:function(I,J){if(B.UA.webkit){var H=this.getInstance(),G=new H.Selection(),D=G.anchorNode;var F=D.getStyle("backgroundColor");this._command(J);G=new H.Selection();if(G.anchorNode.test("div")){var E="<span>"+G.anchorNode.get("innerHTML")+"</span>";
G.anchorNode.set("innerHTML",E);G.anchorNode.one("span").setStyle("backgroundColor",F);G.selectNode(G.anchorNode.one("span"));}}else{this._command(J);}},justifycenter:function(D){this.command("justify","justifycenter");},justifyleft:function(D){this.command("justify","justifyleft");},justifyright:function(D){this.command("justify","justifyright");},justifyfull:function(D){this.command("justify","justifyfull");}}});var C=function(I,Q,N){var J=this.getInstance(),O=J.config.doc,G=O.selection.createRange(),F=O.queryCommandValue(I),K,E,H,D,L,P,M;if(F){K=G.htmlText;E=new RegExp(N,"g");H=K.match(E);if(H){K=K.replace(N+";","").replace(N,"");G.pasteHTML('<var id="yui-ie-bs">');D=O.getElementById("yui-ie-bs");L=O.createElement("div");P=O.createElement(Q);L.innerHTML=K;if(D.parentNode!==J.config.doc.body){D=D.parentNode;}M=L.childNodes;D.parentNode.replaceChild(P,D);B.each(M,function(R){P.appendChild(R);});G.collapse();if(G.moveToElementText){G.moveToElementText(P);}G.select();}}this._command(I);};if(B.UA.ie){A.COMMANDS.bold=function(){C.call(this,"bold","b","FONT-WEIGHT: bold");};A.COMMANDS.italic=function(){C.call(this,"italic","i","FONT-STYLE: italic");};A.COMMANDS.underline=function(){C.call(this,"underline","u","TEXT-DECORATION: underline");};}B.namespace("Plugin");B.Plugin.ExecCommand=A;},"@VERSION@",{requires:["frame"],skinnable:false});