?? richtext.js
字號(hào):
} } // opera likes this to be outside the with block this.iframe.src = dojo.uri.dojoUri("src/widget/templates/richtextframe.html") + "#" + ((document.domain != currentDomain) ? document.domain : ""); this.iframe.width = this.inheritWidth ? this._oldWidth : "100%"; if (this.height) { this.iframe.style.height = this.height; } else { var height = this._oldHeight; if (this._hasCollapseableMargin(this.domNode, 'top')) { height += this._firstChildContributingMargin; } if (this._hasCollapseableMargin(this.domNode, 'bottom')) { height += this._lastChildContributingMargin; } this.iframe.height = height; } var tmpContent = document.createElement('div'); tmpContent.innerHTML = html; // make relative image urls absolute if (this.relativeImageUrls) { var imgs = tmpContent.getElementsByTagName('img'); for (var i=0; i<imgs.length; i++) { imgs[i].src = (new dojo.uri.Uri(window.location, imgs[i].src)).toString(); } html = tmpContent.innerHTML; } // fix margins on tmpContent var firstChild = dojo.dom.firstElement(tmpContent); var lastChild = dojo.dom.lastElement(tmpContent); if(firstChild){ firstChild.style.marginTop = this._firstChildContributingMargin+"px"; } if(lastChild){ lastChild.style.marginBottom = this._lastChildContributingMargin+"px"; } // show existing content behind iframe for now tmpContent.style.position = "absolute"; this.domNode.appendChild(tmpContent); this.domNode.appendChild(this.iframe); var _iframeInitialized = false; // now we wait for onload. Janky hack! var ifrFunc = dojo.lang.hitch(this, function(){ if(!_iframeInitialized){ _iframeInitialized = true; }else{ return; } if(!this.editNode){ if(this.iframe.contentWindow){ this.window = this.iframe.contentWindow; }else{ // for opera this.window = this.iframe.contentDocument.window; } if(dojo.render.html.moz){ this.document = this.iframe.contentWindow.document }else{ this.document = this.iframe.contentDocument; } // curry the getStyle function var getStyle = (function (domNode) { return function (style) { return dojo.style.getStyle(domNode, style); }; })(this.domNode); var font = getStyle('font-weight') + " " + getStyle('font-size') + " " + getStyle('font-family'); // line height is tricky - applying a units value will mess things up. // if we can't get a non-units value, bail out. var lineHeight = "1.0"; var lineHeightStyle = dojo.style.getUnitValue(this.domNode, 'line-height'); if (lineHeightStyle.value && lineHeightStyle.units=="") { lineHeight = lineHeightStyle.value; } dojo.style.insertCssText( ' body,html { background: transparent; padding: 0; margin: 0; }\n' + // TODO: left positioning will case contents to disappear out of view // if it gets too wide for the visible area ' body { top: 0; left: 0; right: 0;' + (this.height ? '' : ' position: fixed; ') + ' font: ' + font + ';\n' + ' min-height: ' + this.minHeight + '; \n' + ' line-height: ' + lineHeight + '} \n' + ' p { margin: 1em 0 !important; }\n' + ' body > *:first-child { padding-top: 0 !important; margin-top: ' + this._firstChildContributingMargin + 'px !important; }\n' + // FIXME: test firstChild nodeType ' body > *:last-child { padding-bottom: 0 !important; margin-bottom: ' + this._lastChildContributingMargin + 'px !important; }\n' + ' li > ul:-moz-first-node, li > ol:-moz-first-node { padding-top: 1.2em; }\n' + ' li { min-height: 1.2em; }\n' + //' p,ul,li { padding-top: 0; padding-bottom: 0; margin-top:0; margin-bottom: 0; }\n' + '', this.document); tmpContent.parentNode.removeChild(tmpContent); this.document.body.innerHTML = html; if(oldMoz){ this.document.designMode = "on"; } this.onLoad(); }else{ tmpContent.parentNode.removeChild(tmpContent); this.editNode.innerHTML = html; this.onDisplayChanged(); } }); if(this.editNode){ ifrFunc(); // iframe already exists, just set content }else if(dojo.render.html.moz){ // FIXME: if we put this on a delay, we get a height of 20px. // Otherwise we get the correctly specified minHeight value. this.iframe.onload = function(){ setTimeout(ifrFunc, 250); } }else{ // new mozillas, opera, safari this.iframe.onload = ifrFunc; } }, /** Draws an active x object, used by IE */ _drawObject: function (html) { this.object = document.createElement("object"); with (this.object) { classid = "clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A"; width = this.inheritWidth ? this._oldWidth : "100%"; style.height = this.height ? this.height : (this._oldHeight+"px"); Scrollbars = this.height ? true : false; Appearance = this._activeX.appearance.flat; } this.domNode.appendChild(this.object); this.object.attachEvent("DocumentComplete", dojo.lang.hitch(this, "onLoad")); this.object.attachEvent("DisplayChanged", dojo.lang.hitch(this, "_updateHeight")); this.object.attachEvent("DisplayChanged", dojo.lang.hitch(this, "onDisplayChanged")); dojo.lang.forEach(this.events, function(e){ this.object.attachEvent(e.toLowerCase(), dojo.lang.hitch(this, e)); }, this); this.object.DocumentHTML = '<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + '<title></title>' + '<style type="text/css">' + ' body,html { padding: 0; margin: 0; }' + //font: ' + font + '; }' + (this.height ? '' : ' body { overflow: hidden; }') + //' #bodywrapper { }' + '</style>' + //'<base href="' + window.location + '">' + '<body><div id="bodywrapper">' + html + '</div></body>'; }, /* Event handlers *****************/ _isResized: function(){ return false; }, onLoad: function(e){ this.isLoaded = true; if (this.object){ this.document = this.object.DOM; this.window = this.document.parentWindow; this.editNode = this.document.body.firstChild; this.domNode.style.height = this.height ? this.height : this.minHeight; this.connect(this, "onDisplayChanged", "_updateHeight"); }else if (this.iframe){ this.editNode = this.document.body; this.connect(this, "onDisplayChanged", "_updateHeight"); try { // sanity check for Mozilla this.document.execCommand("useCSS", false, true); // old moz call this.document.execCommand("styleWithCSS", false, false); // new moz call //this.document.execCommand("insertBrOnReturn", false, false); // new moz call }catch(e2){ } if (dojo.render.html.safari) { /* this.iframe.style.visiblity = "visible"; this.iframe.style.border = "1px solid black"; this.editNode.style.visiblity = "visible"; this.editNode.style.border = "1px solid black"; */ // this.onDisplayChanged(); this.connect(this.editNode, "onblur", "onBlur"); this.connect(this.editNode, "onfocus", "onFocus"); this.interval = setInterval(dojo.lang.hitch(this, "onDisplayChanged"), 750); // dojo.raise("onload"); // dojo.debug(this.editNode.parentNode.parentNode.parentNode.nodeName); } else if (dojo.render.html.mozilla || dojo.render.html.opera) { // We need to unhook the blur event listener on close as we // can encounter a garunteed crash in FF if another event is // also fired var doc = this.document; var blurfp = dojo.event.browser.addListener(this.document, "blur", dojo.lang.hitch(this, "onBlur")); var unBlur = { unBlur: function(e){ dojo.event.browser.removeListener(doc, "blur", blurfp); } }; dojo.event.connect("before", this, "close", unBlur, "unBlur"); dojo.event.browser.addListener(this.document, "focus", dojo.lang.hitch(this, "onFocus")); // safari can't handle key listeners, it kills the speed var addListener = dojo.event.browser.addListener; addListener(this.document, "keypress", dojo.lang.hitch(this, "onKeyPress")); addListener(this.document, "keydown", dojo.lang.hitch(this, "onKeyDown")); addListener(this.document, "keyup", dojo.lang.hitch(this, "onKeyUp")); addListener(this.document, "click", dojo.lang.hitch(this, "onClick")); } // FIXME: when scrollbars appear/disappear this needs to be fired }else if(dojo.render.html.ie){ // IE contentEditable this.editNode.style.zoom = 1.0; } if(this.focusOnLoad){ this.focus(); } this.onDisplayChanged(e); }, /** Fired on keydown */ onKeyDown: function(e){ if((!e)&&(this.object)){ e = dojo.event.browser.fixEvent(this.window.event); } dojo.debug("onkeydown:", e.keyCode); // we need this event at the moment to get the events from control keys // such as the backspace. It might be possible to add this to Dojo, so that // keyPress events can be emulated by the keyDown and keyUp detection. if((dojo.render.html.ie)&&(e.keyCode == e.KEY_TAB)){ e.preventDefault(); e.stopPropagation(); // FIXME: this is a poor-man's indent/outdent. It would be // better if it added 4 " " chars in an undoable way. // Unfortuantly pasteHTML does not prove to be undoable this.execCommand((e.shiftKey ? "outdent" : "indent")); }else if(dojo.render.html.ie){ if((65 <= e.keyCode)&&(e.keyCode <= 90)){ e.charCode = e.keyCode; this.onKeyPress(e); } // dojo.debug(e.ctrlKey); // dojo.debug(e.keyCode); // dojo.debug(e.charCode); // this.onKeyPress(e); } }, /** Fired on keyup */ onKeyUp: function(e){ return; }, KEY_CTRL: 1, /** Fired on keypress. */ onKeyPress: function(e){ if((!e)&&(this.object)){ e = dojo.event.browser.fixEvent(this.window.event); } // handle the various key events var character = e.charCode > 0 ? String.fromCharCode(e.charCode) : null; var code = e.keyCode; var modifiers = e.ctrlKey ? this.KEY_CTRL : 0; if (this._keyHandlers[character]) { dojo.debug("char:", character); var handlers = this._keyHandlers[character], i = 0, handler; while (handler = handlers[i++]) { if (modifiers == handler.modifiers) { handler.handler.call(this); e.preventDefault(); break; } } } /* // define some key combos if (e.ctrlKey || e.metaKey) { // modifier pressed switch (character) { case "b": this.execCommand("bold"); break; case "i": this.execCommand("italic"); break; case "u": this.execCommand("underline"); break; //case "a": this.execCommand("selectall"); break; //case "k": this.execCommand("createlink", ""); break; //case "K": this.execCommand("unlink"); break; case "Z": this.execCommand("redo"); break; case "s": this.close(true); break; // saves case "1": this.execCommand("formatblock", "h1"); break; case "2": this.execCommand("formatblock", "h2"); break; case "3": this.execCommand("formatblock", "h3"); break; case "4": this.execCommand("formatblock", "h4"); break; case "\\": this.execCommand("insertunorderedlist"); break; default: switch (code) { case e.KEY_LEFT_ARROW: case e.KEY_RIGHT_ARROW: //break; // preventDefault stops the browser // going through its history default: preventDefault = false; break; // didn't handle here } } } else { switch (code) { case e.KEY_TAB: // commenting out bcs it's crashing FF // this.execCommand(e.shiftKey ? "unindent" : "indent"); // break; default: preventDefault = false; break; // didn't handle here } } if (preventDefault) { e.preventDefault(); } */ // function call after the character has been inserted dojo.lang.setTimeout(this, this.onKeyPressed, 1, e); }, addKeyHandler: function (key, modifiers, handler) { if (!(this._keyHandlers[key] instanceof Array)) { this._keyHandlers[key] = []; } this._keyHandlers[key].push({ modifiers: modifiers || 0, handler: handler }); }, /** * Fired after a keypress event has occured and it's action taken. This * is useful if action needs to be taken after text operations have * finished */ onKeyPressed: function (e) { // Mozilla adds a single <p> with an embedded <br> when you hit enter once: // <p><br>\n</p> // when you hit enter again it adds another <br> inside your enter // <p><br>\n<br>\n</p> // and if you hit enter again it splits the <br>s over 2 <p>s // <p><br>\n</p>\n<p><br>\n</p> // now this assumes that <p>s have double the line-height of <br>s to work // and so we need to remove the <p>s to ensure the position of the cursor // changes from the users perspective when they hit enter, as the second two // html snippets render the same when margins are set to 0. // TODO: doesn't really work; is this really needed? //if (dojo.render.html.moz) {
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -