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
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 internface elements of this editor instance.
\r
186 * @name CKEDITOR.editor.prototype.langCode
\r
189 * alert( editor.langCode ); // "en" (e.g.)
\r
191 editor.langCode = languageCode;
\r
194 * An object holding 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 ); // "Negrito" (e.g. if language is 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 var config = editor.config;
\r
211 config.contentsLangDirection == 'ui' && ( config.contentsLangDirection = editor.lang.dir );
\r
213 loadPlugins( editor );
\r
217 var loadPlugins = function( editor )
\r
219 var config = editor.config,
\r
220 plugins = config.plugins,
\r
221 extraPlugins = config.extraPlugins,
\r
222 removePlugins = config.removePlugins;
\r
224 if ( extraPlugins )
\r
226 // Remove them first to avoid duplications.
\r
227 var removeRegex = new RegExp( '(?:^|,)(?:' + extraPlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
228 plugins = plugins.replace( removeRegex, '' );
\r
230 plugins += ',' + extraPlugins;
\r
233 if ( removePlugins )
\r
235 removeRegex = new RegExp( '(?:^|,)(?:' + removePlugins.replace( /\s*,\s*/g, '|' ) + ')(?=,|$)' , 'g' );
\r
236 plugins = plugins.replace( removeRegex, '' );
\r
239 // Load the Adobe AIR plugin conditionally.
\r
240 CKEDITOR.env.air && ( plugins += ',adobeair' );
\r
242 // Load all plugins defined in the "plugins" setting.
\r
243 CKEDITOR.plugins.load( plugins.split( ',' ), function( plugins )
\r
245 // The list of plugins.
\r
246 var pluginsArray = [];
\r
248 // The language code to get loaded for each plugin. Null
\r
249 // entries will be appended for plugins with no language files.
\r
250 var languageCodes = [];
\r
252 // The list of URLs to language files.
\r
253 var languageFiles = [];
\r
256 * And object holding references to all plugins used by this
\r
258 * @name CKEDITOR.editor.prototype.plugins
\r
261 * alert( editor.plugins.dialog.path ); // "http://example.com/ckeditor/plugins/dialog/" (e.g.)
\r
263 editor.plugins = plugins;
\r
265 // Loop through all plugins, to build the list of language
\r
266 // files to get loaded.
\r
267 for ( var pluginName in plugins )
\r
269 var plugin = plugins[ pluginName ],
\r
270 pluginLangs = plugin.lang,
\r
271 pluginPath = CKEDITOR.plugins.getPath( pluginName ),
\r
274 // Set the plugin path in the plugin.
\r
275 plugin.path = pluginPath;
\r
277 // If the plugin has "lang".
\r
280 // Resolve the plugin language. If the current language
\r
281 // is not available, get the first one (default one).
\r
282 lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );
\r
284 if ( !plugin.langEntries || !plugin.langEntries[ lang ] )
\r
286 // Put the language file URL into the list of files to
\r
288 languageFiles.push( CKEDITOR.getUrl( pluginPath + 'lang/' + lang + '.js' ) );
\r
292 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );
\r
297 // Save the language code, so we know later which
\r
298 // language has been resolved to this plugin.
\r
299 languageCodes.push( lang );
\r
301 pluginsArray.push( plugin );
\r
304 // Load all plugin specific language files in a row.
\r
305 CKEDITOR.scriptLoader.load( languageFiles, function()
\r
307 // Initialize all plugins that have the "beforeInit" and "init" methods defined.
\r
308 var methods = [ 'beforeInit', 'init', 'afterInit' ];
\r
309 for ( var m = 0 ; m < methods.length ; m++ )
\r
311 for ( var i = 0 ; i < pluginsArray.length ; i++ )
\r
313 var plugin = pluginsArray[ i ];
\r
315 // Uses the first loop to update the language entries also.
\r
316 if ( m === 0 && languageCodes[ i ] && plugin.lang )
\r
317 CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ languageCodes[ i ] ] );
\r
319 // Call the plugin method (beforeInit and init).
\r
320 if ( plugin[ methods[ m ] ] )
\r
321 plugin[ methods[ m ] ]( editor );
\r
325 // Load the editor skin.
\r
326 editor.fire( 'pluginsLoaded' );
\r
327 loadTheme( editor );
\r
332 var loadSkin = function( editor )
\r
334 CKEDITOR.skins.load( editor, 'editor', function()
\r
336 loadLang( editor );
\r
340 var loadTheme = function( editor )
\r
342 var theme = editor.config.theme;
\r
343 CKEDITOR.themes.load( theme, function()
\r
346 * The theme used by this editor instance.
\r
347 * @name CKEDITOR.editor.prototype.theme
\r
348 * @type CKEDITOR.theme
\r
350 * alert( editor.theme ); "http://example.com/ckeditor/themes/default/" (e.g.)
\r
352 var editorTheme = editor.theme = CKEDITOR.themes.get( theme );
\r
353 editorTheme.path = CKEDITOR.themes.getPath( theme );
\r
354 editorTheme.build( editor );
\r
356 if ( editor.config.autoUpdateElement )
\r
357 attachToForm( editor );
\r
361 var attachToForm = function( editor )
\r
363 var element = editor.element;
\r
365 // If are replacing a textarea, we must
\r
366 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.is( 'textarea' ) )
\r
368 var form = element.$.form && new CKEDITOR.dom.element( element.$.form );
\r
371 function onSubmit()
\r
373 editor.updateElement();
\r
375 form.on( 'submit',onSubmit );
\r
377 // Setup the submit function because it doesn't fire the
\r
379 if ( !form.$.submit.nodeName && !form.$.submit.length )
\r
381 form.$.submit = CKEDITOR.tools.override( form.$.submit, function( originalSubmit )
\r
385 editor.updateElement();
\r
387 // For IE, the DOM submit function is not a
\r
388 // function, so we need thid check.
\r
389 if ( originalSubmit.apply )
\r
390 originalSubmit.apply( this, arguments );
\r
397 // Remove 'submit' events registered on form element before destroying.(#3988)
\r
398 editor.on( 'destroy', function()
\r
400 form.removeListener( 'submit', onSubmit );
\r
406 function updateCommands()
\r
409 commands = this._.commands,
\r
415 for ( var name in commands )
\r
417 command = commands[ name ];
\r
418 command[ command.startDisabled ? 'disable' :
\r
419 this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
\r
424 * Initializes the editor instance. This function is called by the editor
\r
425 * contructor (editor_basic.js).
\r
428 CKEDITOR.editor.prototype._init = function()
\r
430 // Get the properties that have been saved in the editor_base
\r
432 var element = CKEDITOR.dom.element.get( this._.element ),
\r
433 instanceConfig = this._.instanceConfig;
\r
434 delete this._.element;
\r
435 delete this._.instanceConfig;
\r
437 this._.commands = {};
\r
438 this._.styles = [];
\r
441 * The DOM element that has been replaced by this editor instance. This
\r
442 * element holds the editor data on load and post.
\r
443 * @name CKEDITOR.editor.prototype.element
\r
444 * @type CKEDITOR.dom.element
\r
446 * var editor = CKEDITOR.instances.editor1;
\r
447 * alert( <b>editor.element</b>.getName() ); "textarea"
\r
449 this.element = element;
\r
452 * The editor instance name. It hay be the replaced element id, name or
\r
453 * a default name using a progressive counter (editor1, editor2, ...).
\r
454 * @name CKEDITOR.editor.prototype.name
\r
457 * var editor = CKEDITOR.instances.editor1;
\r
458 * alert( <b>editor.name</b> ); "editor1"
\r
460 this.name = ( element && ( this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
461 && ( element.getId() || element.getNameAtt() ) )
\r
464 if ( this.name in CKEDITOR.instances )
\r
465 throw '[CKEDITOR.editor] The instance "' + this.name + '" already exists.';
\r
468 * A unique random string assigned to each editor instance in the page.
\r
469 * @name CKEDITOR.editor.prototype.id
\r
472 this.id = CKEDITOR.tools.getNextId();
\r
475 * The configurations for this editor instance. It inherits all
\r
476 * settings defined in (@link CKEDITOR.config}, combined with settings
\r
477 * loaded from custom configuration files and those defined inline in
\r
478 * the page when creating the editor.
\r
479 * @name CKEDITOR.editor.prototype.config
\r
482 * var editor = CKEDITOR.instances.editor1;
\r
483 * alert( <b>editor.config.theme</b> ); "default" e.g.
\r
485 this.config = CKEDITOR.tools.prototypedCopy( CKEDITOR.config );
\r
488 * Namespace containing UI features related to this editor instance.
\r
489 * @name CKEDITOR.editor.prototype.ui
\r
490 * @type CKEDITOR.ui
\r
493 this.ui = new CKEDITOR.ui( this );
\r
496 * Controls the focus state of this editor instance. This property
\r
497 * is rarely used for normal API operations. It is mainly
\r
498 * destinated to developer adding UI elements to the editor interface.
\r
499 * @name CKEDITOR.editor.prototype.focusManager
\r
500 * @type CKEDITOR.focusManager
\r
503 this.focusManager = new CKEDITOR.focusManager( this );
\r
505 CKEDITOR.fire( 'instanceCreated', null, this );
\r
507 this.on( 'mode', updateCommands, null, null, 1 );
\r
508 this.on( 'readOnly', updateCommands, null, null, 1 );
\r
510 initConfig( this, instanceConfig );
\r
514 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
515 /** @lends CKEDITOR.editor.prototype */
\r
518 * Adds a command definition to the editor instance. Commands added with
\r
519 * this function can be later executed with {@link #execCommand}.
\r
520 * @param {String} commandName The indentifier name of the command.
\r
521 * @param {CKEDITOR.commandDefinition} commandDefinition The command definition.
\r
523 * editorInstance.addCommand( 'sample',
\r
525 * exec : function( editor )
\r
527 * alert( 'Executing a command for the editor name "' + editor.name + '"!' );
\r
531 addCommand : function( commandName, commandDefinition )
\r
533 return this._.commands[ commandName ] = new CKEDITOR.command( this, commandDefinition );
\r
537 * Add a trunk of css text to the editor which will be applied to the wysiwyg editing document.
\r
538 * Note: This function should be called before editor is loaded to take effect.
\r
539 * @param css {String} CSS text.
\r
541 * editorInstance.addCss( 'body { background-color: grey; }' );
\r
543 addCss : function( css )
\r
545 this._.styles.push( css );
\r
549 * Destroys the editor instance, releasing all resources used by it.
\r
550 * If the editor replaced an element, the element will be recovered.
\r
551 * @param {Boolean} [noUpdate] If the instance is replacing a DOM
\r
552 * element, this parameter indicates whether or not to update the
\r
553 * element with the instance contents.
\r
555 * alert( CKEDITOR.instances.editor1 ); e.g "object"
\r
556 * <b>CKEDITOR.instances.editor1.destroy()</b>;
\r
557 * alert( CKEDITOR.instances.editor1 ); "undefined"
\r
559 destroy : function( noUpdate )
\r
562 this.updateElement();
\r
564 this.fire( 'destroy' );
\r
565 this.theme && this.theme.destroy( this );
\r
567 CKEDITOR.remove( this );
\r
568 CKEDITOR.fire( 'instanceDestroyed', null, this );
\r
572 * Executes a command.
\r
573 * @param {String} commandName The indentifier name of the command.
\r
574 * @param {Object} [data] Data to be passed to the command
\r
575 * @returns {Boolean} "true" if the command has been successfuly
\r
576 * executed, otherwise "false".
\r
578 * editorInstance.execCommand( 'bold' );
\r
580 execCommand : function( commandName, data )
\r
582 var command = this.getCommand( commandName );
\r
591 if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )
\r
593 if ( this.fire( 'beforeCommandExec', eventData ) !== true )
\r
595 eventData.returnValue = command.exec( eventData.commandData );
\r
597 // Fire the 'afterCommandExec' immediately if command is synchronous.
\r
598 if ( !command.async && this.fire( 'afterCommandExec', eventData ) !== true )
\r
599 return eventData.returnValue;
\r
603 // throw 'Unknown command name "' + commandName + '"';
\r
608 * Gets one of the registered commands. Note that, after registering a
\r
609 * command definition with addCommand, it is transformed internally
\r
610 * into an instance of {@link CKEDITOR.command}, which will be then
\r
611 * returned by this function.
\r
612 * @param {String} commandName The name of the command to be returned.
\r
613 * This is the same used to register the command with addCommand.
\r
614 * @returns {CKEDITOR.command} The command object identified by the
\r
617 getCommand : function( commandName )
\r
619 return this._.commands[ commandName ];
\r
623 * Gets the editor data. The data will be in raw format. It is the same
\r
624 * data that is posted by the editor.
\r
626 * @returns (String) The editor data.
\r
628 * if ( CKEDITOR.instances.editor1.<b>getData()</b> == '' )
\r
629 * alert( 'There is no data available' );
\r
631 getData : function()
\r
633 this.fire( 'beforeGetData' );
\r
635 var eventData = this._.data;
\r
637 if ( typeof eventData != 'string' )
\r
639 var element = this.element;
\r
640 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
641 eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
646 eventData = { dataValue : eventData };
\r
648 // Fire "getData" so data manipulation may happen.
\r
649 this.fire( 'getData', eventData );
\r
651 return eventData.dataValue;
\r
655 * Gets the "raw data" currently available in the editor. This is a
\r
656 * fast method which return the data as is, without processing, so it's
\r
657 * not recommended to use it on resulting pages. It can be used instead
\r
658 * combined with the {@link #loadSnapshot} so one can automatic save
\r
659 * the editor data from time to time while the user is using the
\r
660 * editor, to avoid data loss, without risking performance issues.
\r
662 * alert( editor.getSnapshot() );
\r
664 getSnapshot : function()
\r
666 var data = this.fire( 'getSnapshot' );
\r
668 if ( typeof data != 'string' )
\r
670 var element = this.element;
\r
671 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
672 data = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
\r
679 * Loads "raw data" in the editor. This data is loaded with processing
\r
680 * straight to the editing area. It should not be used as a way to load
\r
681 * any kind of data, but instead in combination with
\r
682 * {@link #getSnapshot} produced data.
\r
684 * var data = editor.getSnapshot();
\r
685 * editor.<b>loadSnapshot( data )</b>;
\r
687 loadSnapshot : function( snapshot )
\r
689 this.fire( 'loadSnapshot', snapshot );
\r
693 * Sets the editor data. The data must be provided in raw format (HTML).<br />
\r
695 * Note that this menthod is asynchronous. The "callback" parameter must
\r
696 * be used if interaction with the editor is needed after setting the data.
\r
697 * @param {String} data HTML code to replace the curent content in the
\r
699 * @param {Function} callback Function to be called after the setData
\r
701 *@param {Boolean} internal Whether suppress any event firing when copying data internally inside editor.
\r
703 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>This is the editor data.</p>' );
\r
705 * CKEDITOR.instances.editor1.<b>setData</b>( '<p>Some other editor data.</p>', function()
\r
707 * this.checkDirty(); // true
\r
710 setData : function( data , callback, internal )
\r
714 this.on( 'dataReady', function( evt )
\r
716 evt.removeListener();
\r
717 callback.call( evt.editor );
\r
721 // Fire "setData" so data manipulation may happen.
\r
722 var eventData = { dataValue : data };
\r
723 !internal && this.fire( 'setData', eventData );
\r
725 this._.data = eventData.dataValue;
\r
727 !internal && this.fire( 'afterSetData', eventData );
\r
731 * Puts or restores the editor into read-only state. When in read-only,
\r
732 * the user is not able to change the editor contents, but still use
\r
733 * some editor features. This function sets the readOnly property of
\r
734 * the editor, firing the "readOnly" event.<br><br>
\r
735 * <strong>Note:</strong> the current editing area will be reloaded.
\r
736 * @param {Boolean} [makeEditable] Indicates that the editor must be
\r
737 * restored from read-only mode, making it editable.
\r
740 setReadOnly : function( makeEditable )
\r
742 if ( this.readOnly != !makeEditable )
\r
744 this.readOnly = !makeEditable;
\r
746 // Fire the readOnly event so the editor features can update
\r
747 // their state accordingly.
\r
748 this.fire( 'readOnly' );
\r
753 * Inserts HTML into the currently selected position in the editor.
\r
754 * @param {String} data HTML code to be inserted into the editor.
\r
756 * CKEDITOR.instances.editor1.<b>insertHtml( '<p>This is a new paragraph.</p>' )</b>;
\r
758 insertHtml : function( data )
\r
760 this.fire( 'insertHtml', data );
\r
764 * Insert text content into the currently selected position in the
\r
765 * editor, in WYSIWYG mode, styles of the selected element will be applied to the inserted text,
\r
766 * spaces around the text will be leaving untouched.
\r
767 * <strong>Note:</strong> two subsequent line-breaks will introduce one paragraph, which element depends on {@link CKEDITOR.config.enterMode};
\r
768 * A single line-break will be instead translated into one <br />.
\r
770 * @param {String} text Text to be inserted into the editor.
\r
772 * CKEDITOR.instances.editor1.<b>insertText( ' line1 \n\n line2' )</b>;
\r
774 insertText : function( text )
\r
776 this.fire( 'insertText', text );
\r
780 * Inserts an element into the currently selected position in the
\r
782 * @param {CKEDITOR.dom.element} element The element to be inserted
\r
785 * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
\r
786 * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;
\r
788 insertElement : function( element )
\r
790 this.fire( 'insertElement', element );
\r
794 * Checks whether the current editor contents present changes when
\r
795 * compared to the contents loaded into the editor at startup, or to
\r
796 * the contents available in the editor when {@link #resetDirty} has
\r
798 * @returns {Boolean} "true" is the contents present changes.
\r
800 * function beforeUnload( e )
\r
802 * if ( CKEDITOR.instances.editor1.<b>checkDirty()</b> )
\r
803 * return e.returnValue = "You'll loose the changes made in the editor.";
\r
806 * if ( window.addEventListener )
\r
807 * window.addEventListener( 'beforeunload', beforeUnload, false );
\r
809 * window.attachEvent( 'onbeforeunload', beforeUnload );
\r
811 checkDirty : function()
\r
813 return ( this.mayBeDirty && this._.previousValue !== this.getSnapshot() );
\r
817 * Resets the "dirty state" of the editor so subsequent calls to
\r
818 * {@link #checkDirty} will return "false" if the user will not make
\r
819 * further changes to the contents.
\r
821 * alert( editor.checkDirty() ); // "true" (e.g.)
\r
822 * editor.<b>resetDirty()</b>;
\r
823 * alert( editor.checkDirty() ); // "false"
\r
825 resetDirty : function()
\r
827 if ( this.mayBeDirty )
\r
828 this._.previousValue = this.getSnapshot();
\r
832 * Updates the <textarea> element that has been replaced by the editor with
\r
833 * the current data available in the editor.
\r
835 * CKEDITOR.instances.editor1.updateElement();
\r
836 * alert( document.getElementById( 'editor1' ).value ); // The current editor data.
\r
838 updateElement : function()
\r
840 var element = this.element;
\r
841 if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
843 var data = this.getData();
\r
845 if ( this.config.htmlEncodeOutput )
\r
846 data = CKEDITOR.tools.htmlEncode( data );
\r
848 if ( element.is( 'textarea' ) )
\r
849 element.setValue( data );
\r
851 element.setHtml( data );
\r
856 CKEDITOR.on( 'loaded', function()
\r
858 // Run the full initialization for pending editors.
\r
859 var pending = CKEDITOR.editor._pending;
\r
862 delete CKEDITOR.editor._pending;
\r
864 for ( var i = 0 ; i < pending.length ; i++ )
\r
865 pending[ i ]._init();
\r
870 * Whether escape HTML when editor update original input element.
\r
871 * @name CKEDITOR.config.htmlEncodeOutput
\r
876 * config.htmlEncodeOutput = true;
\r
880 * If "true", makes the editor start in read-only state. Otherwise, it'll check
\r
881 * if the linked <textarea> has the "disabled" attribute.
\r
882 * @name CKEDITOR.config.readOnly
\r
883 * @see CKEDITOR.editor#setReadOnly
\r
888 * config.readOnly = true;
\r
892 * Fired when a CKEDITOR instance is created, but still before initializing it.
\r
893 * To interact with a fully initialized instance, use the
\r
894 * {@link CKEDITOR#instanceReady} event instead.
\r
895 * @name CKEDITOR#instanceCreated
\r
897 * @param {CKEDITOR.editor} editor The editor instance that has been created.
\r
901 * Fired when a CKEDITOR instance is destroyed.
\r
902 * @name CKEDITOR#instanceDestroyed
\r
904 * @param {CKEDITOR.editor} editor The editor instance that has been destroyed.
\r
908 * Fired when all plugins are loaded and initialized into the editor instance.
\r
909 * @name CKEDITOR.editor#pluginsLoaded
\r
911 * @param {CKEDITOR.editor} editor This editor instance.
\r
915 * Fired before the command execution when {@link #execCommand} is called.
\r
916 * @name CKEDITOR.editor#beforeCommandExec
\r
918 * @param {CKEDITOR.editor} editor This editor instance.
\r
919 * @param {String} data.name The command name.
\r
920 * @param {Object} data.commandData The data to be sent to the command. This
\r
921 * can be manipulated by the event listener.
\r
922 * @param {CKEDITOR.command} data.command The command itself.
\r
926 * Fired after the command execution when {@link #execCommand} is called.
\r
927 * @name CKEDITOR.editor#afterCommandExec
\r
929 * @param {CKEDITOR.editor} editor This editor instance.
\r
930 * @param {String} data.name The command name.
\r
931 * @param {Object} data.commandData The data sent to the command.
\r
932 * @param {CKEDITOR.command} data.command The command itself.
\r
933 * @param {Object} data.returnValue The value returned by the command execution.
\r
937 * Fired every custom configuration file is loaded, before the final
\r
938 * configurations initialization.<br />
\r
940 * Custom configuration files can be loaded thorugh the
\r
941 * {@link CKEDITOR.config.customConfig} setting. Several files can be loading
\r
942 * by chaning this setting.
\r
943 * @name CKEDITOR.editor#customConfigLoaded
\r
945 * @param {CKEDITOR.editor} editor This editor instance.
\r
950 * Fired once the editor configuration is ready (loaded and processed).
\r
951 * @name CKEDITOR.editor#configLoaded
\r
953 * @param {CKEDITOR.editor} editor This editor instance.
\r
955 * if( editor.config.fullPage )
\r
956 * alert( 'This is a full page editor' );
\r
960 * Fired when this editor instance is destroyed. The editor at this
\r
961 * point isn't usable and this event should be used to perform clean up
\r
963 * @name CKEDITOR.editor#destroy
\r
968 * Internal event to get the current data.
\r
969 * @name CKEDITOR.editor#beforeGetData
\r
974 * Internal event to perform the #getSnapshot call.
\r
975 * @name CKEDITOR.editor#getSnapshot
\r
980 * Internal event to perform the #loadSnapshot call.
\r
981 * @name CKEDITOR.editor#loadSnapshot
\r
987 * Event fired before the #getData call returns allowing additional manipulation.
\r
988 * @name CKEDITOR.editor#getData
\r
990 * @param {CKEDITOR.editor} editor This editor instance.
\r
991 * @param {String} data.dataValue The data that will be returned.
\r
995 * Event fired before the #setData call is executed allowing additional manipulation.
\r
996 * @name CKEDITOR.editor#setData
\r
998 * @param {CKEDITOR.editor} editor This editor instance.
\r
999 * @param {String} data.dataValue The data that will be used.
\r
1003 * Event fired at the end of the #setData call is executed. Usually it's better to use the
\r
1004 * {@link CKEDITOR.editor.prototype.dataReady} event.
\r
1005 * @name CKEDITOR.editor#afterSetData
\r
1007 * @param {CKEDITOR.editor} editor This editor instance.
\r
1008 * @param {String} data.dataValue The data that has been set.
\r
1012 * Internal event to perform the #insertHtml call
\r
1013 * @name CKEDITOR.editor#insertHtml
\r
1015 * @param {CKEDITOR.editor} editor This editor instance.
\r
1016 * @param {String} data The HTML to insert.
\r
1020 * Internal event to perform the #insertText call
\r
1021 * @name CKEDITOR.editor#insertText
\r
1023 * @param {CKEDITOR.editor} editor This editor instance.
\r
1024 * @param {String} text The text to insert.
\r
1028 * Internal event to perform the #insertElement call
\r
1029 * @name CKEDITOR.editor#insertElement
\r
1031 * @param {CKEDITOR.editor} editor This editor instance.
\r
1032 * @param {Object} element The element to insert.
\r
1036 * Event fired after {@link CKEDITOR.editor#readOnly} property changes.
\r
1037 * @name CKEDITOR.editor#readOnly
\r
1040 * @param {CKEDITOR.editor} editor This editor instance.
\r