2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview Defines the {@link CKEDITOR.editor} class, which represents an
\r
13 // The counter for automatic instance names.
\r
14 var nameCounter = 0;
\r
16 var getNewName = function()
\r
18 var name = 'editor' + ( ++nameCounter );
\r
19 return ( CKEDITOR.instances && CKEDITOR.instances[ name ] ) ? getNewName() : name;
\r
22 // ##### START: Config Privates
\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
30 var customConfig = editor.config.customConfig;
\r
32 // Check if there is a custom config to load.
\r
33 if ( !customConfig )
\r
36 customConfig = CKEDITOR.getUrl( customConfig );
\r
38 var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = {} );
\r
40 // If the custom config has already been downloaded, reuse it.
\r
41 if ( loadedConfig.fn )
\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
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
54 // Load the custom configuration file.
\r
55 CKEDITOR.scriptLoader.load( customConfig, function()
\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
62 loadedConfig.fn = function(){};
\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
73 var initConfig = function( editor, instanceConfig )
\r
75 // Setup the lister for the "customConfigLoaded" event.
\r
76 editor.on( 'customConfigLoaded', function()
\r
78 if ( instanceConfig )
\r
80 // Register the events that may have been set at the instance
\r
81 // configuration object.
\r
82 if ( instanceConfig.on )
\r
84 for ( var eventName in instanceConfig.on )
\r
86 editor.on( eventName, instanceConfig.on[ eventName ] );
\r
90 // Overwrite the settings from the in-page config.
\r
91 CKEDITOR.tools.extend( editor.config, instanceConfig, true );
\r
93 delete editor.config.on;
\r
96 onConfigLoaded( editor );
\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
104 // Load configs from the custom configuration files.
\r
105 if ( !loadConfig( editor ) )
\r
106 editor.fireOnce( 'customConfigLoaded' );
\r
109 // ##### END: Config Privates
\r
111 var onConfigLoaded = function( editor )
\r
113 // Set config related properties.
\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
122 * The name of the skin used by this editor instance. The skin name can
\r
123 * be set though the {@link CKEDITOR.config.skin} setting.
\r
124 * @name CKEDITOR.editor.prototype.skinName
\r
127 * alert( editor.skinName ); // "kama" (e.g.)
\r
129 editor.skinName = skinName;
\r
132 * The full URL of the skin directory.
\r
133 * @name CKEDITOR.editor.prototype.skinPath
\r
136 * alert( editor.skinPath ); // "http://example.com/ckeditor/skins/kama/" (e.g.)
\r
138 editor.skinPath = skinPath;
\r
141 * The CSS class name used for skin identification purposes.
\r
142 * @name CKEDITOR.editor.prototype.skinClass
\r
145 * alert( editor.skinClass ); // "cke_skin_kama" (e.g.)
\r
147 editor.skinClass = 'cke_skin_' + skinName;
\r
150 * The <a href="http://en.wikipedia.org/wiki/Tabbing_navigation">tabbing
\r
151 * navigation</a> order that has been calculated for this editor
\r
152 * instance. This can be set by the {@link CKEDITOR.config.tabIndex}
\r
153 * setting or taken from the "tabindex" attribute of the
\r
154 * {@link #element} associated to the editor.
\r
155 * @name CKEDITOR.editor.prototype.tabIndex
\r
157 * @default 0 (zero)
\r
159 * alert( editor.tabIndex ); // "0" (e.g.)
\r
161 editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
\r
163 // Fire the "configLoaded" event.
\r
164 editor.fireOnce( 'configLoaded' );
\r
166 // Load language file.
\r
167 loadSkin( editor );
\r
170 var loadLang = function( editor )
\r
172 CKEDITOR.lang.load( editor.config.language, editor.config.defaultLanguage, function( languageCode, lang )
\r
175 * The code for the language resources that have been loaded
\r
176 * for the user internface elements of this editor instance.
\r
177 * @name CKEDITOR.editor.prototype.langCode
\r
180 * alert( editor.langCode ); // "en" (e.g.)
\r
182 editor.langCode = languageCode;
\r
185 * An object holding all language strings used by the editor
\r
187 * @name CKEDITOR.editor.prototype.lang
\r
188 * @type CKEDITOR.lang
\r
190 * alert( editor.lang.bold ); // "Negrito" (e.g. if language is Portuguese)
\r
192 // As we'll be adding plugin specific entries that could come
\r
193 // from different language code files, we need a copy of lang,
\r
194 // not a direct reference to it.
\r
195 editor.lang = CKEDITOR.tools.prototypedCopy( lang );
\r
197 // We're not able to support RTL in Firefox 2 at this time.
\r
198 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 && editor.lang.dir == 'rtl' )
\r
199 editor.lang.dir = 'ltr';
\r
201 var config = editor.config;
\r
202 config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );
\r
204 loadPlugins( editor );
\r
208 var loadPlugins = function( editor )
\r
210 var config = editor.config,
\r
211 plugins = config.plugins,
\r
212 extraPlugins = config.extraPlugins,
\r
213 removePlugins = config.removePlugins;
\r
215 if ( extraPlugins )
\r
217 // Remove them first to avoid duplications.
\r
218 var removeRegex = new RegExp( '(?:^|,)(?:' + extraPlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
219 plugins = plugins.replace( removeRegex, '' );
\r
221 plugins += ',' + extraPlugins;
\r
224 if ( removePlugins )
\r
226 removeRegex = new RegExp( '(?:^|,)(?:' + removePlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
227 plugins = plugins.replace( removeRegex, '' );
\r
230 // Load all plugins defined in the "plugins" setting.
\r
231 CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )
\r
233 // The list of plugins.
\r
234 var pluginsArray = [];
\r
236 // The language code to get loaded for each plugin. Null
\r
237 // entries will be appended for plugins with no language files.
\r
238 var languageCodes = [];
\r
240 // The list of URLs to language files.
\r
241 var languageFiles = [];
\r
244 * And object holding references to all plugins used by this
\r
246 * @name CKEDITOR.editor.prototype.plugins
\r
249 * alert( editor.plugins.dialog.path ); // "http://example.com/ckeditor/plugins/dialog/" (e.g.)
\r
251 editor.plugins = plugins;
\r
253 // Loop through all plugins, to build the list of language
\r
254 // files to get loaded.
\r
255 for ( var pluginName in plugins )
\r
257 var plugin = plugins[ pluginName ],
\r
258 pluginLangs = plugin.lang,
\r
259 pluginPath = CKEDITOR.plugins.getPath( pluginName ),
\r
262 // Set the plugin path in the plugin.
\r
263 plugin.path = pluginPath;
\r
265 // If the plugin has "lang".
\r
268 // Resolve the plugin language. If the current language
\r
269 // is not available, get the first one (default one).
\r
270 lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );
\r
272 if ( !plugin.lang[ lang ] )
\r
274 // Put the language file URL into the list of files to
\r
276 languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );
\r
280 CKEDITOR.tools.extend( editor.lang, plugin.lang[ lang ] );
\r
285 // Save the language code, so we know later which
\r
286 // language has been resolved to this plugin.
\r
287 languageCodes.push( lang );
\r
289 pluginsArray.push( plugin );
\r
292 // Load all plugin specific language files in a row.
\r
293 CKEDITOR.scriptLoader.load( languageFiles, function()
\r
295 // Initialize all plugins that have the "beforeInit" and "init" methods defined.
\r
296 var methods = [ 'beforeInit', 'init', 'afterInit' ];
\r
297 for ( var m = 0 ; m < methods.length ; m++ )
\r
299 for ( var i = 0 ; i < pluginsArray.length ; i++ )
\r
301 var plugin = pluginsArray[ i ];
\r
303 // Uses the first loop to update the language entries also.
\r
304 if ( m === 0 && languageCodes[ i ] && plugin.lang )
\r
305 CKEDITOR.tools.extend( editor.lang, plugin.lang[ languageCodes[ i ] ] );
\r
307 // Call the plugin method (beforeInit and init).
\r
308 if ( plugin[ methods[ m ] ] )
\r
309 plugin[ methods[ m ] ]( editor );
\r
313 // Load the editor skin.
\r
314 editor.fire( 'pluginsLoaded' );
\r
315 loadTheme( editor );
\r
320 var loadSkin = function( editor )
\r
322 CKEDITOR.skins.load( editor, 'editor', function()
\r
324 loadLang( editor );
\r
328 var loadTheme = function( editor )
\r
330 var theme = editor.config.theme;
\r
331 CKEDITOR.themes.load( theme, function()
\r
334 * The theme used by this editor instance.
\r
335 * @name CKEDITOR.editor.prototype.theme
\r
336 * @type CKEDITOR.theme
\r
338 * alert( editor.theme ); "http://example.com/ckeditor/themes/default/" (e.g.)
\r
340 var editorTheme = editor.theme = CKEDITOR.themes.get( theme );
\r
341 editorTheme.path = CKEDITOR.themes.getPath( theme );
\r
342 editorTheme.build( editor );
\r
344 if ( editor.config.autoUpdateElement )
\r
345 attachToForm( editor );
\r
349 var attachToForm = function( editor )
\r
351 var element = editor.element;
\r
353 // If are replacing a textarea, we must
\r
354 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )
\r
356 var form = element.$.form && new CKEDITOR.dom.element( element.$.form );
\r
359 function onSubmit()
\r
361 editor.updateElement();
\r
363 form.on( 'submit',onSubmit );
\r
365 // Setup the submit function because it doesn't fire the
\r
367 if ( !form.$.submit.nodeName )
\r
369 form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )
\r
373 editor.updateElement();
\r
375 // For IE, the DOM submit function is not a
\r
376 // function, so we need thid check.
\r
377 if ( originalSubmit.apply )
\r
378 originalSubmit.apply( this, arguments );
\r
385 // Remove 'submit' events registered on form element before destroying.(#3988)
\r
386 editor.on( 'destroy', function()
\r
388 form.removeListener( 'submit', onSubmit );
\r
394 function updateCommandsMode()
\r
397 commands = this._.commands,
\r
400 for ( var name in commands )
\r
402 command = commands[ name ];
\r
403 command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
\r
408 * Initializes the editor instance. This function is called by the editor
\r
409 * contructor (editor_basic.js).
\r
412 CKEDITOR.editor.prototype._init = function()
\r
414 // Get the properties that have been saved in the editor_base
\r
416 var element = CKEDITOR.dom.element.get( this._.element ),
\r
417 instanceConfig = this._.instanceConfig;
\r
418 delete this._.element;
\r
419 delete this._.instanceConfig;
\r
421 this._.commands = {};
\r
422 this._.styles = [];
\r
425 * The DOM element that has been replaced by this editor instance. This
\r
426 * element holds the editor data on load and post.
\r
427 * @name CKEDITOR.editor.prototype.element
\r
428 * @type CKEDITOR.dom.element
\r
430 * var editor = CKEDITOR.instances.editor1;
\r
431 * alert( <b>editor.element</b>.getName() ); "textarea"
\r
433 this.element = element;
\r
436 * The editor instance name. It hay be the replaced element id, name or
\r
437 * a default name using a progressive counter (editor1, editor2, ...).
\r
438 * @name CKEDITOR.editor.prototype.name
\r
441 * var editor = CKEDITOR.instances.editor1;
\r
442 * alert( <b>editor.name</b> ); "editor1"
\r
444 this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
445 && ( element.getId() || element.getNameAtt() ) )
\r
448 if ( this.name in CKEDITOR.instances )
\r
449 throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';
\r
452 * A unique random string assigned to each editor instance in the page.
\r
453 * @name CKEDITOR.editor.prototype.id
\r
456 this.id = CKEDITOR.tools.getNextId();
\r
459 * The configurations for this editor instance. It inherits all
\r
460 * settings defined in (@link CKEDITOR.config}, combined with settings
\r
461 * loaded from custom configuration files and those defined inline in
\r
462 * the page when creating the editor.
\r
463 * @name CKEDITOR.editor.prototype.config
\r
466 * var editor = CKEDITOR.instances.editor1;
\r
467 * alert( <b>editor.config.theme</b> ); "default" e.g.
\r
469 this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );
\r
472 * Namespace containing UI features related to this editor instance.
\r
473 * @name CKEDITOR.editor.prototype.ui
\r
474 * @type CKEDITOR.ui
\r
477 this.ui = new CKEDITOR.ui( this );
\r
480 * Controls the focus state of this editor instance. This property
\r
481 * is rarely used for normal API operations. It is mainly
\r
482 * destinated to developer adding UI elements to the editor interface.
\r
483 * @name CKEDITOR.editor.prototype.focusManager
\r
484 * @type CKEDITOR.focusManager
\r
487 this.focusManager = new CKEDITOR.focusManager( this );
\r
489 CKEDITOR.fire( 'instanceCreated', null, this );
\r
491 this.on( 'mode', updateCommandsMode, null, null, 1 );
\r
493 initConfig( this, instanceConfig );
\r
497 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
498 /** @lends CKEDITOR.editor.prototype */
\r
501 * Adds a command definition to the editor instance. Commands added with
\r
502 * this function can be later executed with {@link #execCommand}.
\r
503 * @param {String} commandName The indentifier name of the command.
\r
504 * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.
\r
506 * editorInstance.addCommand( 'sample',
\r
508 * exec : function( editor )
\r
510 * alert( 'Executing a command for the editor name "' + editor.name + '"!' );
\r
514 addCommand : function( commandName, commandDefinition )
\r
516 return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );
\r
520 * Add a trunk of css text to the editor which will be applied to the wysiwyg editing document.
\r
521 * Note: This function should be called before editor is loaded to take effect.
\r
522 * @param css {String} CSS text.
\r
524 * editorInstance.addCss( 'body { background-color: grey; }' );
\r
526 addCss : function( css )
\r
528 this._.styles.push( css );
\r
532 * Destroys the editor instance, releasing all resources used by it.
\r
533 * If the editor replaced an element, the element will be recovered.
\r
534 * @param {Boolean} [noUpdate] If the instance is replacing a DOM
\r
535 * element, this parameter indicates whether or not to update the
\r
536 * element with the instance contents.
\r
538 * alert( CKEDITOR.instances.editor1 ); e.g "object"
\r
539 * <b>CKEDITOR.instances.editor1.destroy()</b>;
\r
540 * alert( CKEDITOR.instances.editor1 ); "undefined"
\r
542 destroy : function( noUpdate )
\r
545 this.updateElement();
\r
549 // -> currentMode.unload( holderElement );
\r
550 this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );
\r
553 this.theme.destroy( this );
\r
561 if ( this.toolbox )
\r
563 toolbars = this.toolbox.toolbars;
\r
564 for ( ; index < toolbars.length ; index++ )
\r
566 items = toolbars[ index ].items;
\r
567 for ( j = 0 ; j < items.length ; j++ )
\r
569 instance = items[ j ];
\r
570 if ( instance.clickFn ) CKEDITOR.tools.removeFunction( instance.clickFn );
\r
571 if ( instance.keyDownFn ) CKEDITOR.tools.removeFunction( instance.keyDownFn );
\r
573 if ( instance.index ) CKEDITOR.ui.button._.instances[ instance.index ] = null;
\r
578 if ( this.contextMenu )
\r
579 CKEDITOR.tools.removeFunction( this.contextMenu._.functionId );
\r
581 if ( this._.filebrowserFn )
\r
582 CKEDITOR.tools.removeFunction( this._.filebrowserFn );
\r
584 this.fire( 'destroy' );
\r
585 CKEDITOR.remove( this );
\r
586 CKEDITOR.fire( 'instanceDestroyed', null, this );
\r
590 * Executes a command.
\r
591 * @param {String} commandName The indentifier name of the command.
\r
592 * @param {Object} [data] Data to be passed to the command
\r
593 * @returns {Boolean} "true" if the command has been successfuly
\r
594 * executed, otherwise "false".
\r
596 * editorInstance.execCommand( 'Bold' );
\r
598 execCommand : function( commandName, data )
\r
600 var command = this.getCommand( commandName );
\r
609 if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )
\r
611 if ( this.fire( 'beforeCommandExec', eventData ) !== true )
\r
613 eventData.returnValue = command.exec( eventData.commandData );
\r
615 // Fire the 'afterCommandExec' immediately if command is synchronous.
\r
616 if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )
\r
617 return eventData.returnValue;
\r
621 // throw 'Unknown command name "' + commandName + '"';
\r
626 * Gets one of the registered commands. Note that, after registering a
\r
627 * command definition with addCommand, it is transformed internally
\r
628 * into an instance of {@link CKEDITOR.command}, which will be then
\r
629 * returned by this function.
\r
630 * @param {String} commandName The name of the command to be returned.
\r
631 * This is the same used to register the command with addCommand.
\r
632 * @returns {CKEDITOR.command} The command object identified by the
\r
635 getCommand : function( commandName )
\r
637 return this._.commands[ commandName ];
\r
641 * Gets the editor data. The data will be in raw format. It is the same
\r
642 * data that is posted by the editor.
\r
644 * @returns (String) The editor data.
\r
646 * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )
\r
647 * alert( 'There is no data available' );
\r
649 getData : function()
\r
651 this.fire( 'beforeGetData' );
\r
653 var eventData = this._.data;
\r
655 if ( typeof eventData != 'string' )
\r
657 var element = this.element;
\r
658 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
659 eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
664 eventData = { dataValue : eventData };
\r
666 // Fire "getData" so data manipulation may happen.
\r
667 this.fire( 'getData', eventData );
\r
669 return eventData.dataValue;
\r
673 * Gets the "raw data" currently available in the editor. This is a
\r
674 * fast method which return the data as is, without processing, so it's
\r
675 * not recommended to use it on resulting pages. It can be used instead
\r
676 * combined with the {@link #loadSnapshot} so one can automatic save
\r
677 * the editor data from time to time while the user is using the
\r
678 * editor, to avoid data loss, without risking performance issues.
\r
680 * alert( editor.getSnapshot() );
\r
682 getSnapshot : function()
\r
684 var data = this.fire( 'getSnapshot' );
\r
686 if ( typeof data != 'string' )
\r
688 var element = this.element;
\r
689 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
690 data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
697 * Loads "raw data" in the editor. This data is loaded with processing
\r
698 * straight to the editing area. It should not be used as a way to load
\r
699 * any kind of data, but instead in combination with
\r
700 * {@link #getSnapshot} produced data.
\r
702 * var data = editor.getSnapshot();
\r
703 * editor.<b>loadSnapshot( data )</b>;
\r
705 loadSnapshot : function( snapshot )
\r
707 this.fire( 'loadSnapshot', snapshot );
\r
711 * Sets the editor data. The data must be provided in raw format (HTML).<br />
\r
713 * Note that this menthod is asynchronous. The "callback" parameter must
\r
714 * be used if interaction with the editor is needed after setting the data.
\r
715 * @param {String} data HTML code to replace the curent content in the
\r
717 * @param {Function} callback Function to be called after the setData
\r
720 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>This is the editor data.</p>' );
\r
722 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>Some other editor data.</p>', function()
\r
724 * this.checkDirty(); // true
\r
727 setData : function( data , callback )
\r
731 this.on( 'dataReady', function( evt )
\r
733 evt.removeListener();
\r
734 callback.call( evt.editor );
\r
738 // Fire "setData" so data manipulation may happen.
\r
739 var eventData = { dataValue : data };
\r
740 this.fire( 'setData', eventData );
\r
742 this._.data = eventData.dataValue;
\r
744 this.fire( 'afterSetData', eventData );
\r
748 * Inserts HTML into the currently selected position in the editor.
\r
749 * @param {String} data HTML code to be inserted into the editor.
\r
751 * CKEDITOR.instances.editor1.<b>insertHtml( '<p>This is a new paragraph.</p>' )</b>;
\r
753 insertHtml : function( data )
\r
755 this.fire( 'insertHtml', data );
\r
759 * Inserts an element into the currently selected position in the
\r
761 * @param {CKEDITOR.dom.element} element The element to be inserted
\r
764 * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
\r
765 * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;
\r
767 insertElement : function( element )
\r
769 this.fire( 'insertElement', element );
\r
773 * Checks whether the current editor contents present changes when
\r
774 * compared to the contents loaded into the editor at startup, or to
\r
775 * the contents available in the editor when {@link #resetDirty} has
\r
777 * @returns {Boolean} "true" is the contents present changes.
\r
779 * function beforeUnload( e )
\r
781 * if ( CKEDITOR.instances.editor1.<b>checkDirty()</b> )
\r
782 * return e.returnValue = "You'll loose the changes made in the editor.";
\r
785 * if ( window.addEventListener )
\r
786 * window.addEventListener( 'beforeunload', beforeUnload, false );
\r
788 * window.attachEvent( 'onbeforeunload', beforeUnload );
\r
790 checkDirty : function()
\r
792 return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );
\r
796 * Resets the "dirty state" of the editor so subsequent calls to
\r
797 * {@link #checkDirty} will return "false" if the user will not make
\r
798 * further changes to the contents.
\r
800 * alert( editor.checkDirty() ); // "true" (e.g.)
\r
801 * editor.<b>resetDirty()</b>;
\r
802 * alert( editor.checkDirty() ); // "false"
\r
804 resetDirty : function()
\r
806 if ( this.mayBeDirty )
\r
807 this._.previousValue = this.getSnapshot();
\r
811 * Updates the <textarea> element that has been replaced by the editor with
\r
812 * the current data available in the editor.
\r
814 * CKEDITOR.instances.editor1.updateElement();
\r
815 * alert( document.getElementById( 'editor1' ).value ); // The current editor data.
\r
817 updateElement : function()
\r
819 var element = this.element;
\r
820 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
822 var data = this.getData();
\r
824 if ( this.config.htmlEncodeOutput )
\r
825 data = CKEDITOR.tools.htmlEncode( data );
\r
827 if ( element.is( 'textarea' ) )
\r
828 element.setValue( data );
\r
830 element.setHtml( data );
\r
835 CKEDITOR.on( 'loaded', function()
\r
837 // Run the full initialization for pending editors.
\r
838 var pending = CKEDITOR.editor._pending;
\r
841 delete CKEDITOR.editor._pending;
\r
843 for ( var i = 0 ; i < pending.length ; i++ )
\r
844 pending[ i ]._init();
\r
849 * Whether escape HTML when editor update original input element.
\r
850 * @name CKEDITOR.config.htmlEncodeOutput
\r
855 * config.htmlEncodeOutput = true;
\r
859 * Fired when a CKEDITOR instance is created, but still before initializing it.
\r
860 * To interact with a fully initialized instance, use the
\r
861 * {@link CKEDITOR#instanceReady} event instead.
\r
862 * @name CKEDITOR#instanceCreated
\r
864 * @param {CKEDITOR.editor} editor The editor instance that has been created.
\r
868 * Fired when a CKEDITOR instance is destroyed.
\r
869 * @name CKEDITOR#instanceDestroyed
\r
871 * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.
\r
875 * Fired when all plugins are loaded and initialized into the editor instance.
\r
876 * @name CKEDITOR#pluginsLoaded
\r
878 * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.
\r
882 * Fired before the command execution when {@link #execCommand} is called.
\r
883 * @name CKEDITOR.editor#beforeCommandExec
\r
885 * @param {CKEDITOR.editor} editor This editor instance.
\r
886 * @param {String} data.name The command name.
\r
887 * @param {Object} data.commandData The data to be sent to the command. This
\r
888 * can be manipulated by the event listener.
\r
889 * @param {CKEDITOR.command} data.command The command itself.
\r
893 * Fired after the command execution when {@link #execCommand} is called.
\r
894 * @name CKEDITOR.editor#afterCommandExec
\r
896 * @param {CKEDITOR.editor} editor This editor instance.
\r
897 * @param {String} data.name The command name.
\r
898 * @param {Object} data.commandData The data sent to the command.
\r
899 * @param {CKEDITOR.command} data.command The command itself.
\r
900 * @param {Object} data.returnValue The value returned by the command execution.
\r
904 * Fired every custom configuration file is loaded, before the final
\r
905 * configurations initialization.<br />
\r
907 * Custom configuration files can be loaded thorugh the
\r
908 * {@link CKEDITOR.config.customConfig} setting. Several files can be loading
\r
909 * by chaning this setting.
\r
910 * @name CKEDITOR.editor#customConfigLoaded
\r
912 * @param {CKEDITOR.editor} editor This editor instance.
\r
917 * Fired once the editor configuration is ready (loaded and processed).
\r
918 * @name CKEDITOR.editor#configLoaded
\r
920 * @param {CKEDITOR.editor} editor This editor instance.
\r
922 * if( editor.config.fullPage )
\r
923 * alert( 'This is a full page editor' );
\r