📄 sync.richtextarea.js
字号:
} rowHtml = "<tr>" + rowHtml + "</tr>"; var tableHtml = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\"><tbody>"; for (i = 0; i < rows; ++i) { tableHtml += rowHtml; } tableHtml += "</tbody></table>"; this.insertHtml(tableHtml); }, _markFocused: function() { this.client.application.setFocusedComponent(this); }, _openDialog: function(dialogWindow) { // Activate overlay pane (if required). var contentPane; if (this._overlayPane == null) { this._overlayPane = new Extras.Sync.RichTextArea.OverlayPane(); this._overlayPane._richTextArea = this.component; contentPane = new Echo.ContentPane(); this._overlayPane.add(contentPane); this.baseComponent.add(this._overlayPane); } else { contentPane = this._overlayPane.children[0]; } // Add dialog to overlay pane. contentPane.add(dialogWindow); // Add parent-change listener to dialog so that overlay pane can be // deactivated when necessary. dialogWindow.addListener("parent", this._processDialogCloseRef); }, _processCommand: function(e) { this.execCommand(e.actionCommand); this.focusDocument(); }, _processComponentInsertHtml: function(e) { this._richTextInput.peer._insertHtml(e.html); }, _processDialogClose: function(e) { if (e.newValue != null) { return; } // Deactivate overlay pane if it has no content. if (this._overlayPane.children[0].children.length === 0) { this.baseComponent.remove(this._overlayPane); this._overlayPane = null; } // Remove dialog parent-change listener. e.source.removeListener("parent", this._processDialogCloseRef); }, _processMenuAction: function(e) { if (e.modelId.charAt(0) == '/') { var separatorIndex = e.modelId.indexOf("/", 1); if (separatorIndex == -1) { this._richTextInput.peer.execCommand(e.modelId.substring(1)); } else { this._richTextInput.peer.execCommand(e.modelId.substring(1, separatorIndex), e.modelId.substring(separatorIndex + 1)); } } else { switch (e.modelId) { case "foreground": this.processSetForeground(); break; case "background": this.processSetBackground(); break; case "inserttable": this.processInsertTable(); break; case "inserthyperlink": this.processInsertHyperlink(); break; case "insertimage": this.processInsertImage(); break; case "cut": case "copy": case "paste": case "delete": try { this._richTextInput.peer.execCommand(e.modelId); } catch (ex) { this._openDialog(new Extras.Sync.RichTextArea.MessageDialog(this.component, this._msg["Generic.Error"], this._msg["Error.ClipboardAccessDisabled"])); } } } }, _removeComponentListeners: function() { this.component.removeListener("insertHtml", this._processComponentInsertHtmlRef); }, renderAdd: function(update, parentElement) { this._addComponentListeners(); this._msg = Extras.Sync.RichTextArea.resource.get(this.component.getRenderLocale()); this._icons = this.getIcons(); if (!this._icons) { this._icons = {}; } this._paneRender = this.component.parent.pane; this._mainDiv = document.createElement("div"); this._mainDiv.id = this.component.renderId; if (this._paneRender) { this._mainDiv.style.cssText = "position:absolute;top:0px;left:0px;right:0px;bottom:0px;"; } else { this._mainDiv.style.position = "relative"; // FIXME. set height of component based on height setting. this._mainDiv.style.height = "300px"; } parentElement.appendChild(this._mainDiv); }, renderDispose: function(update) { this._removeComponentListeners(); Echo.Arc.ComponentSync.prototype.renderDispose.call(this, update); this._mainDiv = null; }, renderDisplay: function() { Core.Web.VirtualPosition.redraw(this._mainDiv); Echo.Arc.ComponentSync.prototype.renderDisplay.call(this); }, renderUpdate: function(update) { if (update.isUpdatedPropertySetIn({text: true })) { this._richTextInput.peer._loadData(); update.renderContext.displayRequired = []; return; } var element = this._mainDiv; var containerElement = element.parentNode; Echo.Render.renderComponentDispose(update, update.parent); containerElement.removeChild(element); this.renderAdd(update, containerElement); }, _updateIndicators: function() { var style = this._richTextInput.peer._getCursorStyle(); if (this._toolbarButtons.bold) { this._toolbarButtons.bold.set("pressed", style.bold); } if (this._toolbarButtons.italic) { this._toolbarButtons.italic.set("pressed", style.italic); } if (this._toolbarButtons.underline) { this._toolbarButtons.underline.set("pressed", style.underline); } if (this._toolbarButtons.foreground) { this._toolbarButtons.foreground.set("color", style.foreground || "#000000"); } if (this._toolbarButtons.background) { this._toolbarButtons.background.set("color", style.background || "#ffffff"); } if (this._styleSelect) { this._styleSelect.set("selectedId", style.paragraphStyle); } }});Extras.Sync.RichTextArea.AbstractDialog = Core.extend(Echo.WindowPane, { $static: { TYPE_OK: 0, TYPE_OK_CANCEL: 1 }, $construct: function(richTextArea, type, properties, content) { this._richTextArea = richTextArea; var controlPaneSplitPaneStyleName = richTextArea.render("controlPaneSplitPaneStyleName"); var controlPaneRowStyleName = richTextArea.render("controlPaneRowStyleName"); var controlPaneButtonStyleName = richTextArea.render("controlPaneButtonStyleName"); Echo.WindowPane.call(this, { styleName: richTextArea.render("windowPaneStyleName"), iconInsets: "6px 10px", contentWidth: "25em", contentHeight: "16em", modal: true, resizable: false, events: { close: Core.method(this, this.processCancel) }, children: [ new Echo.SplitPane({ orientation: Echo.SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, autoPositioned: true, styleName: controlPaneSplitPaneStyleName, style: controlPaneSplitPaneStyleName ? null : Extras.Sync.RichTextArea.DEFAULT_CONTROL_PANE_SPLIT_PANE_STYLE, children: [ this.controlsRow = new Echo.Row({ styleName: controlPaneRowStyleName, style: controlPaneRowStyleName ? null : Extras.Sync.RichTextArea.DEFAULT_CONTROL_PANE_ROW_STYLE }), content ] }) ] }); this.controlsRow.add(new Echo.Button({ styleName: controlPaneButtonStyleName, style: controlPaneButtonStyleName ? null : Extras.Sync.RichTextArea.DEFAULT_CONTROL_PANE_BUTTON_STYLE, text: richTextArea.peer._msg["Generic.Ok"], icon: richTextArea.peer._icons.ok, events: { action: Core.method(this, this.processOk) } })); if (type == Extras.Sync.RichTextArea.AbstractDialog.TYPE_OK_CANCEL) { this.controlsRow.add(new Echo.Button({ styleName: controlPaneButtonStyleName, style: controlPaneButtonStyleName ? null : Extras.Sync.RichTextArea.DEFAULT_CONTROL_PANE_BUTTON_STYLE, text: richTextArea.peer._msg["Generic.Cancel"], icon: richTextArea.peer._icons.cancel, events: { action: Core.method(this, this.processCancel) } })); } for (var x in properties) { this.set(x, properties[x]); } }, $virtual: { processCancel: function(e) { this.parent.remove(this); }, processOk: function(e) { this.parent.remove(this); } }});Extras.Sync.RichTextArea.Html = { //FIXME Verify no illegal tags are present or correct. //FIXME Verify no unclosed tags are present or correct. //FIXME Verify no illegal characters are present or correct. //FIXME Provide option to only remove the one trailing BR we add by default. _P_BLOCK_FIND: /<p\b[^>]*>(.*?)<\/p>/ig, _P_STANDALONE_FIND: /<p\/?>/ig, _LEADING_WHITESPACE: /^(\s|<br\/?>| )+/i, _TRAILING_WHITESPACE: /(\s|<br\/?>| )+$/i, _MSIE_INVALID_FONT_COLOR_REPL: /(<font .*?color\=)(#[0-9a-fA-F]{3,6})(.*?>)/ig, _MSIE_INVALID_FONT_BACKGROUND_REPL: /(<font .*?)(background-color)/ig, /** * Cleans HTML input/output. */ clean: function(html) { html = html.replace(Extras.Sync.RichTextArea.Html._P_BLOCK_FIND, "$1<br/>"); html = html.replace(Extras.Sync.RichTextArea.Html._P_STANDALONE_FIND, "<br/>"); html = html.replace(Extras.Sync.RichTextArea.Html._LEADING_WHITESPACE, ""); html = html.replace(Extras.Sync.RichTextArea.Html._TRAILING_WHITESPACE, ""); if (Core.Web.Env.BROWSER_INTERNET_EXPLORER) { html = html.replace(Extras.Sync.RichTextArea.Html._MSIE_INVALID_FONT_COLOR_REPL, "$1\"$2\"$3"); html = html.replace(Extras.Sync.RichTextArea.Html._MSIE_INVALID_FONT_BACKGROUND_REPL, "$1background-color"); } return html; }};Extras.Sync.RichTextArea.ColorDialog = Core.extend(Extras.Sync.RichTextArea.AbstractDialog, { $static: { COLORS: [ "#fce94f", "#edd400", "#c4a000", "#fcaf3e", "#f57900", "#e8b86e", "#e9b96e", "#c17d11", "#8f5902", "#8ae234", "#73d216", "#4e9a06", "#729fcf", "#3465a4", "#204a87", "#ad7fa8", "#75507b", "#5c3566", "#ef2929", "#cc0000", "#a40000", "#eeeeec", "#d3d7cf", "#babdb6", "#888a85", "#555753", "#2e3436", "#ffffff", "#7f7f7f", "#000000" ] }, $construct: function(richTextArea, setBackground, initialColor) { Extras.Sync.RichTextArea.AbstractDialog.call(this, richTextArea, Extras.Sync.RichTextArea.AbstractDialog.TYPE_OK_CANCEL, { title: richTextArea.peer._msg[setBackground ? "ColorDialog.Title.Background" : "ColorDialog.Title.Foreground"], icon: setBackground ? richTextArea.peer._icons.background : richTextArea.peer._icons.foreground, contentWidth: "32em", contentHeight: "22em" }, new Echo.Row({ cellSpacing: "1em", insets: "1em", children: [ new Echo.Column({ children: [
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -