From 1354d17270961fff662d40f90521223f8fd0d73b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Aug 2012 18:59:10 +0400 Subject: update dojo to 1.7.3 --- lib/dijit/Editor.js | 796 +--------------------------------------------------- 1 file changed, 2 insertions(+), 794 deletions(-) (limited to 'lib/dijit/Editor.js') diff --git a/lib/dijit/Editor.js b/lib/dijit/Editor.js index b77dd7165..8ad9b2b4a 100644 --- a/lib/dijit/Editor.js +++ b/lib/dijit/Editor.js @@ -1,794 +1,2 @@ -/* - Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. - Available via Academic Free License >= 2.1 OR the modified BSD license. - see: http://dojotoolkit.org/license for details -*/ - - -if(!dojo._hasResource["dijit.Editor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dijit.Editor"] = true; -dojo.provide("dijit.Editor"); -dojo.require("dijit._editor.RichText"); -dojo.require("dijit.Toolbar"); -dojo.require("dijit.ToolbarSeparator"); -dojo.require("dijit._editor._Plugin"); -dojo.require("dijit._editor.plugins.EnterKeyHandling"); -dojo.require("dijit._editor.range"); -dojo.require("dijit._Container"); -dojo.require("dojo.i18n"); -dojo.require("dijit.layout._LayoutWidget"); -dojo.requireLocalization("dijit._editor", "commands", null, "ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); - - -dojo.declare( - "dijit.Editor", - dijit._editor.RichText, - { - // summary: - // A rich text Editing widget - // - // description: - // This widget provides basic WYSIWYG editing features, based on the browser's - // underlying rich text editing capability, accompanied by a toolbar (`dijit.Toolbar`). - // A plugin model is available to extend the editor's capabilities as well as the - // the options available in the toolbar. Content generation may vary across - // browsers, and clipboard operations may have different results, to name - // a few limitations. Note: this widget should not be used with the HTML - // <TEXTAREA> tag -- see dijit._editor.RichText for details. - - // plugins: [const] Object[] - // A list of plugin names (as strings) or instances (as objects) - // for this widget. - // - // When declared in markup, it might look like: - // | plugins="['bold',{name:'dijit._editor.plugins.FontChoice', command:'fontName', generic:true}]" - plugins: null, - - // extraPlugins: [const] Object[] - // A list of extra plugin names which will be appended to plugins array - extraPlugins: null, - - constructor: function(){ - // summary: - // Runs on widget initialization to setup arrays etc. - // tags: - // private - - if(!dojo.isArray(this.plugins)){ - this.plugins=["undo","redo","|","cut","copy","paste","|","bold","italic","underline","strikethrough","|", - "insertOrderedList","insertUnorderedList","indent","outdent","|","justifyLeft","justifyRight","justifyCenter","justifyFull", - "dijit._editor.plugins.EnterKeyHandling" /*, "createLink"*/]; - } - - this._plugins=[]; - this._editInterval = this.editActionInterval * 1000; - - //IE will always lose focus when other element gets focus, while for FF and safari, - //when no iframe is used, focus will be lost whenever another element gets focus. - //For IE, we can connect to onBeforeDeactivate, which will be called right before - //the focus is lost, so we can obtain the selected range. For other browsers, - //no equivelent of onBeforeDeactivate, so we need to do two things to make sure - //selection is properly saved before focus is lost: 1) when user clicks another - //element in the page, in which case we listen to mousedown on the entire page and - //see whether user clicks out of a focus editor, if so, save selection (focus will - //only lost after onmousedown event is fired, so we can obtain correct caret pos.) - //2) when user tabs away from the editor, which is handled in onKeyDown below. - if(dojo.isIE){ - this.events.push("onBeforeDeactivate"); - this.events.push("onBeforeActivate"); - } - }, - - postMixInProperties: function() { - // summary: - // Extension to make sure a deferred is in place before certain functions - // execute, like making sure all the plugins are properly inserted. - - // Set up a deferred so that the value isn't applied to the editor - // until all the plugins load, needed to avoid timing condition - // reported in #10537. - this.setValueDeferred = new dojo.Deferred(); - this.inherited(arguments); - }, - - postCreate: function(){ - //for custom undo/redo, if enabled. - this._steps=this._steps.slice(0); - this._undoedSteps=this._undoedSteps.slice(0); - - if(dojo.isArray(this.extraPlugins)){ - this.plugins=this.plugins.concat(this.extraPlugins); - } - - this.inherited(arguments); - - this.commands = dojo.i18n.getLocalization("dijit._editor", "commands", this.lang); - - if(!this.toolbar){ - // if we haven't been assigned a toolbar, create one - this.toolbar = new dijit.Toolbar({ - dir: this.dir, - lang: this.lang - }); - this.header.appendChild(this.toolbar.domNode); - } - - dojo.forEach(this.plugins, this.addPlugin, this); - - // Okay, denote the value can now be set. - this.setValueDeferred.callback(true); - - dojo.addClass(this.iframe.parentNode, "dijitEditorIFrameContainer"); - dojo.addClass(this.iframe, "dijitEditorIFrame"); - dojo.attr(this.iframe, "allowTransparency", true); - - if(dojo.isWebKit){ - // Disable selecting the entire editor by inadvertant double-clicks. - // on buttons, title bar, etc. Otherwise clicking too fast on - // a button such as undo/redo selects the entire editor. - dojo.style(this.domNode, "KhtmlUserSelect", "none"); - } - this.toolbar.startup(); - this.onNormalizedDisplayChanged(); //update toolbar button status - }, - destroy: function(){ - dojo.forEach(this._plugins, function(p){ - if(p && p.destroy){ - p.destroy(); - } - }); - this._plugins=[]; - this.toolbar.destroyRecursive(); - delete this.toolbar; - this.inherited(arguments); - }, - addPlugin: function(/*String||Object*/plugin, /*Integer?*/index){ - // summary: - // takes a plugin name as a string or a plugin instance and - // adds it to the toolbar and associates it with this editor - // instance. The resulting plugin is added to the Editor's - // plugins array. If index is passed, it's placed in the plugins - // array at that index. No big magic, but a nice helper for - // passing in plugin names via markup. - // - // plugin: String, args object or plugin instance - // - // args: - // This object will be passed to the plugin constructor - // - // index: Integer - // Used when creating an instance from - // something already in this.plugins. Ensures that the new - // instance is assigned to this.plugins at that index. - var args=dojo.isString(plugin)?{name:plugin}:plugin; - if(!args.setEditor){ - var o={"args":args,"plugin":null,"editor":this}; - dojo.publish(dijit._scopeName + ".Editor.getPlugin",[o]); - if(!o.plugin){ - var pc = dojo.getObject(args.name); - if(pc){ - o.plugin=new pc(args); - } - } - if(!o.plugin){ - console.warn('Cannot find plugin',plugin); - return; - } - plugin=o.plugin; - } - if(arguments.length > 1){ - this._plugins[index] = plugin; - }else{ - this._plugins.push(plugin); - } - plugin.setEditor(this); - if(dojo.isFunction(plugin.setToolbar)){ - plugin.setToolbar(this.toolbar); - } - }, - //the following 3 functions are required to make the editor play nice under a layout widget, see #4070 - startup: function(){ - // summary: - // Exists to make Editor work as a child of a layout widget. - // Developers don't need to call this method. - // tags: - // protected - //console.log('startup',arguments); - }, - resize: function(size){ - // summary: - // Resize the editor to the specified size, see `dijit.layout._LayoutWidget.resize` - if(size){ - // we've been given a height/width for the entire editor (toolbar + contents), calls layout() - // to split the allocated size between the toolbar and the contents - dijit.layout._LayoutWidget.prototype.resize.apply(this, arguments); - } - /* - else{ - // do nothing, the editor is already laid out correctly. The user has probably specified - // the height parameter, which was used to set a size on the iframe - } - */ - }, - layout: function(){ - // summary: - // Called from `dijit.layout._LayoutWidget.resize`. This shouldn't be called directly - // tags: - // protected - - // Converts the iframe (or rather the
surrounding it) to take all the available space - // except what's needed for the header (toolbars) and footer (breadcrumbs, etc). - // A class was added to the iframe container and some themes style it, so we have to - // calc off the added margins and padding too. See tracker: #10662 - var areaHeight = (this._contentBox.h - - (this.getHeaderHeight() + this.getFooterHeight() + - dojo._getPadBorderExtents(this.iframe.parentNode).h + - dojo._getMarginExtents(this.iframe.parentNode).h)); - this.editingArea.style.height = areaHeight + "px"; - if(this.iframe){ - this.iframe.style.height="100%"; - } - this._layoutMode = true; - }, - _onIEMouseDown: function(/*Event*/ e){ - // summary: - // IE only to prevent 2 clicks to focus - // tags: - // private - var outsideClientArea; - // IE 8's componentFromPoint is broken, which is a shame since it - // was smaller code, but oh well. We have to do this brute force - // to detect if the click was scroller or not. - var b = this.document.body; - var clientWidth = b.clientWidth; - var clientHeight = b.clientHeight; - var clientLeft = b.clientLeft; - var offsetWidth = b.offsetWidth; - var offsetHeight = b.offsetHeight; - var offsetLeft = b.offsetLeft; - - //Check for vertical scroller click. - bodyDir = b.dir ? b.dir.toLowerCase() : ""; - if(bodyDir != "rtl"){ - if(clientWidth < offsetWidth && e.x > clientWidth && e.x < offsetWidth){ - // Check the click was between width and offset width, if so, scroller - outsideClientArea = true; - } - }else{ - // RTL mode, we have to go by the left offsets. - if(e.x < clientLeft && e.x > offsetLeft){ - // Check the click was between width and offset width, if so, scroller - outsideClientArea = true; - } - } - if(!outsideClientArea){ - // Okay, might be horiz scroller, check that. - if(clientHeight < offsetHeight && e.y > clientHeight && e.y < offsetHeight){ - // Horizontal scroller. - outsideClientArea = true; - } - } - if(!outsideClientArea){ - delete this._cursorToStart; // Remove the force to cursor to start position. - delete this._savedSelection; // new mouse position overrides old selection - if(e.target.tagName == "BODY"){ - setTimeout(dojo.hitch(this, "placeCursorAtEnd"), 0); - } - this.inherited(arguments); - } - }, - onBeforeActivate: function(e){ - this._restoreSelection(); - }, - onBeforeDeactivate: function(e){ - // summary: - // Called on IE right before focus is lost. Saves the selected range. - // tags: - // private - if(this.customUndo){ - this.endEditing(true); - } - //in IE, the selection will be lost when other elements get focus, - //let's save focus before the editor is deactivated - if(e.target.tagName != "BODY"){ - this._saveSelection(); - } - //console.log('onBeforeDeactivate',this); - }, - - /* beginning of custom undo/redo support */ - - // customUndo: Boolean - // Whether we shall use custom undo/redo support instead of the native - // browser support. By default, we now use custom undo. It works better - // than native browser support and provides a consistent behavior across - // browsers with a minimal performance hit. We already had the hit on - // the slowest browser, IE, anyway. - customUndo: true, - - // editActionInterval: Integer - // When using customUndo, not every keystroke will be saved as a step. - // Instead typing (including delete) will be grouped together: after - // a user stops typing for editActionInterval seconds, a step will be - // saved; if a user resume typing within editActionInterval seconds, - // the timeout will be restarted. By default, editActionInterval is 3 - // seconds. - editActionInterval: 3, - - beginEditing: function(cmd){ - // summary: - // Called to note that the user has started typing alphanumeric characters, if it's not already noted. - // Deals with saving undo; see editActionInterval parameter. - // tags: - // private - if(!this._inEditing){ - this._inEditing=true; - this._beginEditing(cmd); - } - if(this.editActionInterval>0){ - if(this._editTimer){ - clearTimeout(this._editTimer); - } - this._editTimer = setTimeout(dojo.hitch(this, this.endEditing), this._editInterval); - } - }, - - // TODO: declaring these in the prototype is meaningless, just create in the constructor/postCreate - _steps:[], - _undoedSteps:[], - - execCommand: function(cmd){ - // summary: - // Main handler for executing any commands to the editor, like paste, bold, etc. - // Called by plugins, but not meant to be called by end users. - // tags: - // protected - if(this.customUndo && (cmd == 'undo' || cmd == 'redo')){ - return this[cmd](); - }else{ - if(this.customUndo){ - this.endEditing(); - this._beginEditing(); - } - var r; - var isClipboard = /copy|cut|paste/.test(cmd); - try{ - r = this.inherited(arguments); - if(dojo.isWebKit && isClipboard && !r){ //see #4598: webkit does not guarantee clipboard support from js - throw { code: 1011 }; // throw an object like Mozilla's error - } - }catch(e){ - //TODO: when else might we get an exception? Do we need the Mozilla test below? - if(e.code == 1011 /* Mozilla: service denied */ && isClipboard){ - // Warn user of platform limitation. Cannot programmatically access clipboard. See ticket #4136 - var sub = dojo.string.substitute, - accel = {cut:'X', copy:'C', paste:'V'}; - alert(sub(this.commands.systemShortcut, - [this.commands[cmd], sub(this.commands[dojo.isMac ? 'appleKey' : 'ctrlKey'], [accel[cmd]])])); - } - r = false; - } - if(this.customUndo){ - this._endEditing(); - } - return r; - } - }, - queryCommandEnabled: function(cmd){ - // summary: - // Returns true if specified editor command is enabled. - // Used by the plugins to know when to highlight/not highlight buttons. - // tags: - // protected - if(this.customUndo && (cmd == 'undo' || cmd == 'redo')){ - return cmd == 'undo' ? (this._steps.length > 1) : (this._undoedSteps.length > 0); - }else{ - return this.inherited(arguments); - } - }, - _moveToBookmark: function(b){ - // summary: - // Selects the text specified in bookmark b - // tags: - // private - var bookmark = b.mark; - var mark = b.mark; - var col = b.isCollapsed; - var r, sNode, eNode, sel; - if(mark){ - if(dojo.isIE < 9){ - if(dojo.isArray(mark)){ - //IE CONTROL, have to use the native bookmark. - bookmark = []; - dojo.forEach(mark,function(n){ - bookmark.push(dijit.range.getNode(n,this.editNode)); - },this); - dojo.withGlobal(this.window,'moveToBookmark',dijit,[{mark: bookmark, isCollapsed: col}]); - }else{ - if(mark.startContainer && mark.endContainer){ - // Use the pseudo WC3 range API. This works better for positions - // than the IE native bookmark code. - sel = dijit.range.getSelection(this.window); - if(sel && sel.removeAllRanges){ - sel.removeAllRanges(); - r = dijit.range.create(this.window); - sNode = dijit.range.getNode(mark.startContainer,this.editNode); - eNode = dijit.range.getNode(mark.endContainer,this.editNode); - if(sNode && eNode){ - // Okay, we believe we found the position, so add it into the selection - // There are cases where it may not be found, particularly in undo/redo, when - // IE changes the underlying DOM on us (wraps text in a

tag or similar. - // So, in those cases, don't bother restoring selection. - r.setStart(sNode,mark.startOffset); - r.setEnd(eNode,mark.endOffset); - sel.addRange(r); - } - } - } - } - }else{//w3c range - sel = dijit.range.getSelection(this.window); - if(sel && sel.removeAllRanges){ - sel.removeAllRanges(); - r = dijit.range.create(this.window); - sNode = dijit.range.getNode(mark.startContainer,this.editNode); - eNode = dijit.range.getNode(mark.endContainer,this.editNode); - if(sNode && eNode){ - // Okay, we believe we found the position, so add it into the selection - // There are cases where it may not be found, particularly in undo/redo, when - // formatting as been done and so on, so don't restore selection then. - r.setStart(sNode,mark.startOffset); - r.setEnd(eNode,mark.endOffset); - sel.addRange(r); - } - } - } - } - }, - _changeToStep: function(from, to){ - // summary: - // Reverts editor to "to" setting, from the undo stack. - // tags: - // private - this.setValue(to.text); - var b=to.bookmark; - if(!b){ return; } - this._moveToBookmark(b); - }, - undo: function(){ - // summary: - // Handler for editor undo (ex: ctrl-z) operation - // tags: - // private - //console.log('undo'); - var ret = false; - if(!this._undoRedoActive){ - this._undoRedoActive = true; - this.endEditing(true); - var s=this._steps.pop(); - if(s && this._steps.length>0){ - this.focus(); - this._changeToStep(s,this._steps[this._steps.length-1]); - this._undoedSteps.push(s); - this.onDisplayChanged(); - delete this._undoRedoActive; - ret = true; - } - delete this._undoRedoActive; - } - return ret; - }, - redo: function(){ - // summary: - // Handler for editor redo (ex: ctrl-y) operation - // tags: - // private - //console.log('redo'); - var ret = false; - if(!this._undoRedoActive){ - this._undoRedoActive = true; - this.endEditing(true); - var s=this._undoedSteps.pop(); - if(s && this._steps.length>0){ - this.focus(); - this._changeToStep(this._steps[this._steps.length-1],s); - this._steps.push(s); - this.onDisplayChanged(); - ret = true; - } - delete this._undoRedoActive; - } - return ret; - }, - endEditing: function(ignore_caret){ - // summary: - // Called to note that the user has stopped typing alphanumeric characters, if it's not already noted. - // Deals with saving undo; see editActionInterval parameter. - // tags: - // private - if(this._editTimer){ - clearTimeout(this._editTimer); - } - if(this._inEditing){ - this._endEditing(ignore_caret); - this._inEditing=false; - } - }, - - _getBookmark: function(){ - // summary: - // Get the currently selected text - // tags: - // protected - var b=dojo.withGlobal(this.window,dijit.getBookmark); - var tmp=[]; - if(b && b.mark){ - var mark = b.mark; - if(dojo.isIE < 9){ - // Try to use the pseudo range API on IE for better accuracy. - var sel = dijit.range.getSelection(this.window); - if(!dojo.isArray(mark)){ - if(sel){ - var range; - if(sel.rangeCount){ - range = sel.getRangeAt(0); - } - if(range){ - b.mark = range.cloneRange(); - }else{ - b.mark = dojo.withGlobal(this.window,dijit.getBookmark); - } - } - }else{ - // Control ranges (img, table, etc), handle differently. - dojo.forEach(b.mark,function(n){ - tmp.push(dijit.range.getIndex(n,this.editNode).o); - },this); - b.mark = tmp; - } - } - try{ - if(b.mark && b.mark.startContainer){ - tmp=dijit.range.getIndex(b.mark.startContainer,this.editNode).o; - b.mark={startContainer:tmp, - startOffset:b.mark.startOffset, - endContainer:b.mark.endContainer===b.mark.startContainer?tmp:dijit.range.getIndex(b.mark.endContainer,this.editNode).o, - endOffset:b.mark.endOffset}; - } - }catch(e){ - b.mark = null; - } - } - return b; - }, - _beginEditing: function(cmd){ - // summary: - // Called when the user starts typing alphanumeric characters. - // Deals with saving undo; see editActionInterval parameter. - // tags: - // private - if(this._steps.length === 0){ - // You want to use the editor content without post filtering - // to make sure selection restores right for the 'initial' state. - // and undo is called. So not using this.value, as it was 'processed' - // and the line-up for selections may have been altered. - this._steps.push({'text':dijit._editor.getChildrenHtml(this.editNode),'bookmark':this._getBookmark()}); - } - }, - _endEditing: function(ignore_caret){ - // summary: - // Called when the user stops typing alphanumeric characters. - // Deals with saving undo; see editActionInterval parameter. - // tags: - // private - // Avoid filtering to make sure selections restore. - var v = dijit._editor.getChildrenHtml(this.editNode); - - this._undoedSteps=[];//clear undoed steps - this._steps.push({text: v, bookmark: this._getBookmark()}); - }, - onKeyDown: function(e){ - // summary: - // Handler for onkeydown event. - // tags: - // private - - //We need to save selection if the user TAB away from this editor - //no need to call _saveSelection for IE, as that will be taken care of in onBeforeDeactivate - if(!dojo.isIE && !this.iframe && e.keyCode == dojo.keys.TAB && !this.tabIndent){ - this._saveSelection(); - } - if(!this.customUndo){ - this.inherited(arguments); - return; - } - var k = e.keyCode, ks = dojo.keys; - if(e.ctrlKey && !e.altKey){//undo and redo only if the special right Alt + z/y are not pressed #5892 - if(k == 90 || k == 122){ //z - dojo.stopEvent(e); - this.undo(); - return; - }else if(k == 89 || k == 121){ //y - dojo.stopEvent(e); - this.redo(); - return; - } - } - this.inherited(arguments); - - switch(k){ - case ks.ENTER: - case ks.BACKSPACE: - case ks.DELETE: - this.beginEditing(); - break; - case 88: //x - case 86: //v - if(e.ctrlKey && !e.altKey && !e.metaKey){ - this.endEditing();//end current typing step if any - if(e.keyCode == 88){ - this.beginEditing('cut'); - //use timeout to trigger after the cut is complete - setTimeout(dojo.hitch(this, this.endEditing), 1); - }else{ - this.beginEditing('paste'); - //use timeout to trigger after the paste is complete - setTimeout(dojo.hitch(this, this.endEditing), 1); - } - break; - } - //pass through - default: - if(!e.ctrlKey && !e.altKey && !e.metaKey && (e.keyCodedojo.keys.F15)){ - this.beginEditing(); - break; - } - //pass through - case ks.ALT: - this.endEditing(); - break; - case ks.UP_ARROW: - case ks.DOWN_ARROW: - case ks.LEFT_ARROW: - case ks.RIGHT_ARROW: - case ks.HOME: - case ks.END: - case ks.PAGE_UP: - case ks.PAGE_DOWN: - this.endEditing(true); - break; - //maybe ctrl+backspace/delete, so don't endEditing when ctrl is pressed - case ks.CTRL: - case ks.SHIFT: - case ks.TAB: - break; - } - }, - _onBlur: function(){ - // summary: - // Called from focus manager when focus has moved away from this editor - // tags: - // protected - - //this._saveSelection(); - this.inherited(arguments); - this.endEditing(true); - }, - _saveSelection: function(){ - // summary: - // Save the currently selected text in _savedSelection attribute - // tags: - // private - try{ - this._savedSelection=this._getBookmark(); - }catch(e){ /* Squelch any errors that occur if selection save occurs due to being hidden simultaniously. */} - }, - _restoreSelection: function(){ - // summary: - // Re-select the text specified in _savedSelection attribute; - // see _saveSelection(). - // tags: - // private - if(this._savedSelection){ - // Clear off cursor to start, we're deliberately going to a selection. - delete this._cursorToStart; - // only restore the selection if the current range is collapsed - // if not collapsed, then it means the editor does not lose - // selection and there is no need to restore it - if(dojo.withGlobal(this.window,'isCollapsed',dijit)){ - this._moveToBookmark(this._savedSelection); - } - delete this._savedSelection; - } - }, - - onClick: function(){ - // summary: - // Handler for when editor is clicked - // tags: - // protected - this.endEditing(true); - this.inherited(arguments); - }, - - replaceValue: function(/*String*/ html){ - // summary: - // over-ride of replaceValue to support custom undo and stack maintainence. - // tags: - // protected - if(!this.customUndo){ - this.inherited(arguments); - }else{ - if(this.isClosed){ - this.setValue(html); - }else{ - this.beginEditing(); - if(!html){ - html = " " - } - this.setValue(html); - this.endEditing(); - } - } - }, - - _setDisabledAttr: function(/*Boolean*/ value){ - var disableFunc = dojo.hitch(this, function(){ - if((!this.disabled && value) || (!this._buttonEnabledPlugins && value)){ - // Disable editor: disable all enabled buttons and remember that list - dojo.forEach(this._plugins, function(p){ - p.set("disabled", true); - }); - }else if(this.disabled && !value){ - // Restore plugins to being active. - dojo.forEach(this._plugins, function(p){ - p.set("disabled", false); - }); - } - }); - this.setValueDeferred.addCallback(disableFunc); - this.inherited(arguments); - }, - - _setStateClass: function(){ - try{ - this.inherited(arguments); - - // Let theme set the editor's text color based on editor enabled/disabled state. - // We need to jump through hoops because the main document (where the theme CSS is) - // is separate from the iframe's document. - if(this.document && this.document.body){ - dojo.style(this.document.body, "color", dojo.style(this.iframe, "color")); - } - }catch(e){ /* Squelch any errors caused by focus change if hidden during a state change */} - } - } -); - -// Register the "default plugins", ie, the built-in editor commands -dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ - if(o.plugin){ return; } - var args = o.args, p; - var _p = dijit._editor._Plugin; - var name = args.name; - switch(name){ - case "undo": case "redo": case "cut": case "copy": case "paste": case "insertOrderedList": - case "insertUnorderedList": case "indent": case "outdent": case "justifyCenter": - case "justifyFull": case "justifyLeft": case "justifyRight": case "delete": - case "selectAll": case "removeFormat": case "unlink": - case "insertHorizontalRule": - p = new _p({ command: name }); - break; - - case "bold": case "italic": case "underline": case "strikethrough": - case "subscript": case "superscript": - p = new _p({ buttonClass: dijit.form.ToggleButton, command: name }); - break; - case "|": - p = new _p({ button: new dijit.ToolbarSeparator(), setEditor: function(editor) {this.editor = editor;} }); - } -// console.log('name',name,p); - o.plugin=p; -}); - -} +//>>built +define("dijit/Editor",["dojo/_base/array","dojo/_base/declare","dojo/_base/Deferred","dojo/i18n","dojo/dom-attr","dojo/dom-class","dojo/dom-geometry","dojo/dom-style","dojo/_base/event","dojo/keys","dojo/_base/lang","dojo/_base/sniff","dojo/string","dojo/topic","dojo/_base/window","./_base/focus","./_Container","./Toolbar","./ToolbarSeparator","./layout/_LayoutWidget","./form/ToggleButton","./_editor/_Plugin","./_editor/plugins/EnterKeyHandling","./_editor/html","./_editor/range","./_editor/RichText",".","dojo/i18n!./_editor/nls/commands"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_1a,_1b){var _1c=_2("dijit.Editor",_1a,{plugins:null,extraPlugins:null,constructor:function(){if(!_b.isArray(this.plugins)){this.plugins=["undo","redo","|","cut","copy","paste","|","bold","italic","underline","strikethrough","|","insertOrderedList","insertUnorderedList","indent","outdent","|","justifyLeft","justifyRight","justifyCenter","justifyFull",_17];}this._plugins=[];this._editInterval=this.editActionInterval*1000;if(_c("ie")){this.events.push("onBeforeDeactivate");this.events.push("onBeforeActivate");}},postMixInProperties:function(){this.setValueDeferred=new _3();this.inherited(arguments);},postCreate:function(){this._steps=this._steps.slice(0);this._undoedSteps=this._undoedSteps.slice(0);if(_b.isArray(this.extraPlugins)){this.plugins=this.plugins.concat(this.extraPlugins);}this.inherited(arguments);this.commands=_4.getLocalization("dijit._editor","commands",this.lang);if(!this.toolbar){this.toolbar=new _12({dir:this.dir,lang:this.lang});this.header.appendChild(this.toolbar.domNode);}_1.forEach(this.plugins,this.addPlugin,this);this.setValueDeferred.callback(true);_6.add(this.iframe.parentNode,"dijitEditorIFrameContainer");_6.add(this.iframe,"dijitEditorIFrame");_5.set(this.iframe,"allowTransparency",true);if(_c("webkit")){_8.set(this.domNode,"KhtmlUserSelect","none");}this.toolbar.startup();this.onNormalizedDisplayChanged();},destroy:function(){_1.forEach(this._plugins,function(p){if(p&&p.destroy){p.destroy();}});this._plugins=[];this.toolbar.destroyRecursive();delete this.toolbar;this.inherited(arguments);},addPlugin:function(_1d,_1e){var _1f=_b.isString(_1d)?{name:_1d}:_b.isFunction(_1d)?{ctor:_1d}:_1d;if(!_1f.setEditor){var o={"args":_1f,"plugin":null,"editor":this};if(_1f.name){if(_16.registry[_1f.name]){o.plugin=_16.registry[_1f.name](_1f);}else{_e.publish(_1b._scopeName+".Editor.getPlugin",o);}}if(!o.plugin){var pc=_1f.ctor||_b.getObject(_1f.name);if(pc){o.plugin=new pc(_1f);}}if(!o.plugin){console.warn("Cannot find plugin",_1d);return;}_1d=o.plugin;}if(arguments.length>1){this._plugins[_1e]=_1d;}else{this._plugins.push(_1d);}_1d.setEditor(this);if(_b.isFunction(_1d.setToolbar)){_1d.setToolbar(this.toolbar);}},resize:function(_20){if(_20){_14.prototype.resize.apply(this,arguments);}},layout:function(){var _21=(this._contentBox.h-(this.getHeaderHeight()+this.getFooterHeight()+_7.getPadBorderExtents(this.iframe.parentNode).h+_7.getMarginExtents(this.iframe.parentNode).h));this.editingArea.style.height=_21+"px";if(this.iframe){this.iframe.style.height="100%";}this._layoutMode=true;},_onIEMouseDown:function(e){var _22;var b=this.document.body;var _23=b.clientWidth;var _24=b.clientHeight;var _25=b.clientLeft;var _26=b.offsetWidth;var _27=b.offsetHeight;var _28=b.offsetLeft;if(/^rtl$/i.test(b.dir||"")){if(_23<_26&&e.x>_23&&e.x<_26){_22=true;}}else{if(e.x<_25&&e.x>_28){_22=true;}}if(!_22){if(_24<_27&&e.y>_24&&e.y<_27){_22=true;}}if(!_22){delete this._cursorToStart;delete this._savedSelection;if(e.target.tagName=="BODY"){setTimeout(_b.hitch(this,"placeCursorAtEnd"),0);}this.inherited(arguments);}},onBeforeActivate:function(){this._restoreSelection();},onBeforeDeactivate:function(e){if(this.customUndo){this.endEditing(true);}if(e.target.tagName!="BODY"){this._saveSelection();}},customUndo:true,editActionInterval:3,beginEditing:function(cmd){if(!this._inEditing){this._inEditing=true;this._beginEditing(cmd);}if(this.editActionInterval>0){if(this._editTimer){clearTimeout(this._editTimer);}this._editTimer=setTimeout(_b.hitch(this,this.endEditing),this._editInterval);}},_steps:[],_undoedSteps:[],execCommand:function(cmd){if(this.customUndo&&(cmd=="undo"||cmd=="redo")){return this[cmd]();}else{if(this.customUndo){this.endEditing();this._beginEditing();}var r=this.inherited(arguments);if(this.customUndo){this._endEditing();}return r;}},_pasteImpl:function(){return this._clipboardCommand("paste");},_cutImpl:function(){return this._clipboardCommand("cut");},_copyImpl:function(){return this._clipboardCommand("copy");},_clipboardCommand:function(cmd){var r;try{r=this.document.execCommand(cmd,false,null);if(_c("webkit")&&!r){throw {code:1011};}}catch(e){if(e.code==1011){var sub=_d.substitute,_29={cut:"X",copy:"C",paste:"V"};alert(sub(this.commands.systemShortcut,[this.commands[cmd],sub(this.commands[_c("mac")?"appleKey":"ctrlKey"],[_29[cmd]])]));}r=false;}return r;},queryCommandEnabled:function(cmd){if(this.customUndo&&(cmd=="undo"||cmd=="redo")){return cmd=="undo"?(this._steps.length>1):(this._undoedSteps.length>0);}else{return this.inherited(arguments);}},_moveToBookmark:function(b){var _2a=b.mark;var _2b=b.mark;var col=b.isCollapsed;var r,_2c,_2d,sel;if(_2b){if(_c("ie")<9){if(_b.isArray(_2b)){_2a=[];_1.forEach(_2b,function(n){_2a.push(_19.getNode(n,this.editNode));},this);_f.withGlobal(this.window,"moveToBookmark",_1b,[{mark:_2a,isCollapsed:col}]);}else{if(_2b.startContainer&&_2b.endContainer){sel=_19.getSelection(this.window);if(sel&&sel.removeAllRanges){sel.removeAllRanges();r=_19.create(this.window);_2c=_19.getNode(_2b.startContainer,this.editNode);_2d=_19.getNode(_2b.endContainer,this.editNode);if(_2c&&_2d){r.setStart(_2c,_2b.startOffset);r.setEnd(_2d,_2b.endOffset);sel.addRange(r);}}}}}else{sel=_19.getSelection(this.window);if(sel&&sel.removeAllRanges){sel.removeAllRanges();r=_19.create(this.window);_2c=_19.getNode(_2b.startContainer,this.editNode);_2d=_19.getNode(_2b.endContainer,this.editNode);if(_2c&&_2d){r.setStart(_2c,_2b.startOffset);r.setEnd(_2d,_2b.endOffset);sel.addRange(r);}}}}},_changeToStep:function(_2e,to){this.setValue(to.text);var b=to.bookmark;if(!b){return;}this._moveToBookmark(b);},undo:function(){var ret=false;if(!this._undoRedoActive){this._undoRedoActive=true;this.endEditing(true);var s=this._steps.pop();if(s&&this._steps.length>0){this.focus();this._changeToStep(s,this._steps[this._steps.length-1]);this._undoedSteps.push(s);this.onDisplayChanged();delete this._undoRedoActive;ret=true;}delete this._undoRedoActive;}return ret;},redo:function(){var ret=false;if(!this._undoRedoActive){this._undoRedoActive=true;this.endEditing(true);var s=this._undoedSteps.pop();if(s&&this._steps.length>0){this.focus();this._changeToStep(this._steps[this._steps.length-1],s);this._steps.push(s);this.onDisplayChanged();ret=true;}delete this._undoRedoActive;}return ret;},endEditing:function(_2f){if(this._editTimer){clearTimeout(this._editTimer);}if(this._inEditing){this._endEditing(_2f);this._inEditing=false;}},_getBookmark:function(){var b=_f.withGlobal(this.window,_10.getBookmark);var tmp=[];if(b&&b.mark){var _30=b.mark;if(_c("ie")<9){var sel=_19.getSelection(this.window);if(!_b.isArray(_30)){if(sel){var _31;if(sel.rangeCount){_31=sel.getRangeAt(0);}if(_31){b.mark=_31.cloneRange();}else{b.mark=_f.withGlobal(this.window,_10.getBookmark);}}}else{_1.forEach(b.mark,function(n){tmp.push(_19.getIndex(n,this.editNode).o);},this);b.mark=tmp;}}try{if(b.mark&&b.mark.startContainer){tmp=_19.getIndex(b.mark.startContainer,this.editNode).o;b.mark={startContainer:tmp,startOffset:b.mark.startOffset,endContainer:b.mark.endContainer===b.mark.startContainer?tmp:_19.getIndex(b.mark.endContainer,this.editNode).o,endOffset:b.mark.endOffset};}}catch(e){b.mark=null;}}return b;},_beginEditing:function(){if(this._steps.length===0){this._steps.push({"text":_18.getChildrenHtml(this.editNode),"bookmark":this._getBookmark()});}},_endEditing:function(){var v=_18.getChildrenHtml(this.editNode);this._undoedSteps=[];this._steps.push({text:v,bookmark:this._getBookmark()});},onKeyDown:function(e){if(!_c("ie")&&!this.iframe&&e.keyCode==_a.TAB&&!this.tabIndent){this._saveSelection();}if(!this.customUndo){this.inherited(arguments);return;}var k=e.keyCode;if(e.ctrlKey&&!e.altKey){if(k==90||k==122){_9.stop(e);this.undo();return;}else{if(k==89||k==121){_9.stop(e);this.redo();return;}}}this.inherited(arguments);switch(k){case _a.ENTER:case _a.BACKSPACE:case _a.DELETE:this.beginEditing();break;case 88:case 86:if(e.ctrlKey&&!e.altKey&&!e.metaKey){this.endEditing();if(e.keyCode==88){this.beginEditing("cut");setTimeout(_b.hitch(this,this.endEditing),1);}else{this.beginEditing("paste");setTimeout(_b.hitch(this,this.endEditing),1);}break;}default:if(!e.ctrlKey&&!e.altKey&&!e.metaKey&&(e.keyCode<_a.F1||e.keyCode>_a.F15)){this.beginEditing();break;}case _a.ALT:this.endEditing();break;case _a.UP_ARROW:case _a.DOWN_ARROW:case _a.LEFT_ARROW:case _a.RIGHT_ARROW:case _a.HOME:case _a.END:case _a.PAGE_UP:case _a.PAGE_DOWN:this.endEditing(true);break;case _a.CTRL:case _a.SHIFT:case _a.TAB:break;}},_onBlur:function(){this.inherited(arguments);this.endEditing(true);},_saveSelection:function(){try{this._savedSelection=this._getBookmark();}catch(e){}},_restoreSelection:function(){if(this._savedSelection){delete this._cursorToStart;if(_f.withGlobal(this.window,"isCollapsed",_1b)){this._moveToBookmark(this._savedSelection);}delete this._savedSelection;}},onClick:function(){this.endEditing(true);this.inherited(arguments);},replaceValue:function(_32){if(!this.customUndo){this.inherited(arguments);}else{if(this.isClosed){this.setValue(_32);}else{this.beginEditing();if(!_32){_32=" ";}this.setValue(_32);this.endEditing();}}},_setDisabledAttr:function(_33){var _34=_b.hitch(this,function(){if((!this.disabled&&_33)||(!this._buttonEnabledPlugins&&_33)){_1.forEach(this._plugins,function(p){p.set("disabled",true);});}else{if(this.disabled&&!_33){_1.forEach(this._plugins,function(p){p.set("disabled",false);});}}});this.setValueDeferred.addCallback(_34);this.inherited(arguments);},_setStateClass:function(){try{this.inherited(arguments);if(this.document&&this.document.body){_8.set(this.document.body,"color",_8.get(this.iframe,"color"));}}catch(e){}}});function _35(_36){return new _16({command:_36.name});};function _37(_38){return new _16({buttonClass:_15,command:_38.name});};_b.mixin(_16.registry,{"undo":_35,"redo":_35,"cut":_35,"copy":_35,"paste":_35,"insertOrderedList":_35,"insertUnorderedList":_35,"indent":_35,"outdent":_35,"justifyCenter":_35,"justifyFull":_35,"justifyLeft":_35,"justifyRight":_35,"delete":_35,"selectAll":_35,"removeFormat":_35,"unlink":_35,"insertHorizontalRule":_35,"bold":_37,"italic":_37,"underline":_37,"strikethrough":_37,"subscript":_37,"superscript":_37,"|":function(){return new _16({button:new _13(),setEditor:function(_39){this.editor=_39;}});}});return _1c;}); \ No newline at end of file -- cgit v1.2.3