/** * Editor.js * * Copyright 2009, Moxiecode Systems AB * Released under LGPL License. * * License: http://tinymce.moxiecode.com/license * Contributing: http://tinymce.moxiecode.com/contributing */ (function(tinymce) { // Shorten these names var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is, ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode; /** * This class contains the core logic for a TinyMCE editor. * * @class tinymce.Editor * @author Moxiecode * @example * // Add a class to all paragraphs in the editor. * tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.dom.select('p'), 'someclass'); * * // Gets the current editors selection as text * tinyMCE.activeEditor.selection.getContent({format : 'text'}); * * // Creates a new editor instance * var ed = new tinymce.Editor('textareaid', { * some_setting : 1 * }); * * // Select each item the user clicks on * ed.onClick.add(function(ed, e) { * ed.selection.select(e.target); * }); * * ed.render(); */ tinymce.create('tinymce.Editor', { /** * Constructs a editor instance by id. * * @constructor * @method Editor * @param {String} id Unique id for the editor. * @param {Object} s Optional settings string for the editor. * @author Moxiecode */ Editor : function(id, s) { var t = this; /** * Editor instance id, normally the same as the div/textarea that was replaced. * * @property id * @type String */ t.id = t.editorId = id; t.execCommands = {}; t.queryStateCommands = {}; t.queryValueCommands = {}; /** * State to force the editor to return false on a isDirty call. * * @property isNotDirty * @type Boolean */ t.isNotDirty = false; /** * Name/Value object containting plugin instances. * * @property plugins * @type Object */ t.plugins = {}; // Add events to the editor each([ /** * Fires before the initialization of the editor. * * @event onPreInit * @param {tinymce.Editor} sender Editor instance. * @see #onInit */ 'onPreInit', /** * Fires before the initialization of the editor. * * @event onBeforeRenderUI * @param {tinymce.Editor} sender Editor instance. */ 'onBeforeRenderUI', /** * Fires after the rendering has completed. * * @event onPostRender * @param {tinymce.Editor} sender Editor instance. */ 'onPostRender', /** * Fires after the initialization of the editor is done. * * @event onInit * @param {tinymce.Editor} sender Editor instance. * @see #onPreInit */ 'onInit', /** * Fires when the editor instance is removed from page. * * @event onRemove * @param {tinymce.Editor} sender Editor instance. */ 'onRemove', /** * Fires when the editor is activated. * * @event onActivate * @param {tinymce.Editor} sender Editor instance. */ 'onActivate', /** * Fires when the editor is deactivated. * * @event onDeactivate * @param {tinymce.Editor} sender Editor instance. */ 'onDeactivate', /** * Fires when something in the body of the editor is clicked. * * @event onClick * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onClick', /** * Fires when a registered event is intercepted. * * @event onEvent * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onEvent', /** * Fires when a mouseup event is intercepted inside the editor. * * @event onMouseUp * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onMouseUp', /** * Fires when a mousedown event is intercepted inside the editor. * * @event onMouseDown * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onMouseDown', /** * Fires when a dblclick event is intercepted inside the editor. * * @event onDblClick * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onDblClick', /** * Fires when a keydown event is intercepted inside the editor. * * @event onKeyDown * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onKeyDown', /** * Fires when a keydown event is intercepted inside the editor. * * @event onKeyUp * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onKeyUp', /** * Fires when a keypress event is intercepted inside the editor. * * @event onKeyPress * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onKeyPress', /** * Fires when a contextmenu event is intercepted inside the editor. * * @event onContextMenu * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onContextMenu', /** * Fires when a form submit event is intercepted. * * @event onSubmit * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onSubmit', /** * Fires when a form reset event is intercepted. * * @event onReset * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onReset', /** * Fires when a paste event is intercepted inside the editor. * * @event onPaste * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onPaste', /** * Fires when the Serializer does a preProcess on the contents. * * @event onPreProcess * @param {tinymce.Editor} sender Editor instance. * @param {Object} obj PreProcess object. */ 'onPreProcess', /** * Fires when the Serializer does a postProcess on the contents. * * @event onPostProcess * @param {tinymce.Editor} sender Editor instance. * @param {Object} obj PreProcess object. */ 'onPostProcess', /** * Fires before new contents is added to the editor. Using for example setContent. * * @event onBeforeSetContent * @param {tinymce.Editor} sender Editor instance. */ 'onBeforeSetContent', /** * Fires before contents is extracted from the editor using for example getContent. * * @event onBeforeGetContent * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onBeforeGetContent', /** * Fires after the contents has been added to the editor using for example onSetContent. * * @event onSetContent * @param {tinymce.Editor} sender Editor instance. */ 'onSetContent', /** * Fires after the contents has been extracted from the editor using for example getContent. * * @event onGetContent * @param {tinymce.Editor} sender Editor instance. */ 'onGetContent', /** * Fires when the editor gets loaded with contents for example when the load method is executed. * * @event onLoadContent * @param {tinymce.Editor} sender Editor instance. */ 'onLoadContent', /** * Fires when the editor contents gets saved for example when the save method is executed. * * @event onSaveContent * @param {tinymce.Editor} sender Editor instance. */ 'onSaveContent', /** * Fires when the user changes node location using the mouse or keyboard. * * @event onNodeChange * @param {tinymce.Editor} sender Editor instance. */ 'onNodeChange', /** * Fires when a new undo level is added to the editor. * * @event onChange * @param {tinymce.Editor} sender Editor instance. */ 'onChange', /** * Fires before a command gets executed for example "Bold". * * @event onBeforeExecCommand * @param {tinymce.Editor} sender Editor instance. */ 'onBeforeExecCommand', /** * Fires after a command is executed for example "Bold". * * @event onExecCommand * @param {tinymce.Editor} sender Editor instance. */ 'onExecCommand', /** * Fires when the contents is undo:ed. * * @event onUndo * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onUndo', /** * Fires when the contents is redo:ed. * * @event onRedo * @param {tinymce.Editor} sender Editor instance. * @param {Event} evt W3C DOM Event instance. */ 'onRedo', /** * Fires when visual aids is enabled/disabled. * * @event onVisualAid * @param {tinymce.Editor} sender Editor instance. */ 'onVisualAid', /** * Fires when the progress throbber is shown above the editor. * * @event onSetProgressState * @param {tinymce.Editor} sender Editor instance. */ 'onSetProgressState' ], function(e) { t[e] = new Dispatcher(t); }); /** * Name/value collection with editor settings. * * @property settings * @type Object */ t.settings = s = extend({ id : id, language : 'en', docs_language : 'en', theme : 'simple', skin : 'default', delta_width : 0, delta_height : 0, popup_css : '', plugins : '', document_base_url : tinymce.documentBaseURL, add_form_submit_trigger : 1, submit_patch : 1, add_unload_trigger : 1, convert_urls : 1, relative_urls : 1, remove_script_host : 1, table_inline_editing : 0, object_resizing : 1, cleanup : 1, accessibility_focus : 1, custom_shortcuts : 1, custom_undo_redo_keyboard_shortcuts : 1, custom_undo_redo_restore_selection : 1, custom_undo_redo : 1, doctype : tinymce.isIE6 ? '' : '', // Use old doctype on IE 6 to avoid horizontal scroll visual_table_class : 'mceItemTable', visual : 1, font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', apply_source_formatting : 1, directionality : 'ltr', forced_root_block : 'p', valid_elements : '@[id|class|style|title|dir