JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / core / editor.js
index d9017c0..ff17efb 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\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
@@ -33,6 +33,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                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
@@ -44,7 +46,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        // If there is no other customConfig in the chain, fire the\r
                        // "configLoaded" event.\r
-                       if ( editor.config.customConfig == customConfig || !loadConfig( editor ) )\r
+                       if ( CKEDITOR.getUrl( editor.config.customConfig ) == customConfig || !loadConfig( editor ) )\r
                                editor.fireOnce( 'customConfigLoaded' );\r
                }\r
                else\r
@@ -113,25 +115,89 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                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 through the <code>{@link CKEDITOR.config.skin}</code> setting.\r
+                * @name CKEDITOR.editor.prototype.skinName\r
+                * @type String\r
+                * @example\r
+                * alert( editor.skinName );  // E.g. "kama"\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 );  // E.g. "http://example.com/ckeditor/skins/kama/"\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 );  // E.g. "cke_skin_kama"\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 <code>{@link CKEDITOR.config.tabIndex}</code>\r
+                * setting or taken from the <code>tabindex</code> attribute of the\r
+                * <code>{@link #element}</code> associated with the editor.\r
+                * @name CKEDITOR.editor.prototype.tabIndex\r
+                * @type Number\r
+                * @default 0 (zero)\r
+                * @example\r
+                * alert( editor.tabIndex );  // E.g. "0"\r
+                */\r
+               editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;\r
+\r
+               /**\r
+                * Indicates the read-only state of this editor. This is a read-only property.\r
+                * @name CKEDITOR.editor.prototype.readOnly\r
+                * @type Boolean\r
+                * @since 3.6\r
+                * @see CKEDITOR.editor#setReadOnly\r
+                */\r
+               editor.readOnly = !!( editor.config.readOnly || editor.element.getAttribute( 'disabled' ) );\r
+\r
                // Fire the "configLoaded" event.\r
                editor.fireOnce( 'configLoaded' );\r
 \r
                // Load language file.\r
-               loadLang( editor );\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 interface elements of this editor instance.\r
+                                * @name CKEDITOR.editor.prototype.langCode\r
+                                * @type String\r
+                                * @example\r
+                                * alert( editor.langCode );  // E.g. "en"\r
+                                */\r
                                editor.langCode = languageCode;\r
 \r
+                               /**\r
+                                * An object that contains 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 );  // E.g. "Negrito" (if the language is set to 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
@@ -141,6 +207,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 && editor.lang.dir == 'rtl' )\r
                                        editor.lang.dir = 'ltr';\r
 \r
+                               editor.fire( 'langLoaded' );\r
+\r
+                               var config = editor.config;\r
+                               config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );\r
+\r
                                loadPlugins( editor );\r
                        });\r
        };\r
@@ -167,6 +238,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        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
@@ -180,7 +254,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // The list of URLs to language files.\r
                                var languageFiles = [];\r
 \r
-                               // Cache the loaded plugin names.\r
+                               /**\r
+                                * An object that contains references to all plugins used by this\r
+                                * editor instance.\r
+                                * @name CKEDITOR.editor.prototype.plugins\r
+                                * @type Object\r
+                                * @example\r
+                                * alert( editor.plugins.dialog.path );  // E.g. "http://example.com/ckeditor/plugins/dialog/"\r
+                                */\r
                                editor.plugins = plugins;\r
 \r
                                // Loop through all plugins, to build the list of language\r
@@ -202,7 +283,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // 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.lang[ lang ] )\r
+                                               if ( !plugin.langEntries || !plugin.langEntries[ lang ] )\r
                                                {\r
                                                        // Put the language file URL into the list of files to\r
                                                        // get downloaded.\r
@@ -210,7 +291,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                }\r
                                                else\r
                                                {\r
-                                                       CKEDITOR.tools.extend( editor.lang, plugin.lang[ lang ] );\r
+                                                       CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );\r
                                                        lang = null;\r
                                                }\r
                                        }\r
@@ -235,7 +316,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \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.lang[ languageCodes[ i ] ] );\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
@@ -245,7 +326,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                // Load the editor skin.\r
                                                editor.fire( 'pluginsLoaded' );\r
-                                               loadSkin( editor );\r
+                                               loadTheme( editor );\r
                                        });\r
                        });\r
        };\r
@@ -254,7 +335,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        {\r
                CKEDITOR.skins.load( editor, 'editor', function()\r
                        {\r
-                               loadTheme( editor );\r
+                               loadLang( editor );\r
                        });\r
        };\r
 \r
@@ -263,6 +344,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                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 );  // E.g. "http://example.com/ckeditor/themes/default/"\r
+                                */\r
                                var editorTheme = editor.theme = CKEDITOR.themes.get( theme );\r
                                editorTheme.path = CKEDITOR.themes.getPath( theme );\r
                                editorTheme.build( editor );\r
@@ -290,7 +378,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                // Setup the submit function because it doesn't fire the\r
                                // "submit" event.\r
-                               if ( !form.$.submit.nodeName )\r
+                               if ( !form.$.submit.nodeName && !form.$.submit.length )\r
                                {\r
                                        form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )\r
                                                {\r
@@ -317,22 +405,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        };\r
 \r
-       function updateCommandsMode()\r
+       function updateCommands()\r
        {\r
                var command,\r
                        commands = this._.commands,\r
                        mode = this.mode;\r
 \r
+               if ( !mode )\r
+                       return;\r
+\r
                for ( var name in commands )\r
                {\r
                        command = commands[ name ];\r
-                       command[ command.modes[ mode ] ? 'enable' : 'disable' ]();\r
+                       command[ command.startDisabled ? 'disable' :\r
+                                        this.readOnly && !command.readOnly ? '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
+        * contructor (<code>editor_basic.js</code>).\r
         * @private\r
         */\r
        CKEDITOR.editor.prototype._init = function()\r
@@ -348,24 +440,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        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
+                        * The DOM element that was replaced by this editor instance. This\r
+                        * element stores 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
+                        * alert( <strong>editor.element</strong>.getName() );  // E.g. "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
+                        * The editor instance name. It may be the replaced element ID, name, or\r
+                        * a default name using the progressive counter (<code>editor1</code>,\r
+                        * <code>editor2</code>, ...).\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
+                        * alert( <strong>editor.name</strong> );  // "editor1"\r
                         */\r
                        this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
                                                        && ( element.getId() || element.getNameAtt() ) )\r
@@ -375,20 +468,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';\r
 \r
                        /**\r
+                        * A unique random string assigned to each editor instance on 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
+                        * settings defined in <code>(@link CKEDITOR.config}</code>, 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
+                        * alert( <strong>editor.config.theme</strong> );  // E.g. "default"\r
                         */\r
                        this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );\r
 \r
                        /**\r
-                        * Namespace containing UI features related to this editor instance.\r
+                        * The namespace containing UI features related to this editor instance.\r
                         * @name CKEDITOR.editor.prototype.ui\r
                         * @type CKEDITOR.ui\r
                         * @example\r
@@ -398,7 +498,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        /**\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
+                        * intended for developers adding UI elements to the editor interface.\r
                         * @name CKEDITOR.editor.prototype.focusManager\r
                         * @type CKEDITOR.focusManager\r
                         * @example\r
@@ -407,7 +507,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        CKEDITOR.fire( 'instanceCreated', null, this );\r
 \r
-                       this.on( 'mode', updateCommandsMode, null, null, 1 );\r
+                       this.on( 'mode', updateCommands, null, null, 1 );\r
+                       this.on( 'readOnly', updateCommands, null, null, 1 );\r
 \r
                        initConfig( this, instanceConfig );\r
                };\r
@@ -418,7 +519,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
        {\r
                /**\r
                 * Adds a command definition to the editor instance. Commands added with\r
-                * this function can be later executed with {@link #execCommand}.\r
+                * this function can be executed later with the <code>{@link #execCommand}</code> method.\r
                 * @param {String} commandName The indentifier name of the command.\r
                 * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.\r
                 * @example\r
@@ -435,6 +536,14 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );\r
                },\r
 \r
+               /**\r
+                * Adds a piece of CSS code to the editor which will be applied to the WYSIWYG editing document.\r
+                * This CSS would not be added to the output, and is there mainly for editor-specific editing requirements.\r
+                * Note: This function should be called before the 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
@@ -447,28 +556,31 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 *              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
+                * alert( CKEDITOR.instances.editor1 );  //  E.g "object"\r
+                * <strong>CKEDITOR.instances.editor1.destroy()</strong>;\r
+                * alert( CKEDITOR.instances.editor1 );  // "undefined"\r
                 */\r
                destroy : function( noUpdate )\r
                {\r
                        if ( !noUpdate )\r
                                this.updateElement();\r
 \r
-                       this.theme.destroy( this );\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
+                * Executes a command associated with the editor.\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
+                * @param {Object} [data] Data to be passed to the command.\r
+                * @returns {Boolean} <code>true</code> if the command was executed\r
+                *              successfully, otherwise <code>false</code>.\r
+                * @see CKEDITOR.editor.addCommand\r
                 * @example\r
-                * editorInstance.execCommand( 'Bold' );\r
+                * editorInstance.execCommand( 'bold' );\r
                 */\r
                execCommand : function( commandName, data )\r
                {\r
@@ -498,12 +610,14 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\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
+                * Gets one of the registered commands. Note that after registering a\r
+                * command definition with <code>{@link #addCommand}</code>, it is\r
+                * transformed internally into an instance of\r
+                * <code>{@link CKEDITOR.command}</code>, which will then be returned\r
+                * 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
+                * This is the same name that is used to register the command with\r
+                *              <code>addCommand</code>.\r
                 * @returns {CKEDITOR.command} The command object identified by the\r
                 * provided name.\r
                 */\r
@@ -518,7 +632,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 * @type String\r
                 * @returns (String) The editor data.\r
                 * @example\r
-                * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )\r
+                * if ( CKEDITOR.instances.editor1.<strong>getData()</strong> == '' )\r
                 *     alert( 'There is no data available' );\r
                 */\r
                getData : function()\r
@@ -544,6 +658,18 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        return eventData.dataValue;\r
                },\r
 \r
+               /**\r
+                * Gets the "raw data" currently available in the editor. This is a\r
+                * fast method which returns the data as is, without processing, so it is\r
+                * not recommended to use it on resulting pages. Instead it can be used\r
+                * combined with the <code>{@link #loadSnapshot}</code> method in order\r
+                * to be able to automatically save the editor data from time to time\r
+                * while the user is using the editor, to avoid data loss, without risking\r
+                * performance issues.\r
+                * @see CKEDITOR.editor.getData\r
+                * @example\r
+                * alert( editor.getSnapshot() );\r
+                */\r
                getSnapshot : function()\r
                {\r
                        var data = this.fire( 'getSnapshot' );\r
@@ -558,33 +684,90 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        return data;\r
                },\r
 \r
+               /**\r
+                * Loads "raw data" into the editor. The 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
+                * <code>{@link #getSnapshot}</code> produced data.\r
+                * @see CKEDITOR.editor.setData\r
+                * @example\r
+                * var data = editor.getSnapshot();\r
+                * editor.<strong>loadSnapshot( data )</strong>;\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.\r
-                * @param {String} data HTML code to replace the curent content in the editor.\r
+                * Sets the editor data. The data must be provided in the raw format (HTML).<br />\r
+                * <br />\r
+                * Note that this method is asynchronous. The <code>callback</code> 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 <code>setData</code>\r
+                *              is completed.\r
+                *@param {Boolean} internal Whether to suppress any event firing when copying data\r
+                *              internally inside the editor.\r
+                * @example\r
+                * CKEDITOR.instances.editor1.<strong>setData</strong>( '&lt;p&gt;This is the editor data.&lt;/p&gt;' );\r
                 * @example\r
-                * CKEDITOR.instances.editor1.<b>setData( '&lt;p&gt;This is the editor data.&lt;/p&gt;' )</b>;\r
+                * CKEDITOR.instances.editor1.<strong>setData</strong>( '&lt;p&gt;Some other editor data.&lt;/p&gt;', function()\r
+                *     {\r
+                *         this.checkDirty();  // true\r
+                *     });\r
                 */\r
-               setData : function( data )\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
-                       this.fire( 'setData', eventData );\r
+                       !internal && this.fire( 'setData', eventData );\r
 \r
                        this._.data = eventData.dataValue;\r
 \r
-                       this.fire( 'afterSetData', eventData );\r
+                       !internal && this.fire( 'afterSetData', eventData );\r
                },\r
 \r
                /**\r
-                * Inserts HTML into the currently selected position in the editor.\r
+                * Puts or restores the editor into read-only state. When in read-only,\r
+                * the user is not able to change the editor contents, but can still use\r
+                * some editor features. This function sets the <code>{@link CKEDITOR.config.readOnly}</code>\r
+                * property of the editor, firing the <code>{@link CKEDITOR.editor#readOnly}</code> event.<br><br>\r
+                * <strong>Note:</strong> the current editing area will be reloaded.\r
+                * @param {Boolean} [isReadOnly] Indicates that the editor must go\r
+                *              read-only (<code>true</code>, default) or be restored and made editable\r
+                *              (<code>false</code>).\r
+                * @since 3.6\r
+                */\r
+               setReadOnly : function( isReadOnly )\r
+               {\r
+                       isReadOnly = ( isReadOnly == undefined ) || isReadOnly;\r
+\r
+                       if ( this.readOnly != isReadOnly )\r
+                       {\r
+                               this.readOnly = isReadOnly;\r
+\r
+                               // Fire the readOnly event so the editor features can update\r
+                               // their state accordingly.\r
+                               this.fire( 'readOnly' );\r
+                       }\r
+               },\r
+\r
+               /**\r
+                * Inserts HTML code into the currently selected position in the editor in WYSIWYG mode.\r
                 * @param {String} data HTML code to be inserted into the editor.\r
                 * @example\r
-                * CKEDITOR.instances.editor1.<b>insertHtml( '&lt;p&gt;This is a new paragraph.&lt;/p&gt;' )</b>;\r
+                * CKEDITOR.instances.editor1.<strong>insertHtml( '&lt;p&gt;This is a new paragraph.&lt;/p&gt;' )</strong>;\r
                 */\r
                insertHtml : function( data )\r
                {\r
@@ -592,24 +775,67 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\r
 \r
                /**\r
+                * Insert text content into the currently selected position in the\r
+                * editor in WYSIWYG mode. The 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. This depends on <code>{@link CKEDITOR.config.enterMode}</code>;\r
+                * A single line-break will be instead translated into one &lt;br /&gt;.\r
+                * @since 3.5\r
+                * @param {String} text Text to be inserted into the editor.\r
+                * @example\r
+                * CKEDITOR.instances.editor1.<strong>insertText( ' line1 \n\n line2' )</strong>;\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
+                * editor in WYSIWYG mode.\r
                 * @param {CKEDITOR.dom.element} element The element to be inserted\r
                 *              into the editor.\r
                 * @example\r
                 * var element = CKEDITOR.dom.element.createFromHtml( '&lt;img src="hello.png" border="0" title="Hello" /&gt;' );\r
-                * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;\r
+                * CKEDITOR.instances.editor1.<strong>insertElement( element )</strong>;\r
                 */\r
                insertElement : function( element )\r
                {\r
                        this.fire( 'insertElement', element );\r
                },\r
 \r
+               /**\r
+                * Checks whether the current editor contents contain changes when\r
+                * compared to the contents loaded into the editor at startup, or to\r
+                * the contents available in the editor when <code>{@link #resetDirty}</code>\r
+                * was called.\r
+                * @returns {Boolean} "true" is the contents contain changes.\r
+                * @example\r
+                * function beforeUnload( e )\r
+                * {\r
+                *     if ( CKEDITOR.instances.editor1.<strong>checkDirty()</strong> )\r
+                *              return e.returnValue = "You will lose 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
+                * <code>{@link #checkDirty}</code> will return <code>false</code> if the user will not\r
+                * have made further changes to the contents.\r
+                * @example\r
+                * alert( editor.checkDirty() );  // E.g. "true"\r
+                * editor.<strong>resetDirty()</strong>;\r
+                * alert( editor.checkDirty() );  // "false"\r
+                */\r
                resetDirty : function()\r
                {\r
                        if ( this.mayBeDirty )\r
@@ -617,8 +843,9 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\r
 \r
                /**\r
-                * Updates the &lt;textarea&gt; element that has been replaced by the editor with\r
+                * Updates the <code>&lt;textarea&gt;</code> element that was replaced by the editor with\r
                 * the current data available in the editor.\r
+                * @see CKEDITOR.editor.element\r
                 * @example\r
                 * CKEDITOR.instances.editor1.updateElement();\r
                 * alert( document.getElementById( 'editor1' ).value );  // The current editor data.\r
@@ -628,10 +855,15 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        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( this.getData() );\r
+                                       element.setValue( data );\r
                                else\r
-                                       element.setHtml( this.getData() );\r
+                                       element.setHtml( data );\r
                        }\r
                }\r
        });\r
@@ -648,3 +880,180 @@ CKEDITOR.on( 'loaded', function()
                                pending[ i ]._init();\r
                }\r
        });\r
+\r
+/**\r
+ * Whether to escape HTML when the editor updates the 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
+ * If <code>true</code>, makes the editor start in read-only state. Otherwise, it will check\r
+ * if the linked <code>&lt;textarea&gt;</code> element has the <code>disabled</code> attribute.\r
+ * @name CKEDITOR.config.readOnly\r
+ * @see CKEDITOR.editor#setReadOnly\r
+ * @type Boolean\r
+ * @default false\r
+ * @since 3.6\r
+ * @example\r
+ * config.readOnly = 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
+ * <code>{@link CKEDITOR#instanceReady}</code> 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 the language is loaded into the editor instance.\r
+ * @name CKEDITOR.editor#langLoaded\r
+ * @event\r
+ * @since 3.6.1\r
+ * @param {CKEDITOR.editor} editor This editor instance.\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 <code>{@link #execCommand}</code> 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 <code>{@link #execCommand}</code> 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 when the custom configuration file is loaded, before the final\r
+ * configurations initialization.<br />\r
+ * <br />\r
+ * Custom configuration files can be loaded thorugh the\r
+ * <code>{@link CKEDITOR.config.customConfig}</code> setting. Several files can be loaded\r
+ * by changing this setting.\r
+ * @name CKEDITOR.editor#customConfigLoaded\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor This editor instance.\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
+ */\r
+\r
+/**\r
+ * Fired when this editor instance is destroyed. The editor at this\r
+ * point is not usable and this event should be used to perform the 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 <code>#getSnapshot</code> call.\r
+ * @name CKEDITOR.editor#getSnapshot\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Internal event to perform the <code>#loadSnapshot</code> call.\r
+ * @name CKEDITOR.editor#loadSnapshot\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Event fired before the <code>#getData</code> 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 <code>#setData</code> 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 <code>#setData</code> call execution. Usually it is better to use the\r
+ * <code>{@link CKEDITOR.editor.prototype.dataReady}</code> 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 <code>#insertHtml</code> 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 <code>#insertText</code> 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 <code>#insertElement</code> 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
+\r
+/**\r
+ * Event fired after the <code>{@link CKEDITOR.editor#readOnly}</code> property changes.\r
+ * @name CKEDITOR.editor#readOnly\r
+ * @event\r
+ * @since 3.6\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ */\r