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