JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / core / editor.js
index d9017c0..c065301 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
@@ -113,6 +115,7 @@ 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
                editor.skinName = skinName;\r
@@ -123,7 +126,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                editor.fireOnce( 'configLoaded' );\r
 \r
                // Load language file.\r
-               loadLang( editor );\r
+               loadSkin( editor );\r
        };\r
 \r
        var loadLang = function( editor )\r
@@ -245,7 +248,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 +257,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
@@ -435,6 +438,13 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        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
@@ -459,6 +469,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                        this.theme.destroy( this );\r
                        this.fire( 'destroy' );\r
                        CKEDITOR.remove( this );\r
+                       CKEDITOR.fire( 'instanceDestroyed', null, this );\r
                },\r
 \r
                /**\r
@@ -564,13 +575,30 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\r
 \r
                /**\r
-                * Sets the editor data. The data must be provided in raw format.\r
+                * Sets the editor data. The data must be provided in raw format (HTML).\r
+                * <b>Note:</b> This's an asynchronous method, the {@param callback}\r
+                * function should be relied on if you want to interact with the editor\r
+                * after data is fully loaded.\r
+                *\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
                 * @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
                 */\r
-               setData : function( data )\r
+               setData : function( data , callback )\r
                {\r
+                       if( callback )\r
+                       {\r
+                               this.on( 'dataReady', function( evt )\r
+                               {\r
+                                       evt.removeListener();\r
+                                       callback.call( evt.editor );\r
+                               } );\r
+                       }\r
                        // Fire "setData" so data manipulation may happen.\r
                        var eventData = { dataValue : data };\r
                        this.fire( 'setData', eventData );\r
@@ -628,10 +656,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 +681,12 @@ 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
+ * @type {Boolean}\r
+ * @default false\r
+ * @example\r
+ * config.htmlEncodeOutput = true;\r
+ */\r