📄 richtext.js
字号:
} this.onLoad(); } else { dojo.html.removeNode(tmpContent); this.editNode.innerHTML = html; this.onDisplayChanged(); } }); if (this.editNode) { ifrFunc(); } else { if (dojo.render.html.moz) { this.iframe.onload = function () { setTimeout(ifrFunc, 250); }; } else { this.iframe.onload = ifrFunc; } }}, _applyEditingAreaStyleSheets:function () { var files = []; if (this.styleSheets) { files = this.styleSheets.split(";"); this.styleSheets = ""; } files = files.concat(this.editingAreaStyleSheets); this.editingAreaStyleSheets = []; if (files.length > 0) { for (var i = 0; i < files.length; i++) { var url = files[i]; if (url) { this.addStyleSheet(dojo.uri.dojoUri(url)); } } }}, addStyleSheet:function (uri) { var url = uri.toString(); if (dojo.lang.find(this.editingAreaStyleSheets, url) > -1) { dojo.debug("dojo.widget.RichText.addStyleSheet: Style sheet " + url + " is already applied to the editing area!"); return; } if (url.charAt(0) == "." || (url.charAt(0) != "/" && !uri.host)) { url = (new dojo.uri.Uri(dojo.global().location, url)).toString(); } this.editingAreaStyleSheets.push(url); if (this.document.createStyleSheet) { this.document.createStyleSheet(url); } else { var head = this.document.getElementsByTagName("head")[0]; var stylesheet = this.document.createElement("link"); with (stylesheet) { rel = "stylesheet"; type = "text/css"; href = url; } head.appendChild(stylesheet); }}, removeStyleSheet:function (uri) { var url = uri.toString(); if (url.charAt(0) == "." || (url.charAt(0) != "/" && !uri.host)) { url = (new dojo.uri.Uri(dojo.global().location, url)).toString(); } var index = dojo.lang.find(this.editingAreaStyleSheets, url); if (index == -1) { dojo.debug("dojo.widget.RichText.removeStyleSheet: Style sheet " + url + " is not applied to the editing area so it can not be removed!"); return; } delete this.editingAreaStyleSheets[index]; var links = this.document.getElementsByTagName("link"); for (var i = 0; i < links.length; i++) { if (links[i].href == url) { if (dojo.render.html.ie) { links[i].href = ""; } dojo.html.removeNode(links[i]); break; } }}, _drawObject:function (html) { this.object = dojo.html.createExternalElement(dojo.doc(), "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.editorObject = this.object; this.editingArea.appendChild(this.object); this.object.attachEvent("DocumentComplete", dojo.lang.hitch(this, "onLoad")); 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\">" + "<html><title></title>" + "<style type=\"text/css\">" + " body,html { padding: 0; margin: 0; }" + (this.height ? "" : " body, { overflow: hidden; }") + "</style>" + "<body><div>" + html + "<div></body></html>"; this._cacheLocalBlockFormatNames();}, _local2NativeFormatNames:{}, _native2LocalFormatNames:{}, _cacheLocalBlockFormatNames:function () { if (!this._native2LocalFormatNames["p"]) { var obj = this.object; var error = false; if (!obj) { try { obj = dojo.html.createExternalElement(dojo.doc(), "object"); obj.classid = "clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A"; dojo.body().appendChild(obj); obj.DocumentHTML = "<html><head></head><body></body></html>"; } catch (e) { error = true; } } try { var oNamesParm = new ActiveXObject("DEGetBlockFmtNamesParam.DEGetBlockFmtNamesParam"); obj.ExecCommand(this._activeX.command["getblockformatnames"], 0, oNamesParm); var vbNamesArray = new VBArray(oNamesParm.Names); var localFormats = vbNamesArray.toArray(); var nativeFormats = ["p", "pre", "address", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "", "", "", "", "div"]; for (var i = 0; i < nativeFormats.length; ++i) { if (nativeFormats[i].length > 0) { this._local2NativeFormatNames[localFormats[i]] = nativeFormats[i]; this._native2LocalFormatNames[nativeFormats[i]] = localFormats[i]; } } } catch (e) { error = true; } if (obj && !this.object) { dojo.body().removeChild(obj); } } return !error;}, _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.editingArea.style.height = this.height ? this.height : this.minHeight; if (!this.height) { this.connect(this, "onDisplayChanged", "_updateHeight"); } this.window._frameElement = this.object; } else { if (this.iframe && !dojo.render.html.ie) { this.editNode = this.document.body; if (!this.height) { this.connect(this, "onDisplayChanged", "_updateHeight"); } try { this.document.execCommand("useCSS", false, true); this.document.execCommand("styleWithCSS", false, false); } catch (e2) { } if (dojo.render.html.safari) { this.connect(this.editNode, "onblur", "onBlur"); this.connect(this.editNode, "onfocus", "onFocus"); this.connect(this.editNode, "onclick", "onFocus"); this.interval = setInterval(dojo.lang.hitch(this, "onDisplayChanged"), 750); } else { if (dojo.render.html.mozilla || dojo.render.html.opera) { var doc = this.document; var addListener = dojo.event.browser.addListener; var self = this; dojo.lang.forEach(this.events, function (e) { var l = addListener(self.document, e.substr(2).toLowerCase(), dojo.lang.hitch(self, e)); if (e == "onBlur") { var unBlur = {unBlur:function (e) { dojo.event.browser.removeListener(doc, "blur", l); }}; dojo.event.connect("before", self, "close", unBlur, "unBlur"); } }); } } } else { if (dojo.render.html.ie) { if (!this.height) { this.connect(this, "onDisplayChanged", "_updateHeight"); } this.editNode.style.zoom = 1; } } } this._applyEditingAreaStyleSheets(); if (this.focusOnLoad) { this.focus(); } this.onDisplayChanged(e); if (this.onLoadDeferred) { this.onLoadDeferred.callback(true); }}, onKeyDown:function (e) { if ((!e) && (this.object)) { e = dojo.event.browser.fixEvent(this.window.event); } if ((dojo.render.html.ie) && (e.keyCode == e.KEY_TAB)) { e.preventDefault(); e.stopPropagation(); 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); } } }}, onKeyUp:function (e) { return;}, KEY_CTRL:1, onKeyPress:function (e) { if ((!e) && (this.object)) { e = dojo.event.browser.fixEvent(this.window.event); } var modifiers = e.ctrlKey ? this.KEY_CTRL : 0; if (this._keyHandlers[e.key]) { var handlers = this._keyHandlers[e.key], i = 0, handler; while (handler = handlers[i++]) { if (modifiers == handler.modifiers) { e.preventDefault(); handler.handler.call(this); break; } } } 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});}, onKeyPressed:function (e) { this.onDisplayChanged();}, onClick:function (e) { this.onDisplayChanged(e);}, onBlur:function (e) {}, _initialFocus:true, onFocus:function (e) { if ((dojo.render.html.mozilla) && (this._initialFocus)) { this._initialFocus = false; if (dojo.string.trim(this.editNode.innerHTML) == " ") { this.placeCursorAtStart(); } }}, blur:function () { if (this.iframe) { this.window.blur(); } else { if (this.object) { this.document.body.blur(); } else { if (this.editNode) { this.editNode.blur(); } } }}, focus:function () { if (this.iframe && !dojo.render.html.ie) { this.window.focus(); } else { if (this.object) { this.document.focus(); } else { if (this.editNode && this.editNode.focus) { this.editNode.focus(); } else { dojo.debug("Have no idea how to focus into the editor!"); } } }}, onDisplayChanged:function (e) {}, _activeX:{command:{bold:5000, italic:5023, underline:5048, justifycenter:5024, justifyleft:5025, justifyright:5026, cut:5003, copy:5002, paste:5032, "delete":5004, undo:5049, redo:5033, removeformat:5034, selectall:5035, unlink:5050, indent:5018, outdent:5031, insertorderedlist:5030, insertunorderedlist:5051, inserttable:5022, insertcell:5019, insertcol:5020, insertrow:5021, deletecells:5005, deletecols:5006, deleterows:5007, mergecells:5029, splitcell:5047, setblockformat:5043, getblockformat:5011, getblockformatnames:5012, setfontname:5044, getfontname:5013, setfontsize:5045, getfontsize:5014, setbackcolor:5042, getbackcolor:5010, setforecolor:5046, getforecolor:5015, findtext:5008, font:5009, hyperlink:5016, image:5017, lockelement:5027, makeabsolute:5028, sendbackward:5036, bringforward:5037, sendbelowtext:5038, bringabovetext:5039, sendtoback:5040, bringtofront:5041, properties:5052}, ui:{"default":0, prompt:1, noprompt:2}, status:{notsupported:0, disabled:1, enabled:3, latched:7, ninched:11}, appearance:{flat:0, inset:1}, state:{unchecked:0, checked:1, gray:2}}, _normalizeCommand:function (cmd) { var drh = dojo.render.html; var command = cmd.toLowerCase(); if (command == "formatblock") { if (drh.safari) { command = "heading"; } } else { if (this.object) { switch (command) { case "createlink": command = "hyperlink"; break; case "insertimage": command = "image"; break; } } else { if (command == "hilitecolor" && !drh.mozilla) { command = "backcolor"; } } } return command;}, _safariIsLeopard:function () { var gt420 = false; if (dojo.render.html.safari) { var tmp = dojo.render.html.UA.split("AppleWebKit/")[1]; var ver = parseFloat(tmp.split(" ")[0]); if (ver >= 420) { gt420 = true; } } return gt420;}, queryCommandAvailable:function (command) { var ie = 1; var mozilla = 1 << 1; var safari = 1 << 2; var opera = 1 << 3; var safari420 = 1 << 4; var gt420 = this._safariIsLeopard(); function isSupportedBy(browsers) { return {ie:Boolean(browsers & ie), mozilla:Boolean(browsers & mozilla), safari:Boolean(browsers & safari), safari420:Boolean(browsers & safari420), opera:Boolean(browsers & opera)}; } var supportedBy = null; switch (command.toLowerCase()) { case "bold": case "italic": case "underline": case "subscript": case "superscript": case "fontname": case "fontsize": case "forecolor": case "hilitecolor": case "justifycenter": case "justifyfull": case "justifyleft": case "justifyright": case "delete": case "selectall": supportedBy = isSupportedBy(mozilla | ie | safari | opera); break; case "createlink": case "unlink": case "removeformat": case "inserthorizontalrule": case "insertimage": case "insertorderedlist": case "insertunorderedlist": case "indent": case "outdent": case "formatblock": case "inserthtml": case "undo": case "redo": case "strikethrough": supportedBy = isSupportedBy(mozilla | ie | opera | safari420); break; case "blockdirltr": case "blockdirrtl": case "dirltr": case "dirrtl": case "inlinedirltr": case "inlinedirrtl": supportedBy = isSupportedBy(ie); break; case "cut": case "copy": case "paste": supportedBy = isSupportedBy(ie | mozilla | safari420); break; case "inserttable": supportedBy = isSupportedBy(mozilla | (this.object ? ie : 0)); break; case "insertcell": case "insertcol": case "insertrow": case "deletecells": case "deletecols": case "deleterows": case "mergecells": case "splitcell": supportedBy = isSupportedBy(this.object ? ie : 0); break; default: return false; } return (dojo.render.html.ie && supportedBy.ie) || (dojo.render.html.mozilla && supportedBy.mozilla) || (dojo.render.html.safari && supportedBy.safari) || (gt420 && supportedBy.safari420) || (dojo.render.html.opera && supportedBy.opera);}, execCommand:function (command, argument) { var returnValue; this.focus(); command = this._normalizeCommand(command); if (argument != undefined) { if (command == "heading") { throw new Error("unimplemented"); } else { if (command == "formatblock") {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -