📄 richtexteditor.js
字号:
isc.RichTextEditor.addProperties({ dragStartDistance:1, // On init, create our toolbar / RichTextCanvas contents area. initWidget : function () { this.Super("initWidget", arguments); this.createChildren(); }, doWarn : function () { isc.warn("Warning: Not all Rich Text Editing features are supported in this browser."); }, createChildren : function () { // call on a delay to avoid this warning dialog being trapped by the FE as a managed // component that gets destroyed when the example is unloaded. Leads to a crash as we // try to reuse the destroyed object. if (!this.richEditorSupported()) this.delayCall("doWarn"); if (!this.autoChildDefaults) this.autoChildDefaults = {}; // Set up the default width / click handler for control buttons this.autoChildDefaults.width = this.controlButtonWidth; this.autoChildDefaults.click = "if (this.isControl && isc.isA.StatefulCanvas(this)) this.creator.fireAction(this.controlName)"; if (this.toolbarHeight > 0) this._createToolbar(); this.addAutoChild("editArea", { top:this.toolbarHeight, className:this.editAreaClassName, backgroundColor:this.editAreaBackgroundColor, left:0, width:"100%", height:"*", contents:this.value, // This ensures the tabIndices match when the thing is first // written out getTabIndex:function () { if (this.parentElement) return this.parentElement.getTabIndex() return -1; }, changed : isc.RichTextEditor._canvasContentsChanged, getBrowserSpellCheck : function () { return this.parentElement.getBrowserSpellCheck() } }); }, richEditorSupported : function () { return !(isc.Browser.isSafari || isc.Browser.isOpera); }, // browserSpellCheck is a boolean property to enable / disable native browser checking of // spelling, where supported. // This currently only has an effect in Moz // By default return this.browserSpellCheck if specified. Overridden for RichTextItems. getBrowserSpellCheck : function () { return this.browserSpellCheck; }, // Toolbar _createToolbar : function () { // Picks up HLayout constructor from this.toolbarConstructor this.addAutoChild("toolbar", { top:0, left:0, width:"100%", height:this.toolbarHeight, // Make the toolbar overflow:"visible" - if it exceeds the availableSpace we'll allow // the editor itself to decide whether it should be clipped overflow:isc.Canvas.VISIBLE, backgroundColor:this.toolbarBackgroundColor }); // this.controlGroups is an array of groups to show. // each group is an array of controls to create (within the group). for (var i = 0; i < this.controlGroups.length; i++) { // Add separators between the groups. if (i > 0) this.toolbar.addMember(this._createToolbarSeparator()); var controlNames = this[this.controlGroups[i]]; if (!controlNames) { this.logWarn("Unable to find countrol group '" + this.controlGroups[i] + "'. This group should be specified as an array of " + "control names, but is not present"); continue; } for (var j=0; j < controlNames.length; j++) { // use 'addAutoChild' to create the controls and add them to the toolbar as // children. this.addAutoChild( controlNames[j], // These properties used by the default click handler for controls {canFocus:false, isControl:true, controlName:controlNames[j], layoutAlign:isc.Canvas.CENTER}, this.defaultControlConstructor, this.toolbar ); } } }, // Separator bar to write between control groups _createToolbarSeparator : function () { if (!this._separatorProps) this._separatorProps = { autoDraw:false, width:12, height:"100%", src:this.toolbarSeparatorSrc }; return isc.Img.create(this._separatorProps); }, // For tabbing / focussing purposes, this editor should pass straight through to the // editArea setFocus : function (newFocus) { var editArea = this.editArea; if (!editArea) return; return editArea.setFocus(newFocus); }, _setTabIndex : function (tabIndex, auto) { this.Super("_setTabIndex", arguments); if (this.editArea) this.editArea._setTabIndex(this.getTabIndex(), auto); }, // For the font / font-size selector, we want to show a "choose font" type prompt rather // than an empty selector. _makeFontMap : function(prompt, options) { // Add the empty 'select a font size' message and return var map = { _prompt:prompt }; return isc.addProperties(map, options); }, _makeFontNamesMap : function () { return this._makeFontMap("Set Font ...", this.fontNames); }, _makeFontSizesMap : function () { return this._makeFontMap("Set Font Size ...", this.fontSizes); }, // Special constructor functions for font / font-size selector controls fontSelector_autoMaker : function (properties) { isc.addProperties( properties, { numCols:1, cellPadding:1, items:[ // Disable tabbing into the select items {type:"select", name:"fontname", showTitle:false, tabIndex:-1, pickListProperties : { cellHeight:16, // Override 'getCellValue' to preview the font. getCellValue : function (record, recordNum, fieldNum) { var val = this.Super("getCellValue", arguments), fontName = record ? record.fontname : null; if (fontName && fontName != "_prompt") { val = "<SPAN style='font-family:" + fontName + ";'>" + val + "</SPAN>"; } return val; } }, defaultValue:"_prompt", valueMap:this._makeFontNamesMap(), pickValue : function(value) { this.Super("pickValue", arguments); if (value != "_prompt") { this.form.creator.fireAction('setSelectionFont', value); } } } ]} ); return this.createAutoChild("fontSelector", properties); }, fontSizeSelector_autoMaker : function (properties) { isc.addProperties( properties, { numCols:1, cellPadding:1, items:[ {type:"select", name:"fontsize", showTitle:false, tabIndex:-1, defaultValue:"_prompt", valueMap:this._makeFontSizesMap(), // See comments in fontSizeSelector_autoMaker for why we override // pickValue rather than implementing a change handler. pickValue : function(value) { this.Super("pickValue", arguments); if (value != "_prompt") { this.form.creator.fireAction('setSelectionFontSize', value); } } } ]} ); return this.createAutoChild("fontSizeSelector", properties); }, //>@method RichTextEditor.fireAction // This method takes 2 parameters - an "action" (string) and an optional "param" parameter // (can by anything). // It will attempt to call action() on the its editArea, which is a RichTextCanvas instance, // passing in the 'param' as a parameter. // (No-ops if this.editArea.action is not a method). //< fireAction : function (action, param) { var editArea = this.editArea; if (!editArea || !action || !editArea[action] || !isc.isA.Function(editArea[action])) return; this.editArea[action](param); }, // Special handlers for picking colors: // Use a colorChooser widget (for both setting text and background colors) chooseColor : function (selectingTextColor) { if (!this.colorChooser) { this.colorChooser = isc.ColorChooser.create({ creator:this, ID:this.getID() + "_colorChooser", // Avoid showing the auto / transparent button for picking a null color showNullValue:false, colorSelected : function (color) { this.creator._colorSelected(color); }, // Override cancel to put focus back into the edit area cancel : function () { this.Super("cancel", arguments); this.creator.editArea.focus(); } }) } this._selectingTextColor = selectingTextColor; this.colorChooser.show(); }, _colorSelected : function (color) { var action = this._selectingTextColor ? "setSelectionColor" : "setSelectionBackgroundColor"; delete this._selectingTextColor; this.fireAction(action, color); }, chooseTextColor : function () { this.chooseColor(true); }, chooseBackgroundColor : function () { this.chooseColor(false); }, // Retrieving / updating content: _valueChanged : function (oldValue, newValue) { if (this.valueChanged) this.valueChanged(oldValue, newValue); }, //>@method RichTextEditor.valueChanged() // StringMethod fired when the user edits the editor's value. Will not be fired in // response to an explicit <code>setValue</code> call. // @param oldValue Value before the edit // @param newValue Value now //< //>@method RichTextEditor.getValue() // Retrieves the current value of the edit area. // @visibility external //< getValue : function () { if (this.editArea) this.value = this.editArea.getContents(); return this.value; }, //>@method RichTextEditor.setValue() // Updates the current value of the edit area. // @visibility external //< setValue : function (newValue) { this.value = newValue; if (this.editArea) this.editArea.setContents(this.value); } });//!<Deferredisc.RichTextEditor.registerStringMethods({ valueChanged : "oldValue,newValue"});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -