JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.4
[ckeditor.git] / _source / core / editor.js
index a8921db..1e56a12 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, 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
@@ -227,6 +227,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
@@ -269,7 +272,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
@@ -277,7 +280,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
@@ -302,7 +305,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
@@ -364,7 +367,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
@@ -544,44 +547,9 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        if ( !noUpdate )\r
                                this.updateElement();\r
 \r
-                       if ( this.mode )\r
-                       {\r
-                               // ->           currentMode.unload( holderElement );\r
-                               this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );\r
-                       }\r
-\r
-                       this.theme.destroy( this );\r
-\r
-                       var toolbars,\r
-                               index = 0,\r
-                               j,\r
-                               items,\r
-                               instance;\r
-\r
-                       if ( this.toolbox )\r
-                       {\r
-                               toolbars = this.toolbox.toolbars;\r
-                               for ( ; index < toolbars.length ; index++ )\r
-                               {\r
-                                       items = toolbars[ index ].items;\r
-                                       for ( j = 0 ; j < items.length ; j++ )\r
-                                       {\r
-                                               instance = items[ j ];\r
-                                               if ( instance.clickFn ) CKEDITOR.tools.removeFunction( instance.clickFn );\r
-                                               if ( instance.keyDownFn ) CKEDITOR.tools.removeFunction( instance.keyDownFn );\r
-\r
-                                               if ( instance.index ) CKEDITOR.ui.button._.instances[ instance.index ] = null;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       if ( this.contextMenu )\r
-                               CKEDITOR.tools.removeFunction( this.contextMenu._.functionId );\r
-\r
-                       if ( this._.filebrowserFn )\r
-                               CKEDITOR.tools.removeFunction( this._.filebrowserFn );\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
@@ -593,7 +561,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 * @returns {Boolean} "true" if the command has been successfuly\r
                 *              executed, otherwise "false".\r
                 * @example\r
-                * editorInstance.execCommand( 'Bold' );\r
+                * editorInstance.execCommand( 'bold' );\r
                 */\r
                execCommand : function( commandName, data )\r
                {\r
@@ -716,6 +684,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 *              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>( '&lt;p&gt;This is the editor data.&lt;/p&gt;' );\r
                 * @example\r
@@ -724,7 +693,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 *         this.checkDirty();    // true\r
                 *     });\r
                 */\r
-               setData : function( data , callback )\r
+               setData : function( data , callback, internal )\r
                {\r
                        if( callback )\r
                        {\r
@@ -737,11 +706,11 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
 \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
@@ -756,6 +725,22 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\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 &lt;br /&gt;.\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
@@ -873,9 +858,9 @@ CKEDITOR.on( 'loaded', function()
 \r
 /**\r
  * Fired when all plugins are loaded and initialized into the editor instance.\r
- * @name CKEDITOR#pluginsLoaded\r
+ * @name CKEDITOR.editor#pluginsLoaded\r
  * @event\r
- * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
  */\r
 \r
 /**\r
@@ -922,3 +907,79 @@ CKEDITOR.on( 'loaded', function()
  * 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