/** * $Id$ * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. */ /** * This is the TinyMCE editor control instance class. A instance of this class will is made for each * converted text area. * * @constructor * @param {Array} settings Name/Value array of instance specific configuration settings. */ function TinyMCE_Control(settings) { var t, i, tos, fu, p, x, fn, fu, pn, s = settings; this.undoRedoLevel = true; this.isTinyMCE_Control = true; // Default settings this.enabled = true; this.settings = s; this.settings.theme = tinyMCE.getParam("theme", "default"); this.settings.width = tinyMCE.getParam("width", -1); this.settings.height = tinyMCE.getParam("height", -1); this.selection = new TinyMCE_Selection(this); this.undoRedo = new TinyMCE_UndoRedo(this); this.cleanup = new TinyMCE_Cleanup(); this.shortcuts = []; this.hasMouseMoved = false; this.foreColor = this.backColor = "#999999"; this.data = {}; this.cssClasses = []; this.cleanup.init({ valid_elements : s.valid_elements, extended_valid_elements : s.extended_valid_elements, valid_child_elements : s.valid_child_elements, entities : s.entities, entity_encoding : s.entity_encoding, debug : s.cleanup_debug, indent : s.apply_source_formatting, invalid_elements : s.invalid_elements, verify_html : s.verify_html, fix_content_duplication : s.fix_content_duplication, convert_fonts_to_spans : s.convert_fonts_to_spans }); // Wrap old theme t = this.settings.theme; if (!tinyMCE.hasTheme(t)) { fn = tinyMCE.callbacks; tos = {}; for (i=0; i 0) { for (i=0; i 1 && tinyMCE.currentConfig != this.settings.index) { tinyMCE.settings = this.settings; tinyMCE.currentConfig = this.settings.index; } }, /** * Selects this instance as the currently selected instance. This will also dispatch a selectInstance call to all * themes, plugins and other listeners. */ select : function() { var oldInst = tinyMCE.selectedInstance; if (oldInst != this) { if (oldInst) oldInst.execCommand('mceEndTyping'); tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst); tinyMCE.selectedInstance = this; } }, /** * Returns the body element of a editor instance. * * @return Body element of a editor instance. * @type HTMLElement */ getBody : function() { return this.contentBody ? this.contentBody : this.getDoc().body; }, /** * Returns the DOM document of a editor instance. * * @return DOM document of a editor instance. * @type DOMDocument */ getDoc : function() { // return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ? return this.contentWindow.document; }, /** * Returns the window of a editor instance. * * @return Window of a editor instance. * @type Window */ getWin : function() { return this.contentWindow; }, /** * Returns the container window of a editor instance. The container window is the window where the current instance lives in. * * @return container window of a editor instance. * @type DOMDocument */ getContainerWin : function() { return this.containerWindow ? this.containerWindow : window; }, /** * Returns the viewport of the editor instance. * * @return Viewport object with fields top, left, width and height. * @type Object */ getViewPort : function() { return tinyMCE.getViewPort(this.getWin()); }, /** * Returns a node by the specified selector function. This function will * loop through all parent nodes and call the specified function for each node. * If the function then returns true it will stop the execution and return that node. * This function will not go below the instance body element. * * @param {DOMNode} n HTML node to search parents on. * @param {function} f Selection function to execute on each node. * @return DOMNode or null if it wasn't found. * @type DOMNode */ getParentNode : function(n, f) { return tinyMCE.getParentNode(n, f, this.getBody()); }, /** * Returns the parent element of the specified node based on the search criteria. * This method will not go below the point of the instance body. * * @param {HTMLNode} node Node to get parent element of. * @param {string} na Comma separated list of element names to get. * @param {function} f Optional function to call for each node, if it returns true the node is valid. * @return HTMLElement or null based on search criteras. * @type HTMLElement */ getParentElement : function(n, na, f) { return tinyMCE.getParentElement(n, na, f, this.getBody()); }, /** * Returns the first block element parent of the specified node. * This method will not go below the point of the instance body. * * @param {HTMLNode} n Node get parent block element for. * @return First block element parent of the specified node or null if it wasn't found. * @type HTMLElement */ getParentBlockElement : function(n) { return tinyMCE.getParentBlockElement(n, this.getBody()); }, /** * Auto resizes the current editor instance to match the inner document size. */ resizeToContent : function() { var d = this.getDoc(), b = d.body, de = d.documentElement; this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px'; }, /** * Adds a keyboard shortcut to a specific command. These shortcuts can for example be added * at the initInstance callback of a plugin. The shortcut description can be a language variable name * or a string describing the function. If you don't specify a command, the shortcut will simply be a blocker * shortcut. This enables you to remove built in shortcuts or remove theme specific shortcuts from a plugin.
* Example shortcut inst.addShortcut('ctrl,alt', 'k', 'mceSomeCommand', false, 'somevalue'); * Example blocker inst.addShortcut('ctrl,alt', 'k'); * * @param {string} m List of shortcut modifiers keys, for example "ctrl,alt". * @param {Object} k Shortcut key char for example "s" or a keycode value "13". * @param {string} d Optional Shortcut description, this will be presented in the about dialog. * @param {string} cmd Optional Command name to execute, for example mceLink or Bold. * @param {boolean} ui Optional True/false state if a UI (dialog) should be presented or not. * @param {Object} va Optional command value, this can be anything. * @return true/false if the shortcut was added or not * @type boolean */ addShortcut : function(m, k, d, cmd, ui, va) { var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts; if (!tinyMCE.getParam('custom_shortcuts')) return false; m = m.toLowerCase(); k = ie && !n ? k.toUpperCase() : k; c = n ? null : k.charCodeAt(0); d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d; sc = { alt : m.indexOf('alt') != -1, ctrl : m.indexOf('ctrl') != -1, shift : m.indexOf('shift') != -1, charCode : c, keyCode : n ? k : (ie ? c : null), desc : d, cmd : cmd, ui : ui, val : va }; for (i=0; i