JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.3
[ckeditor.git] / _source / core / editor.js
index e214778..0b373f7 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, 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
@@ -120,11 +122,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                editor.skinPath = skinPath;\r
                editor.skinClass = 'cke_skin_' + skinName;\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
-               loadLang( editor );\r
+               loadSkin( editor );\r
        };\r
 \r
        var loadLang = function( editor )\r
@@ -142,6 +146,9 @@ 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
+                               var config = editor.config;\r
+                               config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );\r
+\r
                                loadPlugins( editor );\r
                        });\r
        };\r
@@ -246,7 +253,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
@@ -255,7 +262,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
@@ -327,7 +334,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                for ( var name in commands )\r
                {\r
                        command = commands[ name ];\r
-                       command[ command.modes[ mode ] ? 'enable' : 'disable' ]();\r
+                       command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();\r
                }\r
        }\r
 \r
@@ -464,7 +471,43 @@ 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
                        CKEDITOR.remove( this );\r
                        CKEDITOR.fire( 'instanceDestroyed', null, this );\r
@@ -573,15 +616,21 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\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
-                * @param {Function} callback Function to be called after the setData is completed.\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
                 * @example\r
-                * CKEDITOR.instances.editor1.<b>setData( '&lt;p&gt;This is the editor data.&lt;/p&gt;' )</b>;\r
-                * CKEDITOR.instances.editor1.setData( '&lt;p&gt;Some other editor data.&lt;/p&gt;', function()\r
-                * {\r
-                *              CKEDITOR.instances.editor1.checkDirty();        // true\r
-                * } );\r
+                * CKEDITOR.instances.editor1.<b>setData</b>( '&lt;p&gt;This is the editor data.&lt;/p&gt;' );\r
+                * @example\r
+                * CKEDITOR.instances.editor1.<b>setData</b>( '&lt;p&gt;Some other editor data.&lt;/p&gt;', function()\r
+                *     {\r
+                *         this.checkDirty();    // true\r
+                *     });\r
                 */\r
                setData : function( data , callback )\r
                {\r
@@ -593,6 +642,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                                        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
@@ -650,10 +700,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
@@ -670,3 +725,35 @@ CKEDITOR.on( 'loaded', function()
                                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#pluginsLoaded\r
+ * @event\r
+ */\r