JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
e21477830c15f7afe7d2dc92dfeaf656b61189c4
[ckeditor.git] / _source / core / editor.js
1 /*\r
2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview Defines the {@link CKEDITOR.editor} class, which represents an\r
8  *              editor instance.\r
9  */\r
10 \r
11 (function()\r
12 {\r
13         // The counter for automatic instance names.\r
14         var nameCounter = 0;\r
15 \r
16         var getNewName = function()\r
17         {\r
18                 var name = 'editor' + ( ++nameCounter );\r
19                 return ( CKEDITOR.instances && CKEDITOR.instances[ name ] ) ? getNewName() : name;\r
20         };\r
21 \r
22         // ##### START: Config Privates\r
23 \r
24         // These function loads custom configuration files and cache the\r
25         // CKEDITOR.editorConfig functions defined on them, so there is no need to\r
26         // download them more than once for several instances.\r
27         var loadConfigLoaded = {};\r
28         var loadConfig = function( editor )\r
29         {\r
30                 var customConfig = editor.config.customConfig;\r
31 \r
32                 // Check if there is a custom config to load.\r
33                 if ( !customConfig )\r
34                         return false;\r
35 \r
36                 var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = {} );\r
37 \r
38                 // If the custom config has already been downloaded, reuse it.\r
39                 if ( loadedConfig.fn )\r
40                 {\r
41                         // Call the cached CKEDITOR.editorConfig defined in the custom\r
42                         // config file for the editor instance depending on it.\r
43                         loadedConfig.fn.call( editor, editor.config );\r
44 \r
45                         // If there is no other customConfig in the chain, fire the\r
46                         // "configLoaded" event.\r
47                         if ( editor.config.customConfig == customConfig || !loadConfig( editor ) )\r
48                                 editor.fireOnce( 'customConfigLoaded' );\r
49                 }\r
50                 else\r
51                 {\r
52                         // Load the custom configuration file.\r
53                         CKEDITOR.scriptLoader.load( customConfig, function()\r
54                                 {\r
55                                         // If the CKEDITOR.editorConfig function has been properly\r
56                                         // defined in the custom configuration file, cache it.\r
57                                         if ( CKEDITOR.editorConfig )\r
58                                                 loadedConfig.fn = CKEDITOR.editorConfig;\r
59                                         else\r
60                                                 loadedConfig.fn = function(){};\r
61 \r
62                                         // Call the load config again. This time the custom\r
63                                         // config is already cached and so it will get loaded.\r
64                                         loadConfig( editor );\r
65                                 });\r
66                 }\r
67 \r
68                 return true;\r
69         };\r
70 \r
71         var initConfig = function( editor, instanceConfig )\r
72         {\r
73                 // Setup the lister for the "customConfigLoaded" event.\r
74                 editor.on( 'customConfigLoaded', function()\r
75                         {\r
76                                 if ( instanceConfig )\r
77                                 {\r
78                                         // Register the events that may have been set at the instance\r
79                                         // configuration object.\r
80                                         if ( instanceConfig.on )\r
81                                         {\r
82                                                 for ( var eventName in instanceConfig.on )\r
83                                                 {\r
84                                                         editor.on( eventName, instanceConfig.on[ eventName ] );\r
85                                                 }\r
86                                         }\r
87 \r
88                                         // Overwrite the settings from the in-page config.\r
89                                         CKEDITOR.tools.extend( editor.config, instanceConfig, true );\r
90 \r
91                                         delete editor.config.on;\r
92                                 }\r
93 \r
94                                 onConfigLoaded( editor );\r
95                         });\r
96 \r
97                 // The instance config may override the customConfig setting to avoid\r
98                 // loading the default ~/config.js file.\r
99                 if ( instanceConfig && instanceConfig.customConfig != undefined )\r
100                         editor.config.customConfig = instanceConfig.customConfig;\r
101 \r
102                 // Load configs from the custom configuration files.\r
103                 if ( !loadConfig( editor ) )\r
104                         editor.fireOnce( 'customConfigLoaded' );\r
105         };\r
106 \r
107         // ##### END: Config Privates\r
108 \r
109         var onConfigLoaded = function( editor )\r
110         {\r
111                 // Set config related properties.\r
112 \r
113                 var skin = editor.config.skin.split( ',' ),\r
114                         skinName = skin[ 0 ],\r
115                         skinPath = CKEDITOR.getUrl( skin[ 1 ] || (\r
116                                 '_source/' +    // @Packager.RemoveLine\r
117                                 'skins/' + skinName + '/' ) );\r
118 \r
119                 editor.skinName = skinName;\r
120                 editor.skinPath = skinPath;\r
121                 editor.skinClass = 'cke_skin_' + skinName;\r
122 \r
123                 // Fire the "configLoaded" event.\r
124                 editor.fireOnce( 'configLoaded' );\r
125 \r
126                 // Load language file.\r
127                 loadLang( editor );\r
128         };\r
129 \r
130         var loadLang = function( editor )\r
131         {\r
132                 CKEDITOR.lang.load( editor.config.language, editor.config.defaultLanguage, function( languageCode, lang )\r
133                         {\r
134                                 editor.langCode = languageCode;\r
135 \r
136                                 // As we'll be adding plugin specific entries that could come\r
137                                 // from different language code files, we need a copy of lang,\r
138                                 // not a direct reference to it.\r
139                                 editor.lang = CKEDITOR.tools.prototypedCopy( lang );\r
140 \r
141                                 // We're not able to support RTL in Firefox 2 at this time.\r
142                                 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 && editor.lang.dir == 'rtl' )\r
143                                         editor.lang.dir = 'ltr';\r
144 \r
145                                 loadPlugins( editor );\r
146                         });\r
147         };\r
148 \r
149         var loadPlugins = function( editor )\r
150         {\r
151                 var config                      = editor.config,\r
152                         plugins                 = config.plugins,\r
153                         extraPlugins    = config.extraPlugins,\r
154                         removePlugins   = config.removePlugins;\r
155 \r
156                 if ( extraPlugins )\r
157                 {\r
158                         // Remove them first to avoid duplications.\r
159                         var removeRegex = new RegExp( '(?:^|,)(?:' + extraPlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );\r
160                         plugins = plugins.replace( removeRegex, '' );\r
161 \r
162                         plugins += ',' + extraPlugins;\r
163                 }\r
164 \r
165                 if ( removePlugins )\r
166                 {\r
167                         removeRegex = new RegExp( '(?:^|,)(?:' + removePlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );\r
168                         plugins = plugins.replace( removeRegex, '' );\r
169                 }\r
170 \r
171                 // Load all plugins defined in the "plugins" setting.\r
172                 CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )\r
173                         {\r
174                                 // The list of plugins.\r
175                                 var pluginsArray = [];\r
176 \r
177                                 // The language code to get loaded for each plugin. Null\r
178                                 // entries will be appended for plugins with no language files.\r
179                                 var languageCodes = [];\r
180 \r
181                                 // The list of URLs to language files.\r
182                                 var languageFiles = [];\r
183 \r
184                                 // Cache the loaded plugin names.\r
185                                 editor.plugins = plugins;\r
186 \r
187                                 // Loop through all plugins, to build the list of language\r
188                                 // files to get loaded.\r
189                                 for ( var pluginName in plugins )\r
190                                 {\r
191                                         var plugin = plugins[ pluginName ],\r
192                                                 pluginLangs = plugin.lang,\r
193                                                 pluginPath = CKEDITOR.plugins.getPath( pluginName ),\r
194                                                 lang = null;\r
195 \r
196                                         // Set the plugin path in the plugin.\r
197                                         plugin.path = pluginPath;\r
198 \r
199                                         // If the plugin has "lang".\r
200                                         if ( pluginLangs )\r
201                                         {\r
202                                                 // Resolve the plugin language. If the current language\r
203                                                 // is not available, get the first one (default one).\r
204                                                 lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );\r
205 \r
206                                                 if ( !plugin.lang[ lang ] )\r
207                                                 {\r
208                                                         // Put the language file URL into the list of files to\r
209                                                         // get downloaded.\r
210                                                         languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );\r
211                                                 }\r
212                                                 else\r
213                                                 {\r
214                                                         CKEDITOR.tools.extend( editor.lang, plugin.lang[ lang ] );\r
215                                                         lang = null;\r
216                                                 }\r
217                                         }\r
218 \r
219                                         // Save the language code, so we know later which\r
220                                         // language has been resolved to this plugin.\r
221                                         languageCodes.push( lang );\r
222 \r
223                                         pluginsArray.push( plugin );\r
224                                 }\r
225 \r
226                                 // Load all plugin specific language files in a row.\r
227                                 CKEDITOR.scriptLoader.load( languageFiles, function()\r
228                                         {\r
229                                                 // Initialize all plugins that have the "beforeInit" and "init" methods defined.\r
230                                                 var methods = [ 'beforeInit', 'init', 'afterInit' ];\r
231                                                 for ( var m = 0 ; m < methods.length ; m++ )\r
232                                                 {\r
233                                                         for ( var i = 0 ; i < pluginsArray.length ; i++ )\r
234                                                         {\r
235                                                                 var plugin = pluginsArray[ i ];\r
236 \r
237                                                                 // Uses the first loop to update the language entries also.\r
238                                                                 if ( m === 0 && languageCodes[ i ] && plugin.lang )\r
239                                                                         CKEDITOR.tools.extend( editor.lang, plugin.lang[ languageCodes[ i ] ] );\r
240 \r
241                                                                 // Call the plugin method (beforeInit and init).\r
242                                                                 if ( plugin[ methods[ m ] ] )\r
243                                                                         plugin[ methods[ m ] ]( editor );\r
244                                                         }\r
245                                                 }\r
246 \r
247                                                 // Load the editor skin.\r
248                                                 editor.fire( 'pluginsLoaded' );\r
249                                                 loadSkin( editor );\r
250                                         });\r
251                         });\r
252         };\r
253 \r
254         var loadSkin = function( editor )\r
255         {\r
256                 CKEDITOR.skins.load( editor, 'editor', function()\r
257                         {\r
258                                 loadTheme( editor );\r
259                         });\r
260         };\r
261 \r
262         var loadTheme = function( editor )\r
263         {\r
264                 var theme = editor.config.theme;\r
265                 CKEDITOR.themes.load( theme, function()\r
266                         {\r
267                                 var editorTheme = editor.theme = CKEDITOR.themes.get( theme );\r
268                                 editorTheme.path = CKEDITOR.themes.getPath( theme );\r
269                                 editorTheme.build( editor );\r
270 \r
271                                 if ( editor.config.autoUpdateElement )\r
272                                         attachToForm( editor );\r
273                         });\r
274         };\r
275 \r
276         var attachToForm = function( editor )\r
277         {\r
278                 var element = editor.element;\r
279 \r
280                 // If are replacing a textarea, we must\r
281                 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )\r
282                 {\r
283                         var form = element.$.form && new CKEDITOR.dom.element( element.$.form );\r
284                         if ( form )\r
285                         {\r
286                                 function onSubmit()\r
287                                 {\r
288                                         editor.updateElement();\r
289                                 }\r
290                                 form.on( 'submit',onSubmit );\r
291 \r
292                                 // Setup the submit function because it doesn't fire the\r
293                                 // "submit" event.\r
294                                 if ( !form.$.submit.nodeName )\r
295                                 {\r
296                                         form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )\r
297                                                 {\r
298                                                         return function()\r
299                                                                 {\r
300                                                                         editor.updateElement();\r
301 \r
302                                                                         // For IE, the DOM submit function is not a\r
303                                                                         // function, so we need thid check.\r
304                                                                         if ( originalSubmit.apply )\r
305                                                                                 originalSubmit.apply( this, arguments );\r
306                                                                         else\r
307                                                                                 originalSubmit();\r
308                                                                 };\r
309                                                 });\r
310                                 }\r
311 \r
312                                 // Remove 'submit' events registered on form element before destroying.(#3988)\r
313                                 editor.on( 'destroy', function()\r
314                                 {\r
315                                         form.removeListener( 'submit', onSubmit );\r
316                                 } );\r
317                         }\r
318                 }\r
319         };\r
320 \r
321         function updateCommandsMode()\r
322         {\r
323                 var command,\r
324                         commands = this._.commands,\r
325                         mode = this.mode;\r
326 \r
327                 for ( var name in commands )\r
328                 {\r
329                         command = commands[ name ];\r
330                         command[ command.modes[ mode ] ? 'enable' : 'disable' ]();\r
331                 }\r
332         }\r
333 \r
334         /**\r
335          * Initializes the editor instance. This function is called by the editor\r
336          * contructor (editor_basic.js).\r
337          * @private\r
338          */\r
339         CKEDITOR.editor.prototype._init = function()\r
340                 {\r
341                         // Get the properties that have been saved in the editor_base\r
342                         // implementation.\r
343                         var element                     = CKEDITOR.dom.element.get( this._.element ),\r
344                                 instanceConfig  = this._.instanceConfig;\r
345                         delete this._.element;\r
346                         delete this._.instanceConfig;\r
347 \r
348                         this._.commands = {};\r
349                         this._.styles = [];\r
350 \r
351                         /**\r
352                          * The DOM element that has been replaced by this editor instance. This\r
353                          * element holds the editor data on load and post.\r
354                          * @name CKEDITOR.editor.prototype.element\r
355                          * @type CKEDITOR.dom.element\r
356                          * @example\r
357                          * var editor = CKEDITOR.instances.editor1;\r
358                          * alert( <b>editor.element</b>.getName() );  "textarea"\r
359                          */\r
360                         this.element = element;\r
361 \r
362                         /**\r
363                          * The editor instance name. It hay be the replaced element id, name or\r
364                          * a default name using a progressive counter (editor1, editor2, ...).\r
365                          * @name CKEDITOR.editor.prototype.name\r
366                          * @type String\r
367                          * @example\r
368                          * var editor = CKEDITOR.instances.editor1;\r
369                          * alert( <b>editor.name</b> );  "editor1"\r
370                          */\r
371                         this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
372                                                         && ( element.getId() || element.getNameAtt() ) )\r
373                                                 || getNewName();\r
374 \r
375                         if ( this.name in CKEDITOR.instances )\r
376                                 throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';\r
377 \r
378                         /**\r
379                          * The configurations for this editor instance. It inherits all\r
380                          * settings defined in (@link CKEDITOR.config}, combined with settings\r
381                          * loaded from custom configuration files and those defined inline in\r
382                          * the page when creating the editor.\r
383                          * @name CKEDITOR.editor.prototype.config\r
384                          * @type Object\r
385                          * @example\r
386                          * var editor = CKEDITOR.instances.editor1;\r
387                          * alert( <b>editor.config.theme</b> );  "default" e.g.\r
388                          */\r
389                         this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );\r
390 \r
391                         /**\r
392                          * Namespace containing UI features related to this editor instance.\r
393                          * @name CKEDITOR.editor.prototype.ui\r
394                          * @type CKEDITOR.ui\r
395                          * @example\r
396                          */\r
397                         this.ui = new CKEDITOR.ui( this );\r
398 \r
399                         /**\r
400                          * Controls the focus state of this editor instance. This property\r
401                          * is rarely used for normal API operations. It is mainly\r
402                          * destinated to developer adding UI elements to the editor interface.\r
403                          * @name CKEDITOR.editor.prototype.focusManager\r
404                          * @type CKEDITOR.focusManager\r
405                          * @example\r
406                          */\r
407                         this.focusManager = new CKEDITOR.focusManager( this );\r
408 \r
409                         CKEDITOR.fire( 'instanceCreated', null, this );\r
410 \r
411                         this.on( 'mode', updateCommandsMode, null, null, 1 );\r
412 \r
413                         initConfig( this, instanceConfig );\r
414                 };\r
415 })();\r
416 \r
417 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,\r
418         /** @lends CKEDITOR.editor.prototype */\r
419         {\r
420                 /**\r
421                  * Adds a command definition to the editor instance. Commands added with\r
422                  * this function can be later executed with {@link #execCommand}.\r
423                  * @param {String} commandName The indentifier name of the command.\r
424                  * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.\r
425                  * @example\r
426                  * editorInstance.addCommand( 'sample',\r
427                  * {\r
428                  *     exec : function( editor )\r
429                  *     {\r
430                  *         alert( 'Executing a command for the editor name "' + editor.name + '"!' );\r
431                  *     }\r
432                  * });\r
433                  */\r
434                 addCommand : function( commandName, commandDefinition )\r
435                 {\r
436                         return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );\r
437                 },\r
438 \r
439                 /**\r
440                  * Add a trunk of css text to the editor which will be applied to the wysiwyg editing document.\r
441                  * Note: This function should be called before editor is loaded to take effect.\r
442                  * @param css {String} CSS text.\r
443                  * @example\r
444                  * editorInstance.addCss( 'body { background-color: grey; }' );\r
445                  */\r
446                 addCss : function( css )\r
447                 {\r
448                         this._.styles.push( css );\r
449                 },\r
450 \r
451                 /**\r
452                  * Destroys the editor instance, releasing all resources used by it.\r
453                  * If the editor replaced an element, the element will be recovered.\r
454                  * @param {Boolean} [noUpdate] If the instance is replacing a DOM\r
455                  *              element, this parameter indicates whether or not to update the\r
456                  *              element with the instance contents.\r
457                  * @example\r
458                  * alert( CKEDITOR.instances.editor1 );  e.g "object"\r
459                  * <b>CKEDITOR.instances.editor1.destroy()</b>;\r
460                  * alert( CKEDITOR.instances.editor1 );  "undefined"\r
461                  */\r
462                 destroy : function( noUpdate )\r
463                 {\r
464                         if ( !noUpdate )\r
465                                 this.updateElement();\r
466 \r
467                         this.theme.destroy( this );\r
468                         this.fire( 'destroy' );\r
469                         CKEDITOR.remove( this );\r
470                         CKEDITOR.fire( 'instanceDestroyed', null, this );\r
471                 },\r
472 \r
473                 /**\r
474                  * Executes a command.\r
475                  * @param {String} commandName The indentifier name of the command.\r
476                  * @param {Object} [data] Data to be passed to the command\r
477                  * @returns {Boolean} "true" if the command has been successfuly\r
478                  *              executed, otherwise "false".\r
479                  * @example\r
480                  * editorInstance.execCommand( 'Bold' );\r
481                  */\r
482                 execCommand : function( commandName, data )\r
483                 {\r
484                         var command = this.getCommand( commandName );\r
485 \r
486                         var eventData =\r
487                         {\r
488                                 name: commandName,\r
489                                 commandData: data,\r
490                                 command: command\r
491                         };\r
492 \r
493                         if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )\r
494                         {\r
495                                 if ( this.fire( 'beforeCommandExec', eventData ) !== true )\r
496                                 {\r
497                                         eventData.returnValue = command.exec( eventData.commandData );\r
498 \r
499                                         // Fire the 'afterCommandExec' immediately if command is synchronous.\r
500                                         if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )\r
501                                                 return eventData.returnValue;\r
502                                 }\r
503                         }\r
504 \r
505                         // throw 'Unknown command name "' + commandName + '"';\r
506                         return false;\r
507                 },\r
508 \r
509                 /**\r
510                  * Gets one of the registered commands. Note that, after registering a\r
511                  * command definition with addCommand, it is transformed internally\r
512                  * into an instance of {@link CKEDITOR.command}, which will be then\r
513                  * returned by this function.\r
514                  * @param {String} commandName The name of the command to be returned.\r
515                  * This is the same used to register the command with addCommand.\r
516                  * @returns {CKEDITOR.command} The command object identified by the\r
517                  * provided name.\r
518                  */\r
519                 getCommand : function( commandName )\r
520                 {\r
521                         return this._.commands[ commandName ];\r
522                 },\r
523 \r
524                 /**\r
525                  * Gets the editor data. The data will be in raw format. It is the same\r
526                  * data that is posted by the editor.\r
527                  * @type String\r
528                  * @returns (String) The editor data.\r
529                  * @example\r
530                  * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )\r
531                  *     alert( 'There is no data available' );\r
532                  */\r
533                 getData : function()\r
534                 {\r
535                         this.fire( 'beforeGetData' );\r
536 \r
537                         var eventData = this._.data;\r
538 \r
539                         if ( typeof eventData != 'string' )\r
540                         {\r
541                                 var element = this.element;\r
542                                 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
543                                         eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();\r
544                                 else\r
545                                         eventData = '';\r
546                         }\r
547 \r
548                         eventData = { dataValue : eventData };\r
549 \r
550                         // Fire "getData" so data manipulation may happen.\r
551                         this.fire( 'getData', eventData );\r
552 \r
553                         return eventData.dataValue;\r
554                 },\r
555 \r
556                 getSnapshot : function()\r
557                 {\r
558                         var data = this.fire( 'getSnapshot' );\r
559 \r
560                         if ( typeof data != 'string' )\r
561                         {\r
562                                 var element = this.element;\r
563                                 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
564                                         data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();\r
565                         }\r
566 \r
567                         return data;\r
568                 },\r
569 \r
570                 loadSnapshot : function( snapshot )\r
571                 {\r
572                         this.fire( 'loadSnapshot', snapshot );\r
573                 },\r
574 \r
575                 /**\r
576                  * Sets the editor data. The data must be provided in raw format.\r
577                  * @param {String} data HTML code to replace the curent content in the editor.\r
578                  * @param {Function} callback Function to be called after the setData is completed.\r
579                  * @example\r
580                  * CKEDITOR.instances.editor1.<b>setData( '&lt;p&gt;This is the editor data.&lt;/p&gt;' )</b>;\r
581                  * CKEDITOR.instances.editor1.setData( '&lt;p&gt;Some other editor data.&lt;/p&gt;', function()\r
582                  * {\r
583                  *              CKEDITOR.instances.editor1.checkDirty();        // true\r
584                  * } );\r
585                  */\r
586                 setData : function( data , callback )\r
587                 {\r
588                         if( callback )\r
589                         {\r
590                                 this.on( 'dataReady', function( evt )\r
591                                 {\r
592                                         evt.removeListener();\r
593                                         callback.call( evt.editor );\r
594                                 } );\r
595                         }\r
596                         // Fire "setData" so data manipulation may happen.\r
597                         var eventData = { dataValue : data };\r
598                         this.fire( 'setData', eventData );\r
599 \r
600                         this._.data = eventData.dataValue;\r
601 \r
602                         this.fire( 'afterSetData', eventData );\r
603                 },\r
604 \r
605                 /**\r
606                  * Inserts HTML into the currently selected position in the editor.\r
607                  * @param {String} data HTML code to be inserted into the editor.\r
608                  * @example\r
609                  * CKEDITOR.instances.editor1.<b>insertHtml( '&lt;p&gt;This is a new paragraph.&lt;/p&gt;' )</b>;\r
610                  */\r
611                 insertHtml : function( data )\r
612                 {\r
613                         this.fire( 'insertHtml', data );\r
614                 },\r
615 \r
616                 /**\r
617                  * Inserts an element into the currently selected position in the\r
618                  * editor.\r
619                  * @param {CKEDITOR.dom.element} element The element to be inserted\r
620                  *              into the editor.\r
621                  * @example\r
622                  * var element = CKEDITOR.dom.element.createFromHtml( '&lt;img src="hello.png" border="0" title="Hello" /&gt;' );\r
623                  * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;\r
624                  */\r
625                 insertElement : function( element )\r
626                 {\r
627                         this.fire( 'insertElement', element );\r
628                 },\r
629 \r
630                 checkDirty : function()\r
631                 {\r
632                         return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );\r
633                 },\r
634 \r
635                 resetDirty : function()\r
636                 {\r
637                         if ( this.mayBeDirty )\r
638                                 this._.previousValue = this.getSnapshot();\r
639                 },\r
640 \r
641                 /**\r
642                  * Updates the &lt;textarea&gt; element that has been replaced by the editor with\r
643                  * the current data available in the editor.\r
644                  * @example\r
645                  * CKEDITOR.instances.editor1.updateElement();\r
646                  * alert( document.getElementById( 'editor1' ).value );  // The current editor data.\r
647                  */\r
648                 updateElement : function()\r
649                 {\r
650                         var element = this.element;\r
651                         if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
652                         {\r
653                                 if ( element.is( 'textarea' ) )\r
654                                         element.setValue( this.getData() );\r
655                                 else\r
656                                         element.setHtml( this.getData() );\r
657                         }\r
658                 }\r
659         });\r
660 \r
661 CKEDITOR.on( 'loaded', function()\r
662         {\r
663                 // Run the full initialization for pending editors.\r
664                 var pending = CKEDITOR.editor._pending;\r
665                 if ( pending )\r
666                 {\r
667                         delete CKEDITOR.editor._pending;\r
668 \r
669                         for ( var i = 0 ; i < pending.length ; i++ )\r
670                                 pending[ i ]._init();\r
671                 }\r
672         });\r