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