?? richtext.js
字號:
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; }, queryCommandEnabled: function(/*String*/command){ // summary: check whether a command is enabled or not if(this.disabled){ return false; } command = this._normalizeCommand(command); if(dojo.isMoz || dojo.isSafari){ if(command == "unlink"){ // mozilla returns true always // console.debug(dojo.withGlobal(this.window, "hasAncestorElement",dijit._editor.selection, ['a'])); return dojo.withGlobal(this.window, "hasAncestorElement",dijit._editor.selection, ['a']); }else if(command == "inserttable"){ return true; } } //see #4109 if(dojo.isSafari){ if(command == "copy"){ command = "cut"; }else if(command == "paste"){ return true; } } // return this.document.queryCommandEnabled(command); var elem = dojo.isIE ? this.document.selection.createRange() : this.document; return elem.queryCommandEnabled(command); }, queryCommandState: function(command){ // summary: check the state of a given command if(this.disabled){ return false; } command = this._normalizeCommand(command); return this.document.queryCommandState(command); }, queryCommandValue: function(command){ // summary: check the value of a given command if(this.disabled){ return false; } command = this._normalizeCommand(command); if(dojo.isIE && command == "formatblock"){ return this._local2NativeFormatNames[this.document.queryCommandValue(command)]; } return this.document.queryCommandValue(command); }, // Misc. placeCursorAtStart: function(){ // summary: // place the cursor at the start of the editing area this.focus(); //see comments in placeCursorAtEnd var isvalid=false; if(dojo.isMoz){ var first=this.editNode.firstChild; while(first){ if(first.nodeType == 3){ if(first.nodeValue.replace(/^\s+|\s+$/g, "").length>0){ isvalid=true; dojo.withGlobal(this.window, "selectElement", dijit._editor.selection, [first]); break; } }else if(first.nodeType == 1){ isvalid=true; dojo.withGlobal(this.window, "selectElementChildren",dijit._editor.selection, [first]); break; } first = first.nextSibling; } }else{ isvalid=true; dojo.withGlobal(this.window, "selectElementChildren",dijit._editor.selection, [this.editNode]); } if(isvalid){ dojo.withGlobal(this.window, "collapse", dijit._editor.selection, [true]); } }, placeCursorAtEnd: function(){ // summary: // place the cursor at the end of the editing area this.focus(); //In mozilla, if last child is not a text node, we have to use selectElementChildren on this.editNode.lastChild //otherwise the cursor would be placed at the end of the closing tag of this.editNode.lastChild var isvalid=false; if(dojo.isMoz){ var last=this.editNode.lastChild; while(last){ if(last.nodeType == 3){ if(last.nodeValue.replace(/^\s+|\s+$/g, "").length>0){ isvalid=true; dojo.withGlobal(this.window, "selectElement",dijit._editor.selection, [last]); break; } }else if(last.nodeType == 1){ isvalid=true; if(last.lastChild){ dojo.withGlobal(this.window, "selectElement",dijit._editor.selection, [last.lastChild]); }else{ dojo.withGlobal(this.window, "selectElement",dijit._editor.selection, [last]); } break; } last = last.previousSibling; } }else{ isvalid=true; dojo.withGlobal(this.window, "selectElementChildren",dijit._editor.selection, [this.editNode]); } if(isvalid){ dojo.withGlobal(this.window, "collapse", dijit._editor.selection, [false]); } }, getValue: function(/*Boolean?*/nonDestructive){ // summary: // return the current content of the editing area (post filters are applied) if(this.textarea){ if(this.isClosed || !this.isLoaded){ return this.textarea.value; } } return this._postFilterContent(null, nonDestructive); }, setValue: function(/*String*/html){ // summary: // this function set the content. No undo history is preserved if(!this.isLoaded){ // try again after the editor is finished loading this.onLoadDeferred.addCallback(dojo.hitch(this, function(){ this.setValue(html); })); return; } if(this.textarea && (this.isClosed || !this.isLoaded)){ this.textarea.value=html; }else{ html = this._preFilterContent(html); var node = this.isClosed ? this.domNode : this.editNode; node.innerHTML = html; this._preDomFilterContent(node); } this.onDisplayChanged(); }, replaceValue: function(/*String*/html){ // summary: // this function set the content while trying to maintain the undo stack // (now only works fine with Moz, this is identical to setValue in all // other browsers) if(this.isClosed){ this.setValue(html); }else if(this.window && this.window.getSelection && !dojo.isMoz){ // Safari // look ma! it's a totally f'd browser! this.setValue(html); }else if(this.window && this.window.getSelection){ // Moz html = this._preFilterContent(html); this.execCommand("selectall"); if(dojo.isMoz && !html){ html = " " } this.execCommand("inserthtml", html); this._preDomFilterContent(this.editNode); }else if(this.document && this.document.selection){//IE //In IE, when the first element is not a text node, say //an <a> tag, when replacing the content of the editing //area, the <a> tag will be around all the content //so for now, use setValue for IE too this.setValue(html); } }, _preFilterContent: function(/*String*/html){ // summary: // filter the input before setting the content of the editing area var ec = html; dojo.forEach(this.contentPreFilters, function(ef){ if(ef){ ec = ef(ec); } }); return ec; }, _preDomFilterContent: function(/*DomNode*/dom){ // summary: // filter the input dom = dom || this.editNode; dojo.forEach(this.contentDomPreFilters, function(ef){ if(ef && dojo.isFunction(ef)){ ef(dom); } }, this); }, _postFilterContent: function(/*DomNode|DomNode[]|String?*/dom,/*Boolean?*/nonDestructive){ // summary: // filter the output after getting the content of the editing area var ec; if(!dojo.isString(dom)){ dom = dom || this.editNode; if(this.contentDomPostFilters.length){ if(nonDestructive && dom['cloneNode']){ dom = dom.cloneNode(true); } dojo.forEach(this.contentDomPostFilters, function(ef){ dom = ef(dom); }); } ec = dijit._editor.getChildrenHtml(dom); }else{ ec = dom; } if(!ec.replace(/^(?:\s|\xA0)+/g, "").replace(/(?:\s|\xA0)+$/g,"").length){ ec = ""; } // if(dojo.isIE){ // //removing appended <P> </P> for IE // ec = ec.replace(/(?:<p> </p>[\n\r]*)+$/i,""); // } dojo.forEach(this.contentPostFilters, function(ef){ ec = ef(ec); }); return ec; }, _saveContent: function(/*Event*/e){ // summary: // Saves the content in an onunload event if the editor has not been closed var saveTextarea = dojo.byId(dijit._scopeName + "._editor.RichText.savedContent"); saveTextarea.value += this._SEPARATOR + this.name + ":" + this.getValue(); }, escapeXml: function(/*String*/str, /*Boolean*/noSingleQuotes){ dojo.deprecated('dijit.Editor::escapeXml is deprecated','use dijit._editor.escapeXml instead', 2); return dijit._editor.escapeXml(str,noSingleQuotes); }, getNodeHtml: function(/* DomNode */node){ dojo.deprecated('dijit.Editor::getNodeHtml is deprecated','use dijit._editor.getNodeHtml instead', 2); return dijit._editor.getNodeHtml(node); }, getNodeChildrenHtml: function(/* DomNode */dom){ dojo.deprecated('dijit.Editor::getNodeChildrenHtml is deprecated','use dijit._editor.getChildrenHtml instead', 2); return dijit._editor.getChildrenHtml(dom); }, close: function(/*Boolean*/save, /*Boolean*/force){ // summary: // Kills the editor and optionally writes back the modified contents to the // element from which it originated. // save: // Whether or not to save the changes. If false, the changes are discarded. // force: if(this.isClosed){return false; } if(!arguments.length){ save = true; } this._content = this.getValue(); var changed = (this.savedContent != this._content); // line height is squashed for iframes // FIXME: why was this here? if(this.iframe){ this.domNode.style.lineHeight = null; } if(this.interval){ clearInterval(this.interval); } if(this.textarea){ with(this.textarea.style){ position = ""; left = top = ""; if(dojo.isIE){ overflow = this.__overflow; this.__overflow = null; } } this.textarea.value = save ? this._content : this.savedContent; dojo._destroyElement(this.domNode); this.domNode = this.textarea; }else{// if(save){ //why we treat moz differently? comment out to fix #1061// if(dojo.isMoz){// var nc = dojo.doc.createElement("span");// this.domNode.appendChild(nc);// nc.innerHTML = this.editNode.innerHTML;// }else{// this.domNode.innerHTML = this._content;// }// } this.domNode.innerHTML = save ? this._content : this.savedContent; } dojo.removeClass(this.domNode, "RichTextEditable"); this.isClosed = true; this.isLoaded = false; // FIXME: is this always the right thing to do? delete this.editNode; if(this.window && this.window._frameElement){ this.window._frameElement = null; } this.window = null; this.document = null; this.editingArea = null; this.editorObject = null; return changed; // Boolean: whether the content has been modified }, destroyRendering: function(){ // summary: stub }, destroy: function(){ this.destroyRendering(); if(!this.isClosed){ this.close(false); } this.inherited("destroy",arguments); //dijit._editor.RichText.superclass.destroy.call(this); }, _removeMozBogus: function(/* String */ html){ return html.replace(/\stype="_moz"/gi, '').replace(/\s_moz_dirty=""/gi, ''); // String }, _removeSafariBogus: function(/* String */ html){ return html.replace(/\sclass="webkit-block-placeholder"/gi, ''); // String }, _fixContentForMoz: function(/* String */ html){ // summary: // Moz can not handle strong/em tags correctly, convert them to b/i return html.replace(/<(\/)?strong([ \>])/gi, '<$1b$2') .replace(/<(\/)?em([ \>])/gi, '<$1i$2' ); // String }, _srcInImgRegex : /(?:(<img(?=\s).*?\ssrc=)("|')(.*?)\2)|(?:(<img\s.*?src=)([^"'][^ >]+))/gi , _hrefInARegex : /(?:(<a(?=\s).*?\shref=)("|')(.*?)\2)|(?:(<a\s.*?href=)([^"'][^ >]+))/gi , _preFixUrlAttributes: function(/* String */ html){ return html.replace(this._hrefInARegex, '$1$4$2$3$5$2 _djrealurl=$2$3$5$2') .replace(this._srcInImgRegex, '$1$4$2$3$5$2 _djrealurl=$2$3$5$2'); // String }});}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -