--- /dev/null
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview Defines the {@link CKEDITOR.editor} class, which represents an\r
+ * editor instance.\r
+ */\r
+\r
+(function()\r
+{\r
+ // The counter for automatic instance names.\r
+ var nameCounter = 0;\r
+\r
+ var getNewName = function()\r
+ {\r
+ var name = 'editor' + ( ++nameCounter );\r
+ return ( CKEDITOR.instances && CKEDITOR.instances[ name ] ) ? getNewName() : name;\r
+ };\r
+\r
+ // ##### START: Config Privates\r
+\r
+ // These function loads custom configuration files and cache the\r
+ // CKEDITOR.editorConfig functions defined on them, so there is no need to\r
+ // download them more than once for several instances.\r
+ var loadConfigLoaded = {};\r
+ var loadConfig = function( editor )\r
+ {\r
+ var customConfig = editor.config.customConfig;\r
+\r
+ // Check if there is a custom config to load.\r
+ if ( !customConfig )\r
+ return false;\r
+\r
+ customConfig = CKEDITOR.getUrl( customConfig );\r
+\r
+ var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = {} );\r
+\r
+ // If the custom config has already been downloaded, reuse it.\r
+ if ( loadedConfig.fn )\r
+ {\r
+ // Call the cached CKEDITOR.editorConfig defined in the custom\r
+ // config file for the editor instance depending on it.\r
+ loadedConfig.fn.call( editor, editor.config );\r
+\r
+ // If there is no other customConfig in the chain, fire the\r
+ // "configLoaded" event.\r
+ if ( CKEDITOR.getUrl( editor.config.customConfig ) == customConfig || !loadConfig( editor ) )\r
+ editor.fireOnce( 'customConfigLoaded' );\r
+ }\r
+ else\r
+ {\r
+ // Load the custom configuration file.\r
+ CKEDITOR.scriptLoader.load( customConfig, function()\r
+ {\r
+ // If the CKEDITOR.editorConfig function has been properly\r
+ // defined in the custom configuration file, cache it.\r
+ if ( CKEDITOR.editorConfig )\r
+ loadedConfig.fn = CKEDITOR.editorConfig;\r
+ else\r
+ loadedConfig.fn = function(){};\r
+\r
+ // Call the load config again. This time the custom\r
+ // config is already cached and so it will get loaded.\r
+ loadConfig( editor );\r
+ });\r
+ }\r
+\r
+ return true;\r
+ };\r
+\r
+ var initConfig = function( editor, instanceConfig )\r
+ {\r
+ // Setup the lister for the "customConfigLoaded" event.\r
+ editor.on( 'customConfigLoaded', function()\r
+ {\r
+ if ( instanceConfig )\r
+ {\r
+ // Register the events that may have been set at the instance\r
+ // configuration object.\r
+ if ( instanceConfig.on )\r
+ {\r
+ for ( var eventName in instanceConfig.on )\r
+ {\r
+ editor.on( eventName, instanceConfig.on[ eventName ] );\r
+ }\r
+ }\r
+\r
+ // Overwrite the settings from the in-page config.\r
+ CKEDITOR.tools.extend( editor.config, instanceConfig, true );\r
+\r
+ delete editor.config.on;\r
+ }\r
+\r
+ onConfigLoaded( editor );\r
+ });\r
+\r
+ // The instance config may override the customConfig setting to avoid\r
+ // loading the default ~/config.js file.\r
+ if ( instanceConfig && instanceConfig.customConfig != undefined )\r
+ editor.config.customConfig = instanceConfig.customConfig;\r
+\r
+ // Load configs from the custom configuration files.\r
+ if ( !loadConfig( editor ) )\r
+ editor.fireOnce( 'customConfigLoaded' );\r
+ };\r
+\r
+ // ##### END: Config Privates\r
+\r
+ var onConfigLoaded = function( editor )\r
+ {\r
+ // Set config related properties.\r
+\r
+ var skin = editor.config.skin.split( ',' ),\r
+ skinName = skin[ 0 ],\r
+ skinPath = CKEDITOR.getUrl( skin[ 1 ] || (\r
+ '_source/' + // @Packager.RemoveLine\r
+ 'skins/' + skinName + '/' ) );\r
+\r
+ /**\r
+ * The name of the skin used by this editor instance. The skin name can\r
+ * be set though the {@link CKEDITOR.config.skin} setting.\r
+ * @name CKEDITOR.editor.prototype.skinName\r
+ * @type String\r
+ * @example\r
+ * alert( editor.skinName ); // "kama" (e.g.)\r
+ */\r
+ editor.skinName = skinName;\r
+\r
+ /**\r
+ * The full URL of the skin directory.\r
+ * @name CKEDITOR.editor.prototype.skinPath\r
+ * @type String\r
+ * @example\r
+ * alert( editor.skinPath ); // "http://example.com/ckeditor/skins/kama/" (e.g.)\r
+ */\r
+ editor.skinPath = skinPath;\r
+\r
+ /**\r
+ * The CSS class name used for skin identification purposes.\r
+ * @name CKEDITOR.editor.prototype.skinClass\r
+ * @type String\r
+ * @example\r
+ * alert( editor.skinClass ); // "cke_skin_kama" (e.g.)\r
+ */\r
+ editor.skinClass = 'cke_skin_' + skinName;\r
+\r
+ /**\r
+ * The <a href="http://en.wikipedia.org/wiki/Tabbing_navigation">tabbing\r
+ * navigation</a> order that has been calculated for this editor\r
+ * instance. This can be set by the {@link CKEDITOR.config.tabIndex}\r
+ * setting or taken from the "tabindex" attribute of the\r
+ * {@link #element} associated to the editor.\r
+ * @name CKEDITOR.editor.prototype.tabIndex\r
+ * @type Number\r
+ * @default 0 (zero)\r
+ * @example\r
+ * alert( editor.tabIndex ); // "0" (e.g.)\r
+ */\r
+ editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;\r
+\r
+ // Fire the "configLoaded" event.\r
+ editor.fireOnce( 'configLoaded' );\r
+\r
+ // Load language file.\r
+ loadSkin( editor );\r
+ };\r
+\r
+ var loadLang = function( editor )\r
+ {\r
+ CKEDITOR.lang.load( editor.config.language, editor.config.defaultLanguage, function( languageCode, lang )\r
+ {\r
+ /**\r
+ * The code for the language resources that have been loaded\r
+ * for the user internface elements of this editor instance.\r
+ * @name CKEDITOR.editor.prototype.langCode\r
+ * @type String\r
+ * @example\r
+ * alert( editor.langCode ); // "en" (e.g.)\r
+ */\r
+ editor.langCode = languageCode;\r
+\r
+ /**\r
+ * An object holding all language strings used by the editor\r
+ * interface.\r
+ * @name CKEDITOR.editor.prototype.lang\r
+ * @type CKEDITOR.lang\r
+ * @example\r
+ * alert( editor.lang.bold ); // "Negrito" (e.g. if language is Portuguese)\r
+ */\r
+ // As we'll be adding plugin specific entries that could come\r
+ // from different language code files, we need a copy of lang,\r
+ // not a direct reference to it.\r
+ editor.lang = CKEDITOR.tools.prototypedCopy( lang );\r
+\r
+ // We're not able to support RTL in Firefox 2 at this time.\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 && editor.lang.dir == 'rtl' )\r
+ editor.lang.dir = 'ltr';\r
+\r
+ var config = editor.config;\r
+ config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );\r
+\r
+ loadPlugins( editor );\r
+ });\r
+ };\r
+\r
+ var loadPlugins = function( editor )\r
+ {\r
+ var config = editor.config,\r
+ plugins = config.plugins,\r
+ extraPlugins = config.extraPlugins,\r
+ removePlugins = config.removePlugins;\r
+\r
+ if ( extraPlugins )\r
+ {\r
+ // Remove them first to avoid duplications.\r
+ var removeRegex = new RegExp( '(?:^|,)(?:' + extraPlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );\r
+ plugins = plugins.replace( removeRegex, '' );\r
+\r
+ plugins += ',' + extraPlugins;\r
+ }\r
+\r
+ if ( removePlugins )\r
+ {\r
+ removeRegex = new RegExp( '(?:^|,)(?:' + removePlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );\r
+ plugins = plugins.replace( removeRegex, '' );\r
+ }\r
+\r
+ // Load the Adobe AIR plugin conditionally.\r
+ CKEDITOR.env.air && ( plugins += ',adobeair' );\r
+\r
+ // Load all plugins defined in the "plugins" setting.\r
+ CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )\r
+ {\r
+ // The list of plugins.\r
+ var pluginsArray = [];\r
+\r
+ // The language code to get loaded for each plugin. Null\r
+ // entries will be appended for plugins with no language files.\r
+ var languageCodes = [];\r
+\r
+ // The list of URLs to language files.\r
+ var languageFiles = [];\r
+\r
+ /**\r
+ * And object holding references to all plugins used by this\r
+ * editor istance.\r
+ * @name CKEDITOR.editor.prototype.plugins\r
+ * @type Object\r
+ * @example\r
+ * alert( editor.plugins.dialog.path ); // "http://example.com/ckeditor/plugins/dialog/" (e.g.)\r
+ */\r
+ editor.plugins = plugins;\r
+\r
+ // Loop through all plugins, to build the list of language\r
+ // files to get loaded.\r
+ for ( var pluginName in plugins )\r
+ {\r
+ var plugin = plugins[ pluginName ],\r
+ pluginLangs = plugin.lang,\r
+ pluginPath = CKEDITOR.plugins.getPath( pluginName ),\r
+ lang = null;\r
+\r
+ // Set the plugin path in the plugin.\r
+ plugin.path = pluginPath;\r
+\r
+ // If the plugin has "lang".\r
+ if ( pluginLangs )\r
+ {\r
+ // Resolve the plugin language. If the current language\r
+ // is not available, get the first one (default one).\r
+ lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );\r
+\r
+ if ( !plugin.langEntries || !plugin.langEntries[ lang ] )\r
+ {\r
+ // Put the language file URL into the list of files to\r
+ // get downloaded.\r
+ languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );\r
+ }\r
+ else\r
+ {\r
+ CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );\r
+ lang = null;\r
+ }\r
+ }\r
+\r
+ // Save the language code, so we know later which\r
+ // language has been resolved to this plugin.\r
+ languageCodes.push( lang );\r
+\r
+ pluginsArray.push( plugin );\r
+ }\r
+\r
+ // Load all plugin specific language files in a row.\r
+ CKEDITOR.scriptLoader.load( languageFiles, function()\r
+ {\r
+ // Initialize all plugins that have the "beforeInit" and "init" methods defined.\r
+ var methods = [ 'beforeInit', 'init', 'afterInit' ];\r
+ for ( var m = 0 ; m < methods.length ; m++ )\r
+ {\r
+ for ( var i = 0 ; i < pluginsArray.length ; i++ )\r
+ {\r
+ var plugin = pluginsArray[ i ];\r
+\r
+ // Uses the first loop to update the language entries also.\r
+ if ( m === 0 && languageCodes[ i ] && plugin.lang )\r
+ CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ languageCodes[ i ] ] );\r
+\r
+ // Call the plugin method (beforeInit and init).\r
+ if ( plugin[ methods[ m ] ] )\r
+ plugin[ methods[ m ] ]( editor );\r
+ }\r
+ }\r
+\r
+ // Load the editor skin.\r
+ editor.fire( 'pluginsLoaded' );\r
+ loadTheme( editor );\r
+ });\r
+ });\r
+ };\r
+\r
+ var loadSkin = function( editor )\r
+ {\r
+ CKEDITOR.skins.load( editor, 'editor', function()\r
+ {\r
+ loadLang( editor );\r
+ });\r
+ };\r
+\r
+ var loadTheme = function( editor )\r
+ {\r
+ var theme = editor.config.theme;\r
+ CKEDITOR.themes.load( theme, function()\r
+ {\r
+ /**\r
+ * The theme used by this editor instance.\r
+ * @name CKEDITOR.editor.prototype.theme\r
+ * @type CKEDITOR.theme\r
+ * @example\r
+ * alert( editor.theme ); "http://example.com/ckeditor/themes/default/" (e.g.)\r
+ */\r
+ var editorTheme = editor.theme = CKEDITOR.themes.get( theme );\r
+ editorTheme.path = CKEDITOR.themes.getPath( theme );\r
+ editorTheme.build( editor );\r
+\r
+ if ( editor.config.autoUpdateElement )\r
+ attachToForm( editor );\r
+ });\r
+ };\r
+\r
+ var attachToForm = function( editor )\r
+ {\r
+ var element = editor.element;\r
+\r
+ // If are replacing a textarea, we must\r
+ if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )\r
+ {\r
+ var form = element.$.form && new CKEDITOR.dom.element( element.$.form );\r
+ if ( form )\r
+ {\r
+ function onSubmit()\r
+ {\r
+ editor.updateElement();\r
+ }\r
+ form.on( 'submit',onSubmit );\r
+\r
+ // Setup the submit function because it doesn't fire the\r
+ // "submit" event.\r
+ if ( !form.$.submit.nodeName && !form.$.submit.length )\r
+ {\r
+ form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )\r
+ {\r
+ return function()\r
+ {\r
+ editor.updateElement();\r
+\r
+ // For IE, the DOM submit function is not a\r
+ // function, so we need thid check.\r
+ if ( originalSubmit.apply )\r
+ originalSubmit.apply( this, arguments );\r
+ else\r
+ originalSubmit();\r
+ };\r
+ });\r
+ }\r
+\r
+ // Remove 'submit' events registered on form element before destroying.(#3988)\r
+ editor.on( 'destroy', function()\r
+ {\r
+ form.removeListener( 'submit', onSubmit );\r
+ } );\r
+ }\r
+ }\r
+ };\r
+\r
+ function updateCommandsMode()\r
+ {\r
+ var command,\r
+ commands = this._.commands,\r
+ mode = this.mode;\r
+\r
+ for ( var name in commands )\r
+ {\r
+ command = commands[ name ];\r
+ command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Initializes the editor instance. This function is called by the editor\r
+ * contructor (editor_basic.js).\r
+ * @private\r
+ */\r
+ CKEDITOR.editor.prototype._init = function()\r
+ {\r
+ // Get the properties that have been saved in the editor_base\r
+ // implementation.\r
+ var element = CKEDITOR.dom.element.get( this._.element ),\r
+ instanceConfig = this._.instanceConfig;\r
+ delete this._.element;\r
+ delete this._.instanceConfig;\r
+\r
+ this._.commands = {};\r
+ this._.styles = [];\r
+\r
+ /**\r
+ * The DOM element that has been replaced by this editor instance. This\r
+ * element holds the editor data on load and post.\r
+ * @name CKEDITOR.editor.prototype.element\r
+ * @type CKEDITOR.dom.element\r
+ * @example\r
+ * var editor = CKEDITOR.instances.editor1;\r
+ * alert( <b>editor.element</b>.getName() ); "textarea"\r
+ */\r
+ this.element = element;\r
+\r
+ /**\r
+ * The editor instance name. It hay be the replaced element id, name or\r
+ * a default name using a progressive counter (editor1, editor2, ...).\r
+ * @name CKEDITOR.editor.prototype.name\r
+ * @type String\r
+ * @example\r
+ * var editor = CKEDITOR.instances.editor1;\r
+ * alert( <b>editor.name</b> ); "editor1"\r
+ */\r
+ this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
+ && ( element.getId() || element.getNameAtt() ) )\r
+ || getNewName();\r
+\r
+ if ( this.name in CKEDITOR.instances )\r
+ throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';\r
+\r
+ /**\r
+ * A unique random string assigned to each editor instance in the page.\r
+ * @name CKEDITOR.editor.prototype.id\r
+ * @type String\r
+ */\r
+ this.id = CKEDITOR.tools.getNextId();\r
+\r
+ /**\r
+ * The configurations for this editor instance. It inherits all\r
+ * settings defined in (@link CKEDITOR.config}, combined with settings\r
+ * loaded from custom configuration files and those defined inline in\r
+ * the page when creating the editor.\r
+ * @name CKEDITOR.editor.prototype.config\r
+ * @type Object\r
+ * @example\r
+ * var editor = CKEDITOR.instances.editor1;\r
+ * alert( <b>editor.config.theme</b> ); "default" e.g.\r
+ */\r
+ this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );\r
+\r
+ /**\r
+ * Namespace containing UI features related to this editor instance.\r
+ * @name CKEDITOR.editor.prototype.ui\r
+ * @type CKEDITOR.ui\r
+ * @example\r
+ */\r
+ this.ui = new CKEDITOR.ui( this );\r
+\r
+ /**\r
+ * Controls the focus state of this editor instance. This property\r
+ * is rarely used for normal API operations. It is mainly\r
+ * destinated to developer adding UI elements to the editor interface.\r
+ * @name CKEDITOR.editor.prototype.focusManager\r
+ * @type CKEDITOR.focusManager\r
+ * @example\r
+ */\r
+ this.focusManager = new CKEDITOR.focusManager( this );\r
+\r
+ CKEDITOR.fire( 'instanceCreated', null, this );\r
+\r
+ this.on( 'mode', updateCommandsMode, null, null, 1 );\r
+\r
+ initConfig( this, instanceConfig );\r
+ };\r
+})();\r
+\r
+CKEDITOR.tools.extend( CKEDITOR.editor.prototype,\r
+ /** @lends CKEDITOR.editor.prototype */\r
+ {\r
+ /**\r
+ * Adds a command definition to the editor instance. Commands added with\r
+ * this function can be later executed with {@link #execCommand}.\r
+ * @param {String} commandName The indentifier name of the command.\r
+ * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.\r
+ * @example\r
+ * editorInstance.addCommand( 'sample',\r
+ * {\r
+ * exec : function( editor )\r
+ * {\r
+ * alert( 'Executing a command for the editor name "' + editor.name + '"!' );\r
+ * }\r
+ * });\r
+ */\r
+ addCommand : function( commandName, commandDefinition )\r
+ {\r
+ return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );\r
+ },\r
+\r
+ /**\r
+ * Add a trunk of css text to the editor which will be applied to the wysiwyg editing document.\r
+ * Note: This function should be called before editor is loaded to take effect.\r
+ * @param css {String} CSS text.\r
+ * @example\r
+ * editorInstance.addCss( 'body { background-color: grey; }' );\r
+ */\r
+ addCss : function( css )\r
+ {\r
+ this._.styles.push( css );\r
+ },\r
+\r
+ /**\r
+ * Destroys the editor instance, releasing all resources used by it.\r
+ * If the editor replaced an element, the element will be recovered.\r
+ * @param {Boolean} [noUpdate] If the instance is replacing a DOM\r
+ * element, this parameter indicates whether or not to update the\r
+ * element with the instance contents.\r
+ * @example\r
+ * alert( CKEDITOR.instances.editor1 ); e.g "object"\r
+ * <b>CKEDITOR.instances.editor1.destroy()</b>;\r
+ * alert( CKEDITOR.instances.editor1 ); "undefined"\r
+ */\r
+ destroy : function( noUpdate )\r
+ {\r
+ if ( !noUpdate )\r
+ this.updateElement();\r
+\r
+ this.fire( 'destroy' );\r
+ this.theme && this.theme.destroy( this );\r
+\r
+ CKEDITOR.remove( this );\r
+ CKEDITOR.fire( 'instanceDestroyed', null, this );\r
+ },\r
+\r
+ /**\r
+ * Executes a command.\r
+ * @param {String} commandName The indentifier name of the command.\r
+ * @param {Object} [data] Data to be passed to the command\r
+ * @returns {Boolean} "true" if the command has been successfuly\r
+ * executed, otherwise "false".\r
+ * @example\r
+ * editorInstance.execCommand( 'Bold' );\r
+ */\r
+ execCommand : function( commandName, data )\r
+ {\r
+ var command = this.getCommand( commandName );\r
+\r
+ var eventData =\r
+ {\r
+ name: commandName,\r
+ commandData: data,\r
+ command: command\r
+ };\r
+\r
+ if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )\r
+ {\r
+ if ( this.fire( 'beforeCommandExec', eventData ) !== true )\r
+ {\r
+ eventData.returnValue = command.exec( eventData.commandData );\r
+\r
+ // Fire the 'afterCommandExec' immediately if command is synchronous.\r
+ if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )\r
+ return eventData.returnValue;\r
+ }\r
+ }\r
+\r
+ // throw 'Unknown command name "' + commandName + '"';\r
+ return false;\r
+ },\r
+\r
+ /**\r
+ * Gets one of the registered commands. Note that, after registering a\r
+ * command definition with addCommand, it is transformed internally\r
+ * into an instance of {@link CKEDITOR.command}, which will be then\r
+ * returned by this function.\r
+ * @param {String} commandName The name of the command to be returned.\r
+ * This is the same used to register the command with addCommand.\r
+ * @returns {CKEDITOR.command} The command object identified by the\r
+ * provided name.\r
+ */\r
+ getCommand : function( commandName )\r
+ {\r
+ return this._.commands[ commandName ];\r
+ },\r
+\r
+ /**\r
+ * Gets the editor data. The data will be in raw format. It is the same\r
+ * data that is posted by the editor.\r
+ * @type String\r
+ * @returns (String) The editor data.\r
+ * @example\r
+ * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )\r
+ * alert( 'There is no data available' );\r
+ */\r
+ getData : function()\r
+ {\r
+ this.fire( 'beforeGetData' );\r
+\r
+ var eventData = this._.data;\r
+\r
+ if ( typeof eventData != 'string' )\r
+ {\r
+ var element = this.element;\r
+ if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
+ eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();\r
+ else\r
+ eventData = '';\r
+ }\r
+\r
+ eventData = { dataValue : eventData };\r
+\r
+ // Fire "getData" so data manipulation may happen.\r
+ this.fire( 'getData', eventData );\r
+\r
+ return eventData.dataValue;\r
+ },\r
+\r
+ /**\r
+ * Gets the "raw data" currently available in the editor. This is a\r
+ * fast method which return the data as is, without processing, so it's\r
+ * not recommended to use it on resulting pages. It can be used instead\r
+ * combined with the {@link #loadSnapshot} so one can automatic save\r
+ * the editor data from time to time while the user is using the\r
+ * editor, to avoid data loss, without risking performance issues.\r
+ * @example\r
+ * alert( editor.getSnapshot() );\r
+ */\r
+ getSnapshot : function()\r
+ {\r
+ var data = this.fire( 'getSnapshot' );\r
+\r
+ if ( typeof data != 'string' )\r
+ {\r
+ var element = this.element;\r
+ if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
+ data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();\r
+ }\r
+\r
+ return data;\r
+ },\r
+\r
+ /**\r
+ * Loads "raw data" in the editor. This data is loaded with processing\r
+ * straight to the editing area. It should not be used as a way to load\r
+ * any kind of data, but instead in combination with\r
+ * {@link #getSnapshot} produced data.\r
+ * @example\r
+ * var data = editor.getSnapshot();\r
+ * editor.<b>loadSnapshot( data )</b>;\r
+ */\r
+ loadSnapshot : function( snapshot )\r
+ {\r
+ this.fire( 'loadSnapshot', snapshot );\r
+ },\r
+\r
+ /**\r
+ * Sets the editor data. The data must be provided in raw format (HTML).<br />\r
+ * <br />\r
+ * Note that this menthod is asynchronous. The "callback" parameter must\r
+ * be used if interaction with the editor is needed after setting the data.\r
+ * @param {String} data HTML code to replace the curent content in the\r
+ * editor.\r
+ * @param {Function} callback Function to be called after the setData\r
+ * is completed.\r
+ *@param {Boolean} internal Whether suppress any event firing when copying data internally inside editor.\r
+ * @example\r
+ * CKEDITOR.instances.editor1.<b>setData</b>( '<p>This is the editor data.</p>' );\r
+ * @example\r
+ * CKEDITOR.instances.editor1.<b>setData</b>( '<p>Some other editor data.</p>', function()\r
+ * {\r
+ * this.checkDirty(); // true\r
+ * });\r
+ */\r
+ setData : function( data , callback, internal )\r
+ {\r
+ if( callback )\r
+ {\r
+ this.on( 'dataReady', function( evt )\r
+ {\r
+ evt.removeListener();\r
+ callback.call( evt.editor );\r
+ } );\r
+ }\r
+\r
+ // Fire "setData" so data manipulation may happen.\r
+ var eventData = { dataValue : data };\r
+ !internal && this.fire( 'setData', eventData );\r
+\r
+ this._.data = eventData.dataValue;\r
+\r
+ !internal && this.fire( 'afterSetData', eventData );\r
+ },\r
+\r
+ /**\r
+ * Inserts HTML into the currently selected position in the editor.\r
+ * @param {String} data HTML code to be inserted into the editor.\r
+ * @example\r
+ * CKEDITOR.instances.editor1.<b>insertHtml( '<p>This is a new paragraph.</p>' )</b>;\r
+ */\r
+ insertHtml : function( data )\r
+ {\r
+ this.fire( 'insertHtml', data );\r
+ },\r
+\r
+ /**\r
+ * Insert text content into the currently selected position in the\r
+ * editor, in WYSIWYG mode, styles of the selected element will be applied to the inserted text,\r
+ * spaces around the text will be leaving untouched.\r
+ * <strong>Note:</strong> two subsequent line-breaks will introduce one paragraph, which element depends on {@link CKEDITOR.config.enterMode};\r
+ * A single line-break will be instead translated into one <br />.\r
+ * @since 3.5\r
+ * @param {String} text Text to be inserted into the editor.\r
+ * @example\r
+ * CKEDITOR.instances.editor1.<b>insertText( ' line1 \n\n line2' )</b>;\r
+ */\r
+ insertText : function( text )\r
+ {\r
+ this.fire( 'insertText', text );\r
+ },\r
+\r
+ /**\r
+ * Inserts an element into the currently selected position in the\r
+ * editor.\r
+ * @param {CKEDITOR.dom.element} element The element to be inserted\r
+ * into the editor.\r
+ * @example\r
+ * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );\r
+ * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;\r
+ */\r
+ insertElement : function( element )\r
+ {\r
+ this.fire( 'insertElement', element );\r
+ },\r
+\r
+ /**\r
+ * Checks whether the current editor contents present changes when\r
+ * compared to the contents loaded into the editor at startup, or to\r
+ * the contents available in the editor when {@link #resetDirty} has\r
+ * been called.\r
+ * @returns {Boolean} "true" is the contents present changes.\r
+ * @example\r
+ * function beforeUnload( e )\r
+ * {\r
+ * if ( CKEDITOR.instances.editor1.<b>checkDirty()</b> )\r
+ * return e.returnValue = "You'll loose the changes made in the editor.";\r
+ * }\r
+ *\r
+ * if ( window.addEventListener )\r
+ * window.addEventListener( 'beforeunload', beforeUnload, false );\r
+ * else\r
+ * window.attachEvent( 'onbeforeunload', beforeUnload );\r
+ */\r
+ checkDirty : function()\r
+ {\r
+ return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );\r
+ },\r
+\r
+ /**\r
+ * Resets the "dirty state" of the editor so subsequent calls to\r
+ * {@link #checkDirty} will return "false" if the user will not make\r
+ * further changes to the contents.\r
+ * @example\r
+ * alert( editor.checkDirty() ); // "true" (e.g.)\r
+ * editor.<b>resetDirty()</b>;\r
+ * alert( editor.checkDirty() ); // "false"\r
+ */\r
+ resetDirty : function()\r
+ {\r
+ if ( this.mayBeDirty )\r
+ this._.previousValue = this.getSnapshot();\r
+ },\r
+\r
+ /**\r
+ * Updates the <textarea> element that has been replaced by the editor with\r
+ * the current data available in the editor.\r
+ * @example\r
+ * CKEDITOR.instances.editor1.updateElement();\r
+ * alert( document.getElementById( 'editor1' ).value ); // The current editor data.\r
+ */\r
+ updateElement : function()\r
+ {\r
+ var element = this.element;\r
+ if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
+ {\r
+ var data = this.getData();\r
+\r
+ if ( this.config.htmlEncodeOutput )\r
+ data = CKEDITOR.tools.htmlEncode( data );\r
+\r
+ if ( element.is( 'textarea' ) )\r
+ element.setValue( data );\r
+ else\r
+ element.setHtml( data );\r
+ }\r
+ }\r
+ });\r
+\r
+CKEDITOR.on( 'loaded', function()\r
+ {\r
+ // Run the full initialization for pending editors.\r
+ var pending = CKEDITOR.editor._pending;\r
+ if ( pending )\r
+ {\r
+ delete CKEDITOR.editor._pending;\r
+\r
+ for ( var i = 0 ; i < pending.length ; i++ )\r
+ pending[ i ]._init();\r
+ }\r
+ });\r
+\r
+/**\r
+ * Whether escape HTML when editor update original input element.\r
+ * @name CKEDITOR.config.htmlEncodeOutput\r
+ * @since 3.1\r
+ * @type Boolean\r
+ * @default false\r
+ * @example\r
+ * config.htmlEncodeOutput = true;\r
+ */\r
+\r
+/**\r
+ * Fired when a CKEDITOR instance is created, but still before initializing it.\r
+ * To interact with a fully initialized instance, use the\r
+ * {@link CKEDITOR#instanceReady} event instead.\r
+ * @name CKEDITOR#instanceCreated\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor The editor instance that has been created.\r
+ */\r
+\r
+/**\r
+ * Fired when a CKEDITOR instance is destroyed.\r
+ * @name CKEDITOR#instanceDestroyed\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.\r
+ */\r
+\r
+/**\r
+ * Fired when all plugins are loaded and initialized into the editor instance.\r
+ * @name CKEDITOR.editor#pluginsLoaded\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ */\r
+\r
+/**\r
+ * Fired before the command execution when {@link #execCommand} is called.\r
+ * @name CKEDITOR.editor#beforeCommandExec\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data.name The command name.\r
+ * @param {Object} data.commandData The data to be sent to the command. This\r
+ * can be manipulated by the event listener.\r
+ * @param {CKEDITOR.command} data.command The command itself.\r
+ */\r
+\r
+/**\r
+ * Fired after the command execution when {@link #execCommand} is called.\r
+ * @name CKEDITOR.editor#afterCommandExec\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data.name The command name.\r
+ * @param {Object} data.commandData The data sent to the command.\r
+ * @param {CKEDITOR.command} data.command The command itself.\r
+ * @param {Object} data.returnValue The value returned by the command execution.\r
+ */\r
+\r
+/**\r
+ * Fired every custom configuration file is loaded, before the final\r
+ * configurations initialization.<br />\r
+ * <br />\r
+ * Custom configuration files can be loaded thorugh the\r
+ * {@link CKEDITOR.config.customConfig} setting. Several files can be loading\r
+ * by chaning this setting.\r
+ * @name CKEDITOR.editor#customConfigLoaded\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @example\r
+ */\r
+\r
+/**\r
+ * Fired once the editor configuration is ready (loaded and processed).\r
+ * @name CKEDITOR.editor#configLoaded\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @example\r
+ * if( editor.config.fullPage )\r
+ * alert( 'This is a full page editor' );\r
+ */\r
+\r
+/**\r
+ * Fired when this editor instance is destroyed. The editor at this\r
+ * point isn't usable and this event should be used to perform clean up\r
+ * in any plugin.\r
+ * @name CKEDITOR.editor#destroy\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Internal event to get the current data.\r
+ * @name CKEDITOR.editor#beforeGetData\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the #getSnapshot call.\r
+ * @name CKEDITOR.editor#getSnapshot\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the #loadSnapshot call.\r
+ * @name CKEDITOR.editor#loadSnapshot\r
+ * @event\r
+ */\r
+\r
+\r
+/**\r
+ * Event fired before the #getData call returns allowing additional manipulation.\r
+ * @name CKEDITOR.editor#getData\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data.dataValue The data that will be returned.\r
+ */\r
+\r
+/**\r
+ * Event fired before the #setData call is executed allowing additional manipulation.\r
+ * @name CKEDITOR.editor#setData\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data.dataValue The data that will be used.\r
+ */\r
+\r
+/**\r
+ * Event fired at the end of the #setData call is executed. Usually it's better to use the\r
+ * {@link CKEDITOR.editor.prototype.dataReady} event.\r
+ * @name CKEDITOR.editor#afterSetData\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data.dataValue The data that has been set.\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the #insertHtml call\r
+ * @name CKEDITOR.editor#insertHtml\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} data The HTML to insert.\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the #insertText call\r
+ * @name CKEDITOR.editor#insertText\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {String} text The text to insert.\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the #insertElement call\r
+ * @name CKEDITOR.editor#insertElement\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ * @param {Object} element The element to insert.\r
+ */\r