2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The default editing block plugin, which holds the editing area
13 // This is a semaphore used to avoid recursive calls between
14 // the following data handling functions.
17 CKEDITOR.plugins.add( 'editingblock',
19 init : function( editor )
21 if ( !editor.config.editingBlock )
24 editor.on( 'themeSpace', function( event )
26 if ( event.data.space == 'contents' )
27 event.data.html += '<br>';
30 editor.on( 'themeLoaded', function()
32 editor.fireOnce( 'editingBlockReady' );
35 editor.on( 'uiReady', function()
37 editor.setMode( editor.config.startupMode );
40 editor.on( 'afterSetData', function()
42 if ( !isHandlingData )
46 isHandlingData = true;
47 editor.getMode().loadData( editor.getData() );
48 isHandlingData = false;
55 editor.on( 'mode', function()
60 editor.removeListener( 'mode', arguments.callee );
67 editor.on( 'beforeGetData', function()
69 if ( !isHandlingData && editor.mode )
71 isHandlingData = true;
72 editor.setData( editor.getMode().getData(), null, 1 );
73 isHandlingData = false;
77 editor.on( 'getSnapshot', function( event )
80 event.data = editor.getMode().getSnapshotData();
83 editor.on( 'loadSnapshot', function( event )
86 editor.getMode().loadSnapshotData( event.data );
89 // For the first "mode" call, we'll also fire the "instanceReady"
91 editor.on( 'mode', function( event )
94 event.removeListener();
96 // Redirect the focus into editor for webkit. (#5713)
97 CKEDITOR.env.webkit && editor.container.on( 'focus', function()
102 if ( editor.config.startupFocus )
105 // Fire instanceReady for both the editor and CKEDITOR, but
106 // defer this until the whole execution has completed
107 // to guarantee the editor is fully responsible.
108 setTimeout( function(){
109 editor.fireOnce( 'instanceReady' );
110 CKEDITOR.fire( 'instanceReady', null, editor );
114 editor.on( 'destroy', function ()
116 // -> currentMode.unload( holderElement );
118 this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );
124 * The current editing mode. An editing mode is basically a viewport for
125 * editing or content viewing. By default the possible values for this
126 * property are "wysiwyg" and "source".
129 * alert( CKEDITOR.instances.editor1.mode ); // "wysiwyg" (e.g.)
131 CKEDITOR.editor.prototype.mode = '';
134 * Registers an editing mode. This function is to be used mainly by plugins.
135 * @param {String} mode The mode name.
136 * @param {Object} modeEditor The mode editor definition.
139 CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )
141 modeEditor.name = mode;
142 ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;
146 * Sets the current editing mode in this editor instance.
147 * @param {String} mode A registered mode name.
149 * // Switch to "source" view.
150 * CKEDITOR.instances.editor1.setMode( 'source' );
152 CKEDITOR.editor.prototype.setMode = function( mode )
154 this.fire( 'beforeSetMode', { newMode : mode } );
157 holderElement = this.getThemeSpace( 'contents' ),
158 isDirty = this.checkDirty();
160 // Unload the previous mode.
163 if ( mode == this.mode )
166 this._.previousMode = this.mode;
168 this.fire( 'beforeModeUnload' );
170 var currentMode = this.getMode();
171 data = currentMode.getData();
172 currentMode.unload( holderElement );
176 holderElement.setHtml( '' );
178 // Load required mode.
179 var modeEditor = this.getMode( mode );
181 throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';
185 this.on( 'mode', function()
188 this.removeListener( 'mode', arguments.callee );
192 modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data );
196 * Gets the current or any of the objects that represent the editing
197 * area modes. The two most common editing modes are "wysiwyg" and "source".
198 * @param {String} [mode] The mode to be retrieved. If not specified, the
199 * current one is returned.
201 CKEDITOR.editor.prototype.getMode = function( mode )
203 return this._.modes && this._.modes[ mode || this.mode ];
207 * Moves the selection focus to the editing are space in the editor.
209 CKEDITOR.editor.prototype.focus = function()
211 this.forceNextSelectionCheck();
212 var mode = this.getMode();
219 * The mode to load at the editor startup. It depends on the plugins
220 * loaded. By default, the "wysiwyg" and "source" modes are available.
224 * config.startupMode = 'source';
226 CKEDITOR.config.startupMode = 'wysiwyg';
229 * Sets whether the editor should have the focus when the page loads.
230 * @name CKEDITOR.config.startupFocus
234 * config.startupFocus = true;
238 * Whether to render or not the editing block area in the editor interface.
242 * config.editingBlock = false;
244 CKEDITOR.config.editingBlock = true;
247 * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.
248 * @name CKEDITOR#instanceReady
250 * @param {CKEDITOR.editor} editor The editor instance that has been created.
254 * Fired when the CKEDITOR instance is created, fully initialized and ready for interaction.
255 * @name CKEDITOR.editor#instanceReady
260 * Fired before changing the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#mode
261 * @name CKEDITOR.editor#beforeModeUnload
266 * Fired before the editor mode is set. See also CKEDITOR.editor#mode and CKEDITOR.editor#beforeModeUnload
267 * @name CKEDITOR.editor#beforeSetMode
270 * @param {String} newMode The name of the mode which is about to be set.
274 * Fired after setting the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#beforeModeUnload
275 * @name CKEDITOR.editor#mode
277 * @param {String} previousMode The previous mode of the editor.