dijit._editor.RichText.execCommand
dojo.require("dijit._editor.RichText");
defined in dijit/_editor/RichText.js
Executes a command in the Rich Text area
Usage
function (/*String*/ command, argument) (view source)
var returnValue; //focus() is required for IE to work //In addition, focus() makes sure after the execution of //the command, the editor receives the focus as expected this.focus(); command = this._normalizeCommand(command); if(argument != undefined){ if(command == "heading"){ throw new Error("unimplemented"); }else if((command == "formatblock") && dojo.isIE){ argument = '<'+argument+'>'; } } if(command == "inserthtml"){ argument=this._preFilterContent(argument); if(dojo.isIE){ var insertRange = this.document.selection.createRange(); if(this.document.selection.type.toUpperCase()=='CONTROL'){ var n=insertRange.item(0); while(insertRange.length){ insertRange.remove(insertRange.item(0)); } n.outerHTML=argument; }else{ insertRange.pasteHTML(argument); } insertRange.select(); //insertRange.collapse(true); returnValue=true; }else if(dojo.isMoz && !argument.length){ //mozilla can not inserthtml an empty html to delete current selection //so we delete the selection instead in this case dojo.withGlobal(this.window,'remove',dijit._editor.selection); returnValue=true; }else{ returnValue=this.document.execCommand(command, false, argument); } }else if( (command == "unlink")&& (this.queryCommandEnabled("unlink"))&& (dojo.isMoz || dojo.isSafari) ){ // fix up unlink in Mozilla to unlink the link and not just the selection // grab selection // Mozilla gets upset if we just store the range so we have to // get the basic properties and recreate to save the selection var selection = this.window.getSelection(); // var selectionRange = selection.getRangeAt(0); // var selectionStartContainer = selectionRange.startContainer; // var selectionStartOffset = selectionRange.startOffset; // var selectionEndContainer = selectionRange.endContainer; // var selectionEndOffset = selectionRange.endOffset; // select our link and unlink var a = dojo.withGlobal(this.window, "getAncestorElement",dijit._editor.selection, ['a']); dojo.withGlobal(this.window, "selectElement", dijit._editor.selection, [a]); returnValue=this.document.execCommand("unlink", false, null); }else if((command == "hilitecolor")&&(dojo.isMoz)){ // // mozilla doesn't support hilitecolor properly when useCSS is // // set to false (bugzilla #279330) this.document.execCommand("styleWithCSS", false, true); returnValue = this.document.execCommand(command, false, argument); this.document.execCommand("styleWithCSS", false, false); }else if((dojo.isIE)&&( (command == "backcolor")||(command == "forecolor") )){ // Tested under IE 6 XP2, no problem here, comment out // IE weirdly collapses ranges when we exec these commands, so prevent it // var tr = this.document.selection.createRange(); argument = arguments.length > 1 ? argument : null; returnValue = this.document.execCommand(command, false, argument); // timeout is workaround for weird IE behavior were the text // selection gets correctly re-created, but subsequent input // apparently isn't bound to it // setTimeout(function(){tr.select();}, 1); }else{ argument = arguments.length > 1 ? argument : null; // if(dojo.isMoz){ // this.document = this.iframe.contentWindow.document // } if(argument || command!="createlink"){ returnValue = this.document.execCommand(command, false, argument); } } this.onDisplayChanged(); return returnValue;
parameter | type | description |
---|---|---|
command | String | The command to execute |
argument | optional argument to the command |