?? richtext.js
字號:
// for (var i = 0; i < this.document.getElementsByTagName("p").length; i++) { // var p = this.document.getElementsByTagName("p")[i]; // if (p.innerHTML.match(/^<br>\s$/m)) { // while (p.hasChildNodes()) { p.parentNode.insertBefore(p.firstChild, p); } // p.parentNode.removeChild(p); // } // } //} this.onDisplayChanged(/*e*/); // can't pass in e }, 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.execCommand("selectall"); this.window.getSelection().collapseToStart(); } } }, blur: function () { if (this.iframe) { this.window.blur(); } else if (this.editNode) { this.editNode.blur(); } }, focus: function () { if(this.iframe){ this.window.focus(); }else if(this.editNode){ this.editNode.focus(); } }, /** this event will be fired everytime the display context changes and the result needs to be reflected in the UI */ onDisplayChanged: function (e){ }, /* Formatting commands **********************/ /** IE's Active X codes */ _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, // table commands inserttable: 5022, insertcell: 5019, insertcol: 5020, insertrow: 5021, deletecells: 5005, deletecols: 5006, deleterows: 5007, mergecells: 5029, splitcell: 5047, // the command need mapping, they don't translate directly // to the contentEditable commands 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 } }, /** * Used as the advice function by dojo.event.connect to map our * normalized set of commands to those supported by the target * browser * * @param arugments The arguments Array, containing at least one * item, the command and an optional second item, * an argument. */ _normalizeCommand: function (joinObject){ var drh = dojo.render.html; var command = joinObject.args[0].toLowerCase(); if(command == "formatblock"){ if(drh.safari){ command = "heading"; } if(drh.ie){ joinObject.args[1] = "<"+joinObject.args[1]+">"; } } if (command == "hilitecolor" && !drh.mozilla) { command = "backcolor"; } joinObject.args[0] = command; if (joinObject.args.length > 1) { // a command was specified var argument = joinObject.args[1]; if (command == "heading") { throw new Error("unimplemented"); } joinObject.args[1] = argument; } return joinObject.proceed(); }, /** * Tests whether a command is supported by the host. Clients SHOULD check * whether a command is supported before attempting to use it, behaviour * for unsupported commands is undefined. * * @param command The command to test for * @return true if the command is supported, false otherwise */ queryCommandAvailable: function (command) { var ie = 1; var mozilla = 1 << 1; var safari = 1 << 2; var opera = 1 << 3; function isSupportedBy (browsers) { return { ie: Boolean(browsers & ie), mozilla: Boolean(browsers & mozilla), safari: Boolean(browsers & safari), 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 "undo": case "redo": 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": supportedBy = isSupportedBy(mozilla | ie | opera); break; case "strikethrough": supportedBy = isSupportedBy(mozilla | opera | (this.object ? 0 : ie)); break; case "blockdirltr": case "blockdirrtl": case "dirltr": case "dirrtl": case "inlinedirltr": case "inlinedirrtl": case "cut": case "copy": case "paste": supportedBy = isSupportedBy(ie); 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) || (dojo.render.html.opera && supportedBy.opera); }, /** * Executes a command in the Rich Text area * * @param command The command to execute * @param argument An optional argument to the command */ execCommand: function (command, argument){ var returnValue; if(this.object){ if(command == "forecolor"){ command = "setforecolor"; }else if(command == "backcolor"){ command = "setbackcolor"; } //if (typeof this._activeX.command[command] == "undefined") { return null; } if(command == "inserttable"){ var tableInfo = this.constructor._tableInfo; if(!tableInfo){ tableInfo = document.createElement("object"); tableInfo.classid = "clsid:47B0DFC7-B7A3-11D1-ADC5-006008A5848C"; document.body.appendChild(tableInfo); this.constructor._table = tableInfo; } tableInfo.NumRows = argument["rows"]; tableInfo.NumCols = argument["cols"]; tableInfo.TableAttrs = argument["TableAttrs"]; tableInfo.CellAttrs = argument["CellAttrs"]; tableInfo.Caption = argument["Caption"]; } if(command == "inserthtml"){ var insertRange = this.document.selection.createRange(); insertRange.select(); insertRange.pasteHTML(argument); insertRange.collapse(true); return true; }else if(arguments.length == 1){ return this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt); }else{ return this.object.ExecCommand(this._activeX.command[command], this._activeX.ui.noprompt, argument); } /* */ }else if(command == "inserthtml"){ // on IE, we can use the pasteHTML method of the textRange object // to get an undo-able innerHTML modification if(dojo.render.html.ie){ dojo.debug("inserthtml breaks the undo stack when not using the ActiveX version of the control!"); var insertRange = this.document.selection.createRange(); insertRange.select(); insertRange.pasteHTML(argument); insertRange.collapse(true); return true; }else{ return this.document.execCommand(command, false, argument); } /* */ // fix up unlink in Mozilla to unlink the link and not just the selection }else if((command == "unlink")&& (this.queryCommandEnabled("unlink"))&& (dojo.render.html.mozilla)){ // 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 range = document.createRange(); var a = this.getSelectedNode(); while(a.nodeName != "A"){ a = a.parentNode; } range.selectNode(a); selection.removeAllRanges(); selection.addRange(range); returnValue = this.document.execCommand("unlink", false, null); // restore original selection var selectionRange = document.createRange(); selectionRange.setStart(selectionStartContainer, selectionStartOffset); selectionRange.setEnd(selectionEndContainer, selectionEndOffset); selection.removeAllRanges(); selection.addRange(selectionRange); return returnValue; }else if((command == "inserttable")&&(dojo.render.html.mozilla)){ var cols = "<tr>"; for (var i = 0; i < argument.cols; i++) { cols += "<td></td>"; } cols += "</tr>"; var table = "<table><tbody>"; for (var i = 0; i < argument.rows; i++) { table += cols; } table += "</tbody></table>"; returnValue = this.document.execCommand("inserthtml", false, table); }else if((command == "hilitecolor")&&(dojo.render.html.mozilla)){ // mozilla doesn't support hilitecolor properly when useCSS is // set to false (bugzilla #279330) this.document.execCommand("useCSS", false, false); returnValue = this.document.execCommand(command, false, argument); this.document.execCommand("useCSS", false, true); }else if((dojo.render.html.ie)&&( (command == "backcolor")||(command == "forecolor") )){ // 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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -