2 Copyright (c) 2003-2011, 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 the Adobe AIR plugin conditionally.
\r
231 CKEDITOR.env.air && ( plugins += ',adobeair' );
\r
233 // Load all plugins defined in the "plugins" setting.
\r
234 CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )
\r
236 // The list of plugins.
\r
237 var pluginsArray = [];
\r
239 // The language code to get loaded for each plugin. Null
\r
240 // entries will be appended for plugins with no language files.
\r
241 var languageCodes = [];
\r
243 // The list of URLs to language files.
\r
244 var languageFiles = [];
\r
247 * And object holding references to all plugins used by this
\r
249 * @name CKEDITOR.editor.prototype.plugins
\r
252 * alert( editor.plugins.dialog.path ); // "http://example.com/ckeditor/plugins/dialog/" (e.g.)
\r
254 editor.plugins = plugins;
\r
256 // Loop through all plugins, to build the list of language
\r
257 // files to get loaded.
\r
258 for ( var pluginName in plugins )
\r
260 var plugin = plugins[ pluginName ],
\r
261 pluginLangs = plugin.lang,
\r
262 pluginPath = CKEDITOR.plugins.getPath( pluginName ),
\r
265 // Set the plugin path in the plugin.
\r
266 plugin.path = pluginPath;
\r
268 // If the plugin has "lang".
\r
271 // Resolve the plugin language. If the current language
\r
272 // is not available, get the first one (default one).
\r
273 lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );
\r
275 if ( !plugin.langEntries || !plugin.langEntries[ lang ] )
\r
277 // Put the language file URL into the list of files to
\r
279 languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );
\r
283 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );
\r
288 // Save the language code, so we know later which
\r
289 // language has been resolved to this plugin.
\r
290 languageCodes.push( lang );
\r
292 pluginsArray.push( plugin );
\r
295 // Load all plugin specific language files in a row.
\r
296 CKEDITOR.scriptLoader.load( languageFiles, function()
\r
298 // Initialize all plugins that have the "beforeInit" and "init" methods defined.
\r
299 var methods = [ 'beforeInit', 'init', 'afterInit' ];
\r
300 for ( var m = 0 ; m < methods.length ; m++ )
\r
302 for ( var i = 0 ; i < pluginsArray.length ; i++ )
\r
304 var plugin = pluginsArray[ i ];
\r
306 // Uses the first loop to update the language entries also.
\r
307 if ( m === 0 && languageCodes[ i ] && plugin.lang )
\r
308 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ languageCodes[ i ] ] );
\r
310 // Call the plugin method (beforeInit and init).
\r
311 if ( plugin[ methods[ m ] ] )
\r
312 plugin[ methods[ m ] ]( editor );
\r
316 // Load the editor skin.
\r
317 editor.fire( 'pluginsLoaded' );
\r
318 loadTheme( editor );
\r
323 var loadSkin = function( editor )
\r
325 CKEDITOR.skins.load( editor, 'editor', function()
\r
327 loadLang( editor );
\r
331 var loadTheme = function( editor )
\r
333 var theme = editor.config.theme;
\r
334 CKEDITOR.themes.load( theme, function()
\r
337 * The theme used by this editor instance.
\r
338 * @name CKEDITOR.editor.prototype.theme
\r
339 * @type CKEDITOR.theme
\r
341 * alert( editor.theme ); "http://example.com/ckeditor/themes/default/" (e.g.)
\r
343 var editorTheme = editor.theme = CKEDITOR.themes.get( theme );
\r
344 editorTheme.path = CKEDITOR.themes.getPath( theme );
\r
345 editorTheme.build( editor );
\r
347 if ( editor.config.autoUpdateElement )
\r
348 attachToForm( editor );
\r
352 var attachToForm = function( editor )
\r
354 var element = editor.element;
\r
356 // If are replacing a textarea, we must
\r
357 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )
\r
359 var form = element.$.form && new CKEDITOR.dom.element( element.$.form );
\r
362 function onSubmit()
\r
364 editor.updateElement();
\r
366 form.on( 'submit',onSubmit );
\r
368 // Setup the submit function because it doesn't fire the
\r
370 if ( !form.$.submit.nodeName && !form.$.submit.length )
\r
372 form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )
\r
376 editor.updateElement();
\r
378 // For IE, the DOM submit function is not a
\r
379 // function, so we need thid check.
\r
380 if ( originalSubmit.apply )
\r
381 originalSubmit.apply( this, arguments );
\r
388 // Remove 'submit' events registered on form element before destroying.(#3988)
\r
389 editor.on( 'destroy', function()
\r
391 form.removeListener( 'submit', onSubmit );
\r
397 function updateCommandsMode()
\r
400 commands = this._.commands,
\r
403 for ( var name in commands )
\r
405 command = commands[ name ];
\r
406 command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
\r
411 * Initializes the editor instance. This function is called by the editor
\r
412 * contructor (editor_basic.js).
\r
415 CKEDITOR.editor.prototype._init = function()
\r
417 // Get the properties that have been saved in the editor_base
\r
419 var element = CKEDITOR.dom.element.get( this._.element ),
\r
420 instanceConfig = this._.instanceConfig;
\r
421 delete this._.element;
\r
422 delete this._.instanceConfig;
\r
424 this._.commands = {};
\r
425 this._.styles = [];
\r
428 * The DOM element that has been replaced by this editor instance. This
\r
429 * element holds the editor data on load and post.
\r
430 * @name CKEDITOR.editor.prototype.element
\r
431 * @type CKEDITOR.dom.element
\r
433 * var editor = CKEDITOR.instances.editor1;
\r
434 * alert( <b>editor.element</b>.getName() ); "textarea"
\r
436 this.element = element;
\r
439 * The editor instance name. It hay be the replaced element id, name or
\r
440 * a default name using a progressive counter (editor1, editor2, ...).
\r
441 * @name CKEDITOR.editor.prototype.name
\r
444 * var editor = CKEDITOR.instances.editor1;
\r
445 * alert( <b>editor.name</b> ); "editor1"
\r
447 this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
448 && ( element.getId() || element.getNameAtt() ) )
\r
451 if ( this.name in CKEDITOR.instances )
\r
452 throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';
\r
455 * A unique random string assigned to each editor instance in the page.
\r
456 * @name CKEDITOR.editor.prototype.id
\r
459 this.id = CKEDITOR.tools.getNextId();
\r
462 * The configurations for this editor instance. It inherits all
\r
463 * settings defined in (@link CKEDITOR.config}, combined with settings
\r
464 * loaded from custom configuration files and those defined inline in
\r
465 * the page when creating the editor.
\r
466 * @name CKEDITOR.editor.prototype.config
\r
469 * var editor = CKEDITOR.instances.editor1;
\r
470 * alert( <b>editor.config.theme</b> ); "default" e.g.
\r
472 this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );
\r
475 * Namespace containing UI features related to this editor instance.
\r
476 * @name CKEDITOR.editor.prototype.ui
\r
477 * @type CKEDITOR.ui
\r
480 this.ui = new CKEDITOR.ui( this );
\r
483 * Controls the focus state of this editor instance. This property
\r
484 * is rarely used for normal API operations. It is mainly
\r
485 * destinated to developer adding UI elements to the editor interface.
\r
486 * @name CKEDITOR.editor.prototype.focusManager
\r
487 * @type CKEDITOR.focusManager
\r
490 this.focusManager = new CKEDITOR.focusManager( this );
\r
492 CKEDITOR.fire( 'instanceCreated', null, this );
\r
494 this.on( 'mode', updateCommandsMode, null, null, 1 );
\r
496 initConfig( this, instanceConfig );
\r
500 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
501 /** @lends CKEDITOR.editor.prototype */
\r
504 * Adds a command definition to the editor instance. Commands added with
\r
505 * this function can be later executed with {@link #execCommand}.
\r
506 * @param {String} commandName The indentifier name of the command.
\r
507 * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.
\r
509 * editorInstance.addCommand( 'sample',
\r
511 * exec : function( editor )
\r
513 * alert( 'Executing a command for the editor name "' + editor.name + '"!' );
\r
517 addCommand : function( commandName, commandDefinition )
\r
519 return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );
\r
523 * Add a trunk of css text to the editor which will be applied to the wysiwyg editing document.
\r
524 * Note: This function should be called before editor is loaded to take effect.
\r
525 * @param css {String} CSS text.
\r
527 * editorInstance.addCss( 'body { background-color: grey; }' );
\r
529 addCss : function( css )
\r
531 this._.styles.push( css );
\r
535 * Destroys the editor instance, releasing all resources used by it.
\r
536 * If the editor replaced an element, the element will be recovered.
\r
537 * @param {Boolean} [noUpdate] If the instance is replacing a DOM
\r
538 * element, this parameter indicates whether or not to update the
\r
539 * element with the instance contents.
\r
541 * alert( CKEDITOR.instances.editor1 ); e.g "object"
\r
542 * <b>CKEDITOR.instances.editor1.destroy()</b>;
\r
543 * alert( CKEDITOR.instances.editor1 ); "undefined"
\r
545 destroy : function( noUpdate )
\r
548 this.updateElement();
\r
550 this.fire( 'destroy' );
\r
551 this.theme && this.theme.destroy( this );
\r
553 CKEDITOR.remove( this );
\r
554 CKEDITOR.fire( 'instanceDestroyed', null, this );
\r
558 * Executes a command.
\r
559 * @param {String} commandName The indentifier name of the command.
\r
560 * @param {Object} [data] Data to be passed to the command
\r
561 * @returns {Boolean} "true" if the command has been successfuly
\r
562 * executed, otherwise "false".
\r
564 * editorInstance.execCommand( 'bold' );
\r
566 execCommand : function( commandName, data )
\r
568 var command = this.getCommand( commandName );
\r
577 if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )
\r
579 if ( this.fire( 'beforeCommandExec', eventData ) !== true )
\r
581 eventData.returnValue = command.exec( eventData.commandData );
\r
583 // Fire the 'afterCommandExec' immediately if command is synchronous.
\r
584 if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )
\r
585 return eventData.returnValue;
\r
589 // throw 'Unknown command name "' + commandName + '"';
\r
594 * Gets one of the registered commands. Note that, after registering a
\r
595 * command definition with addCommand, it is transformed internally
\r
596 * into an instance of {@link CKEDITOR.command}, which will be then
\r
597 * returned by this function.
\r
598 * @param {String} commandName The name of the command to be returned.
\r
599 * This is the same used to register the command with addCommand.
\r
600 * @returns {CKEDITOR.command} The command object identified by the
\r
603 getCommand : function( commandName )
\r
605 return this._.commands[ commandName ];
\r
609 * Gets the editor data. The data will be in raw format. It is the same
\r
610 * data that is posted by the editor.
\r
612 * @returns (String) The editor data.
\r
614 * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )
\r
615 * alert( 'There is no data available' );
\r
617 getData : function()
\r
619 this.fire( 'beforeGetData' );
\r
621 var eventData = this._.data;
\r
623 if ( typeof eventData != 'string' )
\r
625 var element = this.element;
\r
626 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
627 eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
632 eventData = { dataValue : eventData };
\r
634 // Fire "getData" so data manipulation may happen.
\r
635 this.fire( 'getData', eventData );
\r
637 return eventData.dataValue;
\r
641 * Gets the "raw data" currently available in the editor. This is a
\r
642 * fast method which return the data as is, without processing, so it's
\r
643 * not recommended to use it on resulting pages. It can be used instead
\r
644 * combined with the {@link #loadSnapshot} so one can automatic save
\r
645 * the editor data from time to time while the user is using the
\r
646 * editor, to avoid data loss, without risking performance issues.
\r
648 * alert( editor.getSnapshot() );
\r
650 getSnapshot : function()
\r
652 var data = this.fire( 'getSnapshot' );
\r
654 if ( typeof data != 'string' )
\r
656 var element = this.element;
\r
657 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
658 data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
665 * Loads "raw data" in the editor. This data is loaded with processing
\r
666 * straight to the editing area. It should not be used as a way to load
\r
667 * any kind of data, but instead in combination with
\r
668 * {@link #getSnapshot} produced data.
\r
670 * var data = editor.getSnapshot();
\r
671 * editor.<b>loadSnapshot( data )</b>;
\r
673 loadSnapshot : function( snapshot )
\r
675 this.fire( 'loadSnapshot', snapshot );
\r
679 * Sets the editor data. The data must be provided in raw format (HTML).<br />
\r
681 * Note that this menthod is asynchronous. The "callback" parameter must
\r
682 * be used if interaction with the editor is needed after setting the data.
\r
683 * @param {String} data HTML code to replace the curent content in the
\r
685 * @param {Function} callback Function to be called after the setData
\r
687 *@param {Boolean} internal Whether suppress any event firing when copying data internally inside editor.
\r
689 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>This is the editor data.</p>' );
\r
691 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>Some other editor data.</p>', function()
\r
693 * this.checkDirty(); // true
\r
696 setData : function( data , callback, internal )
\r
700 this.on( 'dataReady', function( evt )
\r
702 evt.removeListener();
\r
703 callback.call( evt.editor );
\r
707 // Fire "setData" so data manipulation may happen.
\r
708 var eventData = { dataValue : data };
\r
709 !internal && this.fire( 'setData', eventData );
\r
711 this._.data = eventData.dataValue;
\r
713 !internal && this.fire( 'afterSetData', eventData );
\r
717 * Inserts HTML into the currently selected position in the editor.
\r
718 * @param {String} data HTML code to be inserted into the editor.
\r
720 * CKEDITOR.instances.editor1.<b>insertHtml( '<p>This is a new paragraph.</p>' )</b>;
\r
722 insertHtml : function( data )
\r
724 this.fire( 'insertHtml', data );
\r
728 * Insert text content into the currently selected position in the
\r
729 * editor, in WYSIWYG mode, styles of the selected element will be applied to the inserted text,
\r
730 * spaces around the text will be leaving untouched.
\r
731 * <strong>Note:</strong> two subsequent line-breaks will introduce one paragraph, which element depends on {@link CKEDITOR.config.enterMode};
\r
732 * A single line-break will be instead translated into one <br />.
\r
734 * @param {String} text Text to be inserted into the editor.
\r
736 * CKEDITOR.instances.editor1.<b>insertText( ' line1 \n\n line2' )</b>;
\r
738 insertText : function( text )
\r
740 this.fire( 'insertText', text );
\r
744 * Inserts an element into the currently selected position in the
\r
746 * @param {CKEDITOR.dom.element} element The element to be inserted
\r
749 * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
\r
750 * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;
\r
752 insertElement : function( element )
\r
754 this.fire( 'insertElement', element );
\r
758 * Checks whether the current editor contents present changes when
\r
759 * compared to the contents loaded into the editor at startup, or to
\r
760 * the contents available in the editor when {@link #resetDirty} has
\r
762 * @returns {Boolean} "true" is the contents present changes.
\r
764 * function beforeUnload( e )
\r
766 * if ( CKEDITOR.instances.editor1.<b>checkDirty()</b> )
\r
767 * return e.returnValue = "You'll loose the changes made in the editor.";
\r
770 * if ( window.addEventListener )
\r
771 * window.addEventListener( 'beforeunload', beforeUnload, false );
\r
773 * window.attachEvent( 'onbeforeunload', beforeUnload );
\r
775 checkDirty : function()
\r
777 return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );
\r
781 * Resets the "dirty state" of the editor so subsequent calls to
\r
782 * {@link #checkDirty} will return "false" if the user will not make
\r
783 * further changes to the contents.
\r
785 * alert( editor.checkDirty() ); // "true" (e.g.)
\r
786 * editor.<b>resetDirty()</b>;
\r
787 * alert( editor.checkDirty() ); // "false"
\r
789 resetDirty : function()
\r
791 if ( this.mayBeDirty )
\r
792 this._.previousValue = this.getSnapshot();
\r
796 * Updates the <textarea> element that has been replaced by the editor with
\r
797 * the current data available in the editor.
\r
799 * CKEDITOR.instances.editor1.updateElement();
\r
800 * alert( document.getElementById( 'editor1' ).value ); // The current editor data.
\r
802 updateElement : function()
\r
804 var element = this.element;
\r
805 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
807 var data = this.getData();
\r
809 if ( this.config.htmlEncodeOutput )
\r
810 data = CKEDITOR.tools.htmlEncode( data );
\r
812 if ( element.is( 'textarea' ) )
\r
813 element.setValue( data );
\r
815 element.setHtml( data );
\r
820 CKEDITOR.on( 'loaded', function()
\r
822 // Run the full initialization for pending editors.
\r
823 var pending = CKEDITOR.editor._pending;
\r
826 delete CKEDITOR.editor._pending;
\r
828 for ( var i = 0 ; i < pending.length ; i++ )
\r
829 pending[ i ]._init();
\r
834 * Whether escape HTML when editor update original input element.
\r
835 * @name CKEDITOR.config.htmlEncodeOutput
\r
840 * config.htmlEncodeOutput = true;
\r
844 * Fired when a CKEDITOR instance is created, but still before initializing it.
\r
845 * To interact with a fully initialized instance, use the
\r
846 * {@link CKEDITOR#instanceReady} event instead.
\r
847 * @name CKEDITOR#instanceCreated
\r
849 * @param {CKEDITOR.editor} editor The editor instance that has been created.
\r
853 * Fired when a CKEDITOR instance is destroyed.
\r
854 * @name CKEDITOR#instanceDestroyed
\r
856 * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.
\r
860 * Fired when all plugins are loaded and initialized into the editor instance.
\r
861 * @name CKEDITOR.editor#pluginsLoaded
\r
863 * @param {CKEDITOR.editor} editor This editor instance.
\r
867 * Fired before the command execution when {@link #execCommand} is called.
\r
868 * @name CKEDITOR.editor#beforeCommandExec
\r
870 * @param {CKEDITOR.editor} editor This editor instance.
\r
871 * @param {String} data.name The command name.
\r
872 * @param {Object} data.commandData The data to be sent to the command. This
\r
873 * can be manipulated by the event listener.
\r
874 * @param {CKEDITOR.command} data.command The command itself.
\r
878 * Fired after the command execution when {@link #execCommand} is called.
\r
879 * @name CKEDITOR.editor#afterCommandExec
\r
881 * @param {CKEDITOR.editor} editor This editor instance.
\r
882 * @param {String} data.name The command name.
\r
883 * @param {Object} data.commandData The data sent to the command.
\r
884 * @param {CKEDITOR.command} data.command The command itself.
\r
885 * @param {Object} data.returnValue The value returned by the command execution.
\r
889 * Fired every custom configuration file is loaded, before the final
\r
890 * configurations initialization.<br />
\r
892 * Custom configuration files can be loaded thorugh the
\r
893 * {@link CKEDITOR.config.customConfig} setting. Several files can be loading
\r
894 * by chaning this setting.
\r
895 * @name CKEDITOR.editor#customConfigLoaded
\r
897 * @param {CKEDITOR.editor} editor This editor instance.
\r
902 * Fired once the editor configuration is ready (loaded and processed).
\r
903 * @name CKEDITOR.editor#configLoaded
\r
905 * @param {CKEDITOR.editor} editor This editor instance.
\r
907 * if( editor.config.fullPage )
\r
908 * alert( 'This is a full page editor' );
\r
912 * Fired when this editor instance is destroyed. The editor at this
\r
913 * point isn't usable and this event should be used to perform clean up
\r
915 * @name CKEDITOR.editor#destroy
\r
920 * Internal event to get the current data.
\r
921 * @name CKEDITOR.editor#beforeGetData
\r
926 * Internal event to perform the #getSnapshot call.
\r
927 * @name CKEDITOR.editor#getSnapshot
\r
932 * Internal event to perform the #loadSnapshot call.
\r
933 * @name CKEDITOR.editor#loadSnapshot
\r
939 * Event fired before the #getData call returns allowing additional manipulation.
\r
940 * @name CKEDITOR.editor#getData
\r
942 * @param {CKEDITOR.editor} editor This editor instance.
\r
943 * @param {String} data.dataValue The data that will be returned.
\r
947 * Event fired before the #setData call is executed allowing additional manipulation.
\r
948 * @name CKEDITOR.editor#setData
\r
950 * @param {CKEDITOR.editor} editor This editor instance.
\r
951 * @param {String} data.dataValue The data that will be used.
\r
955 * Event fired at the end of the #setData call is executed. Usually it's better to use the
\r
956 * {@link CKEDITOR.editor.prototype.dataReady} event.
\r
957 * @name CKEDITOR.editor#afterSetData
\r
959 * @param {CKEDITOR.editor} editor This editor instance.
\r
960 * @param {String} data.dataValue The data that has been set.
\r
964 * Internal event to perform the #insertHtml call
\r
965 * @name CKEDITOR.editor#insertHtml
\r
967 * @param {CKEDITOR.editor} editor This editor instance.
\r
968 * @param {String} data The HTML to insert.
\r
972 * Internal event to perform the #insertText call
\r
973 * @name CKEDITOR.editor#insertText
\r
975 * @param {CKEDITOR.editor} editor This editor instance.
\r
976 * @param {String} text The text to insert.
\r
980 * Internal event to perform the #insertElement call
\r
981 * @name CKEDITOR.editor#insertElement
\r
983 * @param {CKEDITOR.editor} editor This editor instance.
\r
984 * @param {Object} element The element to insert.
\r