exec-command-min.js revision aa2ac226ad6e45232f8416eecc99d2165ce74d03
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(e,d){var c=a.COMMANDS[e];if(c){return c.call(this,e,d);}else{return this._command(e,d);}},_command:function(f,d){var c=this.getInstance();try{c.config.doc.execCommand(f,null,d);}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(d,c){return this.exec.command(d,c);},_execCommand:function(d,c){return this.exec._command(d,c);}});this.get("host").on("dom:keypress",b.bind(function(c){this._lastKey=c.keyCode;},this));}},{NAME:"execCommand",NS:"exec",ATTRS:{host:{value:false}},COMMANDS:{wrap:function(e,c){var d=this.getInstance();return(new d.Selection()).wrapContent(c);},inserthtml:function(e,c){var d=this.getInstance();if(d.Selection.hasCursor()||b.UA.ie){return(new d.Selection()).insertContent(c);}else{this._command("inserthtml",c);}},insertandfocus:function(g,d){var f=this.getInstance(),c,e;if(f.Selection.hasCursor()){d+=f.Selection.CURSOR;c=this.command("inserthtml",d);e=new f.Selection();e.focusCursor(true,true);}else{this.command("inserthtml",d);}return c;},insertbr:function(e){var d=this.getInstance(),f,c=new d.Selection();c.setCursor();f=c.getCursor();f.insert("<br>","before");c.focusCursor(true,false);return f.previous();},insertimage:function(d,c){return this.command("inserthtml",'<img src="'+c+'">');},addclass:function(e,c){var d=this.getInstance();return(new d.Selection()).getSelected().addClass(c);},removeclass:function(e,c){var d=this.getInstance();return(new d.Selection()).getSelected().removeClass(c);},forecolor:function(e,f){var d=this.getInstance(),c=new d.Selection(),g;if(!b.UA.ie){this._command("useCSS",false);}if(d.Selection.hasCursor()){if(c.isCollapsed){if(c.anchorNode&&(c.anchorNode.get("innerHTML")==="&nbsp;")){c.anchorNode.setStyle("color",f);g=c.anchorNode;}else{g=this.command("inserthtml",'<span style="color: '+f+'">'+d.Selection.CURSOR+"</span>");c.focusCursor(true,true);}return g;}else{return this._command(e,f);}}else{this._command(e,f);}},backcolor:function(e,f){var d=this.getInstance(),c=new d.Selection(),g;if(b.UA.gecko||b.UA.opera){e="hilitecolor";}if(!b.UA.ie){this._command("useCSS",false);}if(d.Selection.hasCursor()){if(c.isCollapsed){if(c.anchorNode&&(c.anchorNode.get("innerHTML")==="&nbsp;")){c.anchorNode.setStyle("backgroundColor",f);g=c.anchorNode;}else{g=this.command("inserthtml",'<span style="background-color: '+f+'">'+d.Selection.CURSOR+"</span>");c.focusCursor(true,true);}return g;}else{return this._command(e,f);}}else{this._command(e,f);}},hilitecolor:function(){return a.COMMANDS.backcolor.apply(this,arguments);},fontname:function(e,f){this._command("fontname",f);var d=this.getInstance(),c=new d.Selection();if(c.isCollapsed&&(this._lastKey!=32)){if(c.anchorNode.test("font")){c.anchorNode.set("face",f);}}},fontsize:function(e,g){this._command("fontsize",g);var d=this.getInstance(),c=new d.Selection();if(c.isCollapsed&&c.anchorNode&&(this._lastKey!=32)){if(b.UA.webkit){if(c.anchorNode.getStyle("lineHeight")){c.anchorNode.setStyle("lineHeight","");}}if(c.anchorNode.test("font")){c.anchorNode.set("size",g);}else{if(b.UA.gecko){var f=c.anchorNode.ancestor("p");if(f){f.setStyle("fontSize","");}}}}}}});b.namespace("Plugin");b.Plugin.ExecCommand=a;},"@VERSION@",{skinnable:false,requires:["frame"]});