]*>( | |\s|\u00a0|)<\/p>[\r\n]*|[\r\n]*)$/, ''); }); } self.load({initial: true, format: 'html'}); self.startContent = self.getContent({format: 'raw'}); /** * Is set to true after the editor instance has been initialized * * @property initialized * @type Boolean * @example * function isEditorInitialized(editor) { * return editor && editor.initialized; * } */ self.initialized = true; each(self._pendingNativeEvents, function(name) { self.dom.bind(getEventTarget(self, name), name, function(e) { self.fire(e.type, e); }); }); self.fire('init'); self.focus(true); self.nodeChanged({initial: true}); self.execCallback('init_instance_callback', self); // Add editor specific CSS styles if (self.contentStyles.length > 0) { contentCssText = ''; each(self.contentStyles, function(style) { contentCssText += style + "\r\n"; }); self.dom.addStyle(contentCssText); } // Load specified content CSS last each(self.contentCSS, function(cssUrl) { if (!self.loadedCSS[cssUrl]) { self.dom.loadCSS(cssUrl); self.loadedCSS[cssUrl] = true; } }); // Handle auto focus if (settings.auto_focus) { setTimeout(function () { var ed = self.editorManager.get(settings.auto_focus); ed.selection.select(ed.getBody(), 1); ed.selection.collapse(1); ed.getBody().focus(); ed.getWin().focus(); }, 100); } // Clean up references for IE targetElm = doc = body = null; }, /** * Focuses/activates the editor. This will set this editor as the activeEditor in the tinymce collection * it will also place DOM focus inside the editor. * * @method focus * @param {Boolean} skip_focus Skip DOM focus. Just set is as the active editor. */ focus: function(skip_focus) { var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, rng; var controlElm, doc = self.getDoc(), body; if (!skip_focus) { // Get selected control element rng = selection.getRng(); if (rng.item) { controlElm = rng.item(0); } self._refreshContentEditable(); // Focus the window iframe if (!contentEditable) { // WebKit needs this call to fire focusin event properly see #5948 // But Opera pre Blink engine will produce an empty selection so skip Opera if (!Env.opera) { self.getBody().focus(); } self.getWin().focus(); } // Focus the body as well since it's contentEditable if (isGecko || contentEditable) { body = self.getBody(); // Check for setActive since it doesn't scroll to the element if (body.setActive && Env.ie < 11) { body.setActive(); } else { body.focus(); } if (contentEditable) { selection.normalize(); } } // Restore selected control element // This is needed when for example an image is selected within a // layer a call to focus will then remove the control selection if (controlElm && controlElm.ownerDocument == doc) { rng = doc.body.createControlRange(); rng.addElement(controlElm); rng.select(); } } if (self.editorManager.activeEditor != self) { if ((oed = self.editorManager.activeEditor)) { oed.fire('deactivate', {relatedTarget: self}); } self.fire('activate', {relatedTarget: oed}); } self.editorManager.activeEditor = self; }, /** * Executes a legacy callback. This method is useful to call old 2.x option callbacks. * There new event model is a better way to add callback so this method might be removed in the future. * * @method execCallback * @param {String} name Name of the callback to execute. * @return {Object} Return value passed from callback function. */ execCallback: function(name) { var self = this, callback = self.settings[name], scope; if (!callback) { return; } // Look through lookup if (self.callbackLookup && (scope = self.callbackLookup[name])) { callback = scope.func; scope = scope.scope; } if (typeof(callback) === 'string') { scope = callback.replace(/\.\w+$/, ''); scope = scope ? resolve(scope) : 0; callback = resolve(callback); self.callbackLookup = self.callbackLookup || {}; self.callbackLookup[name] = {func: callback, scope: scope}; } return callback.apply(scope || self, Array.prototype.slice.call(arguments, 1)); }, /** * Translates the specified string by replacing variables with language pack items it will also check if there is * a key mathcin the input. * * @method translate * @param {String} text String to translate by the language pack data. * @return {String} Translated string. */ translate: function(text) { var lang = this.settings.language || 'en', i18n = this.editorManager.i18n; if (!text) { return ''; } return i18n.data[lang + '.' + text] || text.replace(/\{\#([^\}]+)\}/g, function(a, b) { return i18n.data[lang + '.' + b] || '{#' + b + '}'; }); }, /** * Returns a language pack item by name/key. * * @method getLang * @param {String} name Name/key to get from the language pack. * @param {String} defaultVal Optional default value to retrive. */ getLang: function(name, defaultVal) { return ( this.editorManager.i18n.data[(this.settings.language || 'en') + '.' + name] || (defaultVal !== undefined ? defaultVal : '{#' + name + '}') ); }, /** * Returns a configuration parameter by name. * * @method getParam * @param {String} name Configruation parameter to retrive. * @param {String} defaultVal Optional default value to return. * @param {String} type Optional type parameter. * @return {String} Configuration parameter value or default value. * @example * // Returns a specific config value from the currently active editor * var someval = tinymce.activeEditor.getParam('myvalue'); * * // Returns a specific config value from a specific editor instance by id * var someval2 = tinymce.get('my_editor').getParam('myvalue'); */ getParam: function(name, defaultVal, type) { var value = name in this.settings ? this.settings[name] : defaultVal, output; if (type === 'hash') { output = {}; if (typeof(value) === 'string') { each(value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(','), function(value) { value = value.split('='); if (value.length > 1) { output[trim(value[0])] = trim(value[1]); } else { output[trim(value[0])] = trim(value); } }); } else { output = value; } return output; } return value; }, /** * Distpaches out a onNodeChange event to all observers. This method should be called when you * need to update the UI states or element path etc. * * @method nodeChanged */ nodeChanged: function() { var self = this, selection = self.selection, node, parents, root; // Fix for bug #1896577 it seems that this can not be fired while the editor is loading if (self.initialized && !self.settings.disable_nodechange) { // Get start node root = self.getBody(); node = selection.getStart() || root; node = ie && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state // Edge case for
|