dijit._editor.RichText.open
dojo.require("dijit._editor.RichText");
defined in dijit/_editor/RichText.js
Transforms the node referenced in this.domNode into a rich text editing node. This will result in the creation and replacement with an
Usage
function (/*DomNode?*/ element) (view source)
if((!this.onLoadDeferred)||(this.onLoadDeferred.fired >= 0)){ this.onLoadDeferred = new dojo.Deferred(); } if(!this.isClosed){ this.close(); } dojo.publish(dijit._scopeName + "._editor.RichText::open", [ this ]); this._content = ""; if((arguments.length == 1)&&(element["nodeName"])){ this.domNode = element; } // else unchanged var html; if( (this.domNode["nodeName"])&& (this.domNode.nodeName.toLowerCase() == "textarea")){ // if we were created from a textarea, then we need to create a // new editing harness node. this.textarea = this.domNode; this.name=this.textarea.name; html = this._preFilterContent(this.textarea.value); this.domNode = dojo.doc.createElement("div"); this.domNode.setAttribute('widgetId',this.id); this.textarea.removeAttribute('widgetId'); this.domNode.cssText = this.textarea.cssText; this.domNode.className += " "+this.textarea.className; dojo.place(this.domNode, this.textarea, "before"); var tmpFunc = dojo.hitch(this, function(){ //some browsers refuse to submit display=none textarea, so //move the textarea out of screen instead dojo.attr(this.textarea, 'tabIndex', '-1'); with(this.textarea.style){ display = "block"; position = "absolute"; left = top = "-1000px"; if(dojo.isIE){ //nasty IE bug: abnormal formatting if overflow is not hidden this.__overflow = overflow; overflow = "hidden"; } } }); if(dojo.isIE){ setTimeout(tmpFunc, 10); }else{ tmpFunc(); } // this.domNode.innerHTML = html; // if(this.textarea.form){ // // FIXME: port: this used to be before advice!!! // dojo.connect(this.textarea.form, "onsubmit", this, function(){ // // FIXME: should we be calling close() here instead? // this.textarea.value = this.getValue(); // }); // } }else{ html = this._preFilterContent(dijit._editor.getChildrenHtml(this.domNode)); this.domNode.innerHTML = ''; } if(html == ""){ html = " "; } var content = dojo.contentBox(this.domNode); // var content = dojo.contentBox(this.srcNodeRef); this._oldHeight = content.h; this._oldWidth = content.w; // If we're a list item we have to put in a blank line to force the // bullet to nicely align at the top of text if( (this.domNode["nodeName"]) && (this.domNode.nodeName == "LI") ){ this.domNode.innerHTML = " <br>"; } this.editingArea = dojo.doc.createElement("div"); this.domNode.appendChild(this.editingArea); if(this.name != "" && (!dojo.config["useXDomain"] || dojo.config["allowXdRichTextSave"])){ var saveTextarea = dojo.byId(dijit._scopeName + "._editor.RichText.savedContent"); if(saveTextarea.value != ""){ var datas = saveTextarea.value.split(this._SEPARATOR), i=0, dat; while((dat=datas[i++])){ var data = dat.split(":"); if(data[0] == this.name){ html = data[1]; datas.splice(i, 1); break; } } } // FIXME: need to do something different for Opera/Safari this.connect(window, "onbeforeunload", "_saveContent"); // dojo.connect(window, "onunload", this, "_saveContent"); } this.isClosed = false; // Safari's selections go all out of whack if we do it inline, // so for now IE is our only hero //if(typeof dojo.doc.body.contentEditable != "undefined"){ if(dojo.isIE || dojo.isSafari || dojo.isOpera){ // contentEditable, easy var burl = dojo.moduleUrl("dojo", "resources/blank.html")+""; var ifr = this.editorObject = this.iframe = dojo.doc.createElement('iframe'); ifr.id = this.id+"_iframe"; ifr.src = burl; ifr.style.border = "none"; ifr.style.width = "100%"; ifr.frameBorder = 0; // ifr.style.scrolling = this.height ? "auto" : "vertical"; this.editingArea.appendChild(ifr); var h = null; // set later in non-ie6 branch var loadFunc = dojo.hitch( this, function(){ if(h){ dojo.disconnect(h); h = null; } this.window = ifr.contentWindow; var d = this.document = this.window.document; d.open(); d.write(this._getIframeDocTxt(html)); d.close(); if(dojo.isIE >= 7){ if(this.height){ ifr.style.height = this.height; } if(this.minHeight){ ifr.style.minHeight = this.minHeight; } }else{ ifr.style.height = this.height ? this.height : this.minHeight; } if(dojo.isIE){ this._localizeEditorCommands(); } this.onLoad(); this.savedContent = this.getValue(true); }); if(dojo.isIE && dojo.isIE < 7){ // IE 6 is a steaming pile... var t = setInterval(function(){ if(ifr.contentWindow.isLoaded){ clearInterval(t); loadFunc(); } }, 100); }else{ // blissful sanity! h = dojo.connect( ((dojo.isIE) ? ifr.contentWindow : ifr), "onload", loadFunc ); } }else{ // designMode in iframe this._drawIframe(html); this.savedContent = this.getValue(true); } // TODO: this is a guess at the default line-height, kinda works if(this.domNode.nodeName == "LI"){ this.domNode.lastChild.style.marginTop = "-1.2em"; } this.domNode.className += " RichTextEditable";
parameter | type | description |
---|---|---|
element | DomNode | Optional. |