2 Copyright (c) 2003-2012, 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 through the <code>{@link CKEDITOR.config.skin}</code> setting.
\r
124 * @name CKEDITOR.editor.prototype.skinName
\r
127 * alert( editor.skinName ); // E.g. "kama"
\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 ); // E.g. "http://example.com/ckeditor/skins/kama/"
\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 ); // E.g. "cke_skin_kama"
\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 <code>{@link CKEDITOR.config.tabIndex}</code>
\r
153 * setting or taken from the <code>tabindex</code> attribute of the
\r
154 * <code>{@link #element}</code> associated with the editor.
\r
155 * @name CKEDITOR.editor.prototype.tabIndex
\r
157 * @default 0 (zero)
\r
159 * alert( editor.tabIndex ); // E.g. "0"
\r
161 editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
\r
164 * Indicates the read-only state of this editor. This is a read-only property.
\r
165 * @name CKEDITOR.editor.prototype.readOnly
\r
168 * @see CKEDITOR.editor#setReadOnly
\r
170 editor.readOnly = !!( editor.config.readOnly || editor.element.getAttribute( 'disabled' ) );
\r
172 // Fire the "configLoaded" event.
\r
173 editor.fireOnce( 'configLoaded' );
\r
175 // Load language file.
\r
176 loadSkin( editor );
\r
179 var loadLang = function( editor )
\r
181 CKEDITOR.lang.load( editor.config.language, editor.config.defaultLanguage, function( languageCode, lang )
\r
184 * The code for the language resources that have been loaded
\r
185 * for the user interface elements of this editor instance.
\r
186 * @name CKEDITOR.editor.prototype.langCode
\r
189 * alert( editor.langCode ); // E.g. "en"
\r
191 editor.langCode = languageCode;
\r
194 * An object that contains all language strings used by the editor
\r
196 * @name CKEDITOR.editor.prototype.lang
\r
197 * @type CKEDITOR.lang
\r
199 * alert( editor.lang.bold ); // E.g. "Negrito" (if the language is set to Portuguese)
\r
201 // As we'll be adding plugin specific entries that could come
\r
202 // from different language code files, we need a copy of lang,
\r
203 // not a direct reference to it.
\r
204 editor.lang = CKEDITOR.tools.prototypedCopy( lang );
\r
206 // We're not able to support RTL in Firefox 2 at this time.
\r
207 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 && editor.lang.dir == 'rtl' )
\r
208 editor.lang.dir = 'ltr';
\r
210 editor.fire( 'langLoaded' );
\r
212 var config = editor.config;
\r
213 config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );
\r
215 loadPlugins( editor );
\r
219 var loadPlugins = function( editor )
\r
221 var config = editor.config,
\r
222 plugins = config.plugins,
\r
223 extraPlugins = config.extraPlugins,
\r
224 removePlugins = config.removePlugins;
\r
226 if ( extraPlugins )
\r
228 // Remove them first to avoid duplications.
\r
229 var removeRegex = new RegExp( '(?:^|,)(?:' + extraPlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
230 plugins = plugins.replace( removeRegex, '' );
\r
232 plugins += ',' + extraPlugins;
\r
235 if ( removePlugins )
\r
237 removeRegex = new RegExp( '(?:^|,)(?:' + removePlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
238 plugins = plugins.replace( removeRegex, '' );
\r
241 // Load the Adobe AIR plugin conditionally.
\r
242 CKEDITOR.env.air && ( plugins += ',adobeair' );
\r
244 // Load all plugins defined in the "plugins" setting.
\r
245 CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )
\r
247 // The list of plugins.
\r
248 var pluginsArray = [];
\r
250 // The language code to get loaded for each plugin. Null
\r
251 // entries will be appended for plugins with no language files.
\r
252 var languageCodes = [];
\r
254 // The list of URLs to language files.
\r
255 var languageFiles = [];
\r
258 * An object that contains references to all plugins used by this
\r
260 * @name CKEDITOR.editor.prototype.plugins
\r
263 * alert( editor.plugins.dialog.path ); // E.g. "http://example.com/ckeditor/plugins/dialog/"
\r
265 editor.plugins = plugins;
\r
267 // Loop through all plugins, to build the list of language
\r
268 // files to get loaded.
\r
269 for ( var pluginName in plugins )
\r
271 var plugin = plugins[ pluginName ],
\r
272 pluginLangs = plugin.lang,
\r
273 pluginPath = CKEDITOR.plugins.getPath( pluginName ),
\r
276 // Set the plugin path in the plugin.
\r
277 plugin.path = pluginPath;
\r
279 // If the plugin has "lang".
\r
282 // Resolve the plugin language. If the current language
\r
283 // is not available, get the first one (default one).
\r
284 lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );
\r
286 if ( !plugin.langEntries || !plugin.langEntries[ lang ] )
\r
288 // Put the language file URL into the list of files to
\r
290 languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );
\r
294 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );
\r
299 // Save the language code, so we know later which
\r
300 // language has been resolved to this plugin.
\r
301 languageCodes.push( lang );
\r
303 pluginsArray.push( plugin );
\r
306 // Load all plugin specific language files in a row.
\r
307 CKEDITOR.scriptLoader.load( languageFiles, function()
\r
309 // Initialize all plugins that have the "beforeInit" and "init" methods defined.
\r
310 var methods = [ 'beforeInit', 'init', 'afterInit' ];
\r
311 for ( var m = 0 ; m < methods.length ; m++ )
\r
313 for ( var i = 0 ; i < pluginsArray.length ; i++ )
\r
315 var plugin = pluginsArray[ i ];
\r
317 // Uses the first loop to update the language entries also.
\r
318 if ( m === 0 && languageCodes[ i ] && plugin.lang )
\r
319 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ languageCodes[ i ] ] );
\r
321 // Call the plugin method (beforeInit and init).
\r
322 if ( plugin[ methods[ m ] ] )
\r
323 plugin[ methods[ m ] ]( editor );
\r
327 // Load the editor skin.
\r
328 editor.fire( 'pluginsLoaded' );
\r
329 loadTheme( editor );
\r
334 var loadSkin = function( editor )
\r
336 CKEDITOR.skins.load( editor, 'editor', function()
\r
338 loadLang( editor );
\r
342 var loadTheme = function( editor )
\r
344 var theme = editor.config.theme;
\r
345 CKEDITOR.themes.load( theme, function()
\r
348 * The theme used by this editor instance.
\r
349 * @name CKEDITOR.editor.prototype.theme
\r
350 * @type CKEDITOR.theme
\r
352 * alert( editor.theme ); // E.g. "http://example.com/ckeditor/themes/default/"
\r
354 var editorTheme = editor.theme = CKEDITOR.themes.get( theme );
\r
355 editorTheme.path = CKEDITOR.themes.getPath( theme );
\r
356 editorTheme.build( editor );
\r
358 if ( editor.config.autoUpdateElement )
\r
359 attachToForm( editor );
\r
363 var attachToForm = function( editor )
\r
365 var element = editor.element;
\r
367 // If are replacing a textarea, we must
\r
368 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )
\r
370 var form = element.$.form && new CKEDITOR.dom.element( element.$.form );
\r
373 function onSubmit()
\r
375 editor.updateElement();
\r
377 form.on( 'submit',onSubmit );
\r
379 // Setup the submit function because it doesn't fire the
\r
381 if ( !form.$.submit.nodeName && !form.$.submit.length )
\r
383 form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )
\r
387 editor.updateElement();
\r
389 // For IE, the DOM submit function is not a
\r
390 // function, so we need thid check.
\r
391 if ( originalSubmit.apply )
\r
392 originalSubmit.apply( this, arguments );
\r
399 // Remove 'submit' events registered on form element before destroying.(#3988)
\r
400 editor.on( 'destroy', function()
\r
402 form.removeListener( 'submit', onSubmit );
\r
408 function updateCommands()
\r
411 commands = this._.commands,
\r
417 for ( var name in commands )
\r
419 command = commands[ name ];
\r
420 command[ command.startDisabled ? 'disable' :
\r
421 this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
\r
426 * Initializes the editor instance. This function is called by the editor
\r
427 * contructor (<code>editor_basic.js</code>).
\r
430 CKEDITOR.editor.prototype._init = function()
\r
432 // Get the properties that have been saved in the editor_base
\r
434 var element = CKEDITOR.dom.element.get( this._.element ),
\r
435 instanceConfig = this._.instanceConfig;
\r
436 delete this._.element;
\r
437 delete this._.instanceConfig;
\r
439 this._.commands = {};
\r
440 this._.styles = [];
\r
443 * The DOM element that was replaced by this editor instance. This
\r
444 * element stores the editor data on load and post.
\r
445 * @name CKEDITOR.editor.prototype.element
\r
446 * @type CKEDITOR.dom.element
\r
448 * var editor = CKEDITOR.instances.editor1;
\r
449 * alert( <strong>editor.element</strong>.getName() ); // E.g. "textarea"
\r
451 this.element = element;
\r
454 * The editor instance name. It may be the replaced element ID, name, or
\r
455 * a default name using the progressive counter (<code>editor1</code>,
\r
456 * <code>editor2</code>, ...).
\r
457 * @name CKEDITOR.editor.prototype.name
\r
460 * var editor = CKEDITOR.instances.editor1;
\r
461 * alert( <strong>editor.name</strong> ); // "editor1"
\r
463 this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
464 && ( element.getId() || element.getNameAtt() ) )
\r
467 if ( this.name in CKEDITOR.instances )
\r
468 throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';
\r
471 * A unique random string assigned to each editor instance on the page.
\r
472 * @name CKEDITOR.editor.prototype.id
\r
475 this.id = CKEDITOR.tools.getNextId();
\r
478 * The configurations for this editor instance. It inherits all
\r
479 * settings defined in <code>(@link CKEDITOR.config}</code>, combined with settings
\r
480 * loaded from custom configuration files and those defined inline in
\r
481 * the page when creating the editor.
\r
482 * @name CKEDITOR.editor.prototype.config
\r
485 * var editor = CKEDITOR.instances.editor1;
\r
486 * alert( <strong>editor.config.theme</strong> ); // E.g. "default"
\r
488 this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );
\r
491 * The namespace containing UI features related to this editor instance.
\r
492 * @name CKEDITOR.editor.prototype.ui
\r
493 * @type CKEDITOR.ui
\r
496 this.ui = new CKEDITOR.ui( this );
\r
499 * Controls the focus state of this editor instance. This property
\r
500 * is rarely used for normal API operations. It is mainly
\r
501 * intended for developers adding UI elements to the editor interface.
\r
502 * @name CKEDITOR.editor.prototype.focusManager
\r
503 * @type CKEDITOR.focusManager
\r
506 this.focusManager = new CKEDITOR.focusManager( this );
\r
508 CKEDITOR.fire( 'instanceCreated', null, this );
\r
510 this.on( 'mode', updateCommands, null, null, 1 );
\r
511 this.on( 'readOnly', updateCommands, null, null, 1 );
\r
513 initConfig( this, instanceConfig );
\r
517 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
518 /** @lends CKEDITOR.editor.prototype */
\r
521 * Adds a command definition to the editor instance. Commands added with
\r
522 * this function can be executed later with the <code>{@link #execCommand}</code> method.
\r
523 * @param {String} commandName The indentifier name of the command.
\r
524 * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.
\r
526 * editorInstance.addCommand( 'sample',
\r
528 * exec : function( editor )
\r
530 * alert( 'Executing a command for the editor name "' + editor.name + '"!' );
\r
534 addCommand : function( commandName, commandDefinition )
\r
536 return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );
\r
540 * Adds a piece of CSS code to the editor which will be applied to the WYSIWYG editing document.
\r
541 * This CSS would not be added to the output, and is there mainly for editor-specific editing requirements.
\r
542 * Note: This function should be called before the editor is loaded to take effect.
\r
543 * @param css {String} CSS text.
\r
545 * editorInstance.addCss( 'body { background-color: grey; }' );
\r
547 addCss : function( css )
\r
549 this._.styles.push( css );
\r
553 * Destroys the editor instance, releasing all resources used by it.
\r
554 * If the editor replaced an element, the element will be recovered.
\r
555 * @param {Boolean} [noUpdate] If the instance is replacing a DOM
\r
556 * element, this parameter indicates whether or not to update the
\r
557 * element with the instance contents.
\r
559 * alert( CKEDITOR.instances.editor1 ); // E.g "object"
\r
560 * <strong>CKEDITOR.instances.editor1.destroy()</strong>;
\r
561 * alert( CKEDITOR.instances.editor1 ); // "undefined"
\r
563 destroy : function( noUpdate )
\r
566 this.updateElement();
\r
568 this.fire( 'destroy' );
\r
569 this.theme && this.theme.destroy( this );
\r
571 CKEDITOR.remove( this );
\r
572 CKEDITOR.fire( 'instanceDestroyed', null, this );
\r
576 * Executes a command associated with the editor.
\r
577 * @param {String} commandName The indentifier name of the command.
\r
578 * @param {Object} [data] Data to be passed to the command.
\r
579 * @returns {Boolean} <code>true</code> if the command was executed
\r
580 * successfully, otherwise <code>false</code>.
\r
581 * @see CKEDITOR.editor.addCommand
\r
583 * editorInstance.execCommand( 'bold' );
\r
585 execCommand : function( commandName, data )
\r
587 var command = this.getCommand( commandName );
\r
596 if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )
\r
598 if ( this.fire( 'beforeCommandExec', eventData ) !== true )
\r
600 eventData.returnValue = command.exec( eventData.commandData );
\r
602 // Fire the 'afterCommandExec' immediately if command is synchronous.
\r
603 if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )
\r
604 return eventData.returnValue;
\r
608 // throw 'Unknown command name "' + commandName + '"';
\r
613 * Gets one of the registered commands. Note that after registering a
\r
614 * command definition with <code>{@link #addCommand}</code>, it is
\r
615 * transformed internally into an instance of
\r
616 * <code>{@link CKEDITOR.command}</code>, which will then be returned
\r
617 * by this function.
\r
618 * @param {String} commandName The name of the command to be returned.
\r
619 * This is the same name that is used to register the command with
\r
620 * <code>addCommand</code>.
\r
621 * @returns {CKEDITOR.command} The command object identified by the
\r
624 getCommand : function( commandName )
\r
626 return this._.commands[ commandName ];
\r
630 * Gets the editor data. The data will be in raw format. It is the same
\r
631 * data that is posted by the editor.
\r
633 * @returns (String) The editor data.
\r
635 * if ( CKEDITOR.instances.editor1.<strong>getData()</strong> == '' )
\r
636 * alert( 'There is no data available' );
\r
638 getData : function()
\r
640 this.fire( 'beforeGetData' );
\r
642 var eventData = this._.data;
\r
644 if ( typeof eventData != 'string' )
\r
646 var element = this.element;
\r
647 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
648 eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
653 eventData = { dataValue : eventData };
\r
655 // Fire "getData" so data manipulation may happen.
\r
656 this.fire( 'getData', eventData );
\r
658 return eventData.dataValue;
\r
662 * Gets the "raw data" currently available in the editor. This is a
\r
663 * fast method which returns the data as is, without processing, so it is
\r
664 * not recommended to use it on resulting pages. Instead it can be used
\r
665 * combined with the <code>{@link #loadSnapshot}</code> method in order
\r
666 * to be able to automatically save the editor data from time to time
\r
667 * while the user is using the editor, to avoid data loss, without risking
\r
668 * performance issues.
\r
669 * @see CKEDITOR.editor.getData
\r
671 * alert( editor.getSnapshot() );
\r
673 getSnapshot : function()
\r
675 var data = this.fire( 'getSnapshot' );
\r
677 if ( typeof data != 'string' )
\r
679 var element = this.element;
\r
680 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
681 data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
688 * Loads "raw data" into the editor. The data is loaded with processing
\r
689 * straight to the editing area. It should not be used as a way to load
\r
690 * any kind of data, but instead in combination with
\r
691 * <code>{@link #getSnapshot}</code> produced data.
\r
692 * @see CKEDITOR.editor.setData
\r
694 * var data = editor.getSnapshot();
\r
695 * editor.<strong>loadSnapshot( data )</strong>;
\r
697 loadSnapshot : function( snapshot )
\r
699 this.fire( 'loadSnapshot', snapshot );
\r
703 * Sets the editor data. The data must be provided in the raw format (HTML).<br />
\r
705 * Note that this method is asynchronous. The <code>callback</code> parameter must
\r
706 * be used if interaction with the editor is needed after setting the data.
\r
707 * @param {String} data HTML code to replace the curent content in the
\r
709 * @param {Function} callback Function to be called after the <code>setData</code>
\r
711 *@param {Boolean} internal Whether to suppress any event firing when copying data
\r
712 * internally inside the editor.
\r
714 * CKEDITOR.instances.editor1.<strong>setData</strong>( '<p>This is the editor data.</p>' );
\r
716 * CKEDITOR.instances.editor1.<strong>setData</strong>( '<p>Some other editor data.</p>', function()
\r
718 * this.checkDirty(); // true
\r
721 setData : function( data , callback, internal )
\r
725 this.on( 'dataReady', function( evt )
\r
727 evt.removeListener();
\r
728 callback.call( evt.editor );
\r
732 // Fire "setData" so data manipulation may happen.
\r
733 var eventData = { dataValue : data };
\r
734 !internal && this.fire( 'setData', eventData );
\r
736 this._.data = eventData.dataValue;
\r
738 !internal && this.fire( 'afterSetData', eventData );
\r
742 * Puts or restores the editor into read-only state. When in read-only,
\r
743 * the user is not able to change the editor contents, but can still use
\r
744 * some editor features. This function sets the <code>{@link CKEDITOR.config.readOnly}</code>
\r
745 * property of the editor, firing the <code>{@link CKEDITOR.editor#readOnly}</code> event.<br><br>
\r
746 * <strong>Note:</strong> the current editing area will be reloaded.
\r
747 * @param {Boolean} [isReadOnly] Indicates that the editor must go
\r
748 * read-only (<code>true</code>, default) or be restored and made editable
\r
749 * (<code>false</code>).
\r
752 setReadOnly : function( isReadOnly )
\r
754 isReadOnly = ( isReadOnly == undefined ) || isReadOnly;
\r
756 if ( this.readOnly != isReadOnly )
\r
758 this.readOnly = isReadOnly;
\r
760 // Fire the readOnly event so the editor features can update
\r
761 // their state accordingly.
\r
762 this.fire( 'readOnly' );
\r
767 * Inserts HTML code into the currently selected position in the editor in WYSIWYG mode.
\r
768 * @param {String} data HTML code to be inserted into the editor.
\r
770 * CKEDITOR.instances.editor1.<strong>insertHtml( '<p>This is a new paragraph.</p>' )</strong>;
\r
772 insertHtml : function( data )
\r
774 this.fire( 'insertHtml', data );
\r
778 * Insert text content into the currently selected position in the
\r
779 * editor in WYSIWYG mode. The styles of the selected element will be applied to the inserted text.
\r
780 * Spaces around the text will be leaving untouched.
\r
781 * <strong>Note:</strong> two subsequent line-breaks will introduce one paragraph. This depends on <code>{@link CKEDITOR.config.enterMode}</code>;
\r
782 * A single line-break will be instead translated into one <br />.
\r
784 * @param {String} text Text to be inserted into the editor.
\r
786 * CKEDITOR.instances.editor1.<strong>insertText( ' line1 \n\n line2' )</strong>;
\r
788 insertText : function( text )
\r
790 this.fire( 'insertText', text );
\r
794 * Inserts an element into the currently selected position in the
\r
795 * editor in WYSIWYG mode.
\r
796 * @param {CKEDITOR.dom.element} element The element to be inserted
\r
799 * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
\r
800 * CKEDITOR.instances.editor1.<strong>insertElement( element )</strong>;
\r
802 insertElement : function( element )
\r
804 this.fire( 'insertElement', element );
\r
808 * Checks whether the current editor contents contain changes when
\r
809 * compared to the contents loaded into the editor at startup, or to
\r
810 * the contents available in the editor when <code>{@link #resetDirty}</code>
\r
812 * @returns {Boolean} "true" is the contents contain changes.
\r
814 * function beforeUnload( e )
\r
816 * if ( CKEDITOR.instances.editor1.<strong>checkDirty()</strong> )
\r
817 * return e.returnValue = "You will lose the changes made in the editor.";
\r
820 * if ( window.addEventListener )
\r
821 * window.addEventListener( 'beforeunload', beforeUnload, false );
\r
823 * window.attachEvent( 'onbeforeunload', beforeUnload );
\r
825 checkDirty : function()
\r
827 return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );
\r
831 * Resets the "dirty state" of the editor so subsequent calls to
\r
832 * <code>{@link #checkDirty}</code> will return <code>false</code> if the user will not
\r
833 * have made further changes to the contents.
\r
835 * alert( editor.checkDirty() ); // E.g. "true"
\r
836 * editor.<strong>resetDirty()</strong>;
\r
837 * alert( editor.checkDirty() ); // "false"
\r
839 resetDirty : function()
\r
841 if ( this.mayBeDirty )
\r
842 this._.previousValue = this.getSnapshot();
\r
846 * Updates the <code><textarea></code> element that was replaced by the editor with
\r
847 * the current data available in the editor.
\r
848 * @see CKEDITOR.editor.element
\r
850 * CKEDITOR.instances.editor1.updateElement();
\r
851 * alert( document.getElementById( 'editor1' ).value ); // The current editor data.
\r
853 updateElement : function()
\r
855 var element = this.element;
\r
856 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
858 var data = this.getData();
\r
860 if ( this.config.htmlEncodeOutput )
\r
861 data = CKEDITOR.tools.htmlEncode( data );
\r
863 if ( element.is( 'textarea' ) )
\r
864 element.setValue( data );
\r
866 element.setHtml( data );
\r
871 CKEDITOR.on( 'loaded', function()
\r
873 // Run the full initialization for pending editors.
\r
874 var pending = CKEDITOR.editor._pending;
\r
877 delete CKEDITOR.editor._pending;
\r
879 for ( var i = 0 ; i < pending.length ; i++ )
\r
880 pending[ i ]._init();
\r
885 * Whether to escape HTML when the editor updates the original input element.
\r
886 * @name CKEDITOR.config.htmlEncodeOutput
\r
891 * config.htmlEncodeOutput = true;
\r
895 * If <code>true</code>, makes the editor start in read-only state. Otherwise, it will check
\r
896 * if the linked <code><textarea></code> element has the <code>disabled</code> attribute.
\r
897 * @name CKEDITOR.config.readOnly
\r
898 * @see CKEDITOR.editor#setReadOnly
\r
903 * config.readOnly = true;
\r
907 * Fired when a CKEDITOR instance is created, but still before initializing it.
\r
908 * To interact with a fully initialized instance, use the
\r
909 * <code>{@link CKEDITOR#instanceReady}</code> event instead.
\r
910 * @name CKEDITOR#instanceCreated
\r
912 * @param {CKEDITOR.editor} editor The editor instance that has been created.
\r
916 * Fired when a CKEDITOR instance is destroyed.
\r
917 * @name CKEDITOR#instanceDestroyed
\r
919 * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.
\r
923 * Fired when the language is loaded into the editor instance.
\r
924 * @name CKEDITOR.editor#langLoaded
\r
927 * @param {CKEDITOR.editor} editor This editor instance.
\r
931 * Fired when all plugins are loaded and initialized into the editor instance.
\r
932 * @name CKEDITOR.editor#pluginsLoaded
\r
934 * @param {CKEDITOR.editor} editor This editor instance.
\r
938 * Fired before the command execution when <code>{@link #execCommand}</code> is called.
\r
939 * @name CKEDITOR.editor#beforeCommandExec
\r
941 * @param {CKEDITOR.editor} editor This editor instance.
\r
942 * @param {String} data.name The command name.
\r
943 * @param {Object} data.commandData The data to be sent to the command. This
\r
944 * can be manipulated by the event listener.
\r
945 * @param {CKEDITOR.command} data.command The command itself.
\r
949 * Fired after the command execution when <code>{@link #execCommand}</code> is called.
\r
950 * @name CKEDITOR.editor#afterCommandExec
\r
952 * @param {CKEDITOR.editor} editor This editor instance.
\r
953 * @param {String} data.name The command name.
\r
954 * @param {Object} data.commandData The data sent to the command.
\r
955 * @param {CKEDITOR.command} data.command The command itself.
\r
956 * @param {Object} data.returnValue The value returned by the command execution.
\r
960 * Fired when the custom configuration file is loaded, before the final
\r
961 * configurations initialization.<br />
\r
963 * Custom configuration files can be loaded thorugh the
\r
964 * <code>{@link CKEDITOR.config.customConfig}</code> setting. Several files can be loaded
\r
965 * by changing this setting.
\r
966 * @name CKEDITOR.editor#customConfigLoaded
\r
968 * @param {CKEDITOR.editor} editor This editor instance.
\r
972 * Fired once the editor configuration is ready (loaded and processed).
\r
973 * @name CKEDITOR.editor#configLoaded
\r
975 * @param {CKEDITOR.editor} editor This editor instance.
\r
979 * Fired when this editor instance is destroyed. The editor at this
\r
980 * point is not usable and this event should be used to perform the clean-up
\r
982 * @name CKEDITOR.editor#destroy
\r
987 * Internal event to get the current data.
\r
988 * @name CKEDITOR.editor#beforeGetData
\r
993 * Internal event to perform the <code>#getSnapshot</code> call.
\r
994 * @name CKEDITOR.editor#getSnapshot
\r
999 * Internal event to perform the <code>#loadSnapshot</code> call.
\r
1000 * @name CKEDITOR.editor#loadSnapshot
\r
1005 * Event fired before the <code>#getData</code> call returns allowing additional manipulation.
\r
1006 * @name CKEDITOR.editor#getData
\r
1008 * @param {CKEDITOR.editor} editor This editor instance.
\r
1009 * @param {String} data.dataValue The data that will be returned.
\r
1013 * Event fired before the <code>#setData</code> call is executed allowing additional manipulation.
\r
1014 * @name CKEDITOR.editor#setData
\r
1016 * @param {CKEDITOR.editor} editor This editor instance.
\r
1017 * @param {String} data.dataValue The data that will be used.
\r
1021 * Event fired at the end of the <code>#setData</code> call execution. Usually it is better to use the
\r
1022 * <code>{@link CKEDITOR.editor.prototype.dataReady}</code> event.
\r
1023 * @name CKEDITOR.editor#afterSetData
\r
1025 * @param {CKEDITOR.editor} editor This editor instance.
\r
1026 * @param {String} data.dataValue The data that has been set.
\r
1030 * Internal event to perform the <code>#insertHtml</code> call
\r
1031 * @name CKEDITOR.editor#insertHtml
\r
1033 * @param {CKEDITOR.editor} editor This editor instance.
\r
1034 * @param {String} data The HTML to insert.
\r
1038 * Internal event to perform the <code>#insertText</code> call
\r
1039 * @name CKEDITOR.editor#insertText
\r
1041 * @param {CKEDITOR.editor} editor This editor instance.
\r
1042 * @param {String} text The text to insert.
\r
1046 * Internal event to perform the <code>#insertElement</code> call
\r
1047 * @name CKEDITOR.editor#insertElement
\r
1049 * @param {CKEDITOR.editor} editor This editor instance.
\r
1050 * @param {Object} element The element to insert.
\r
1054 * Event fired after the <code>{@link CKEDITOR.editor#readOnly}</code> property changes.
\r
1055 * @name CKEDITOR.editor#readOnly
\r
1058 * @param {CKEDITOR.editor} editor This editor instance.
\r