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 The default editing block plugin, which holds the editing area
\r
13 var getMode = function( editor, mode )
\r
15 return editor._.modes && editor._.modes[ mode || editor.mode ];
\r
18 // This is a semaphore used to avoid recursive calls between
\r
19 // the following data handling functions.
\r
22 CKEDITOR.plugins.add( 'editingblock',
\r
24 init : function( editor )
\r
26 if ( !editor.config.editingBlock )
\r
29 editor.on( 'themeSpace', function( event )
\r
31 if ( event.data.space == 'contents' )
\r
32 event.data.html += '<br>';
\r
35 editor.on( 'themeLoaded', function()
\r
37 editor.fireOnce( 'editingBlockReady' );
\r
40 editor.on( 'uiReady', function()
\r
42 editor.setMode( editor.config.startupMode );
\r
45 editor.on( 'afterSetData', function()
\r
47 if ( !isHandlingData )
\r
51 isHandlingData = true;
\r
52 getMode( editor ).loadData( editor.getData() );
\r
53 isHandlingData = false;
\r
60 editor.on( 'mode', function()
\r
63 editor.removeListener( 'mode', arguments.callee );
\r
69 editor.on( 'beforeGetData', function()
\r
71 if ( !isHandlingData && editor.mode )
\r
73 isHandlingData = true;
\r
74 editor.setData( getMode( editor ).getData() );
\r
75 isHandlingData = false;
\r
79 editor.on( 'getSnapshot', function( event )
\r
82 event.data = getMode( editor ).getSnapshotData();
\r
85 editor.on( 'loadSnapshot', function( event )
\r
88 getMode( editor ).loadSnapshotData( event.data );
\r
91 // For the first "mode" call, we'll also fire the "instanceReady"
\r
93 editor.on( 'mode', function( event )
\r
95 // Do that once only.
\r
96 event.removeListener();
\r
98 // Redirect the focus into editor for webkit. (#5713)
\r
99 CKEDITOR.env.webkit && editor.container.on( 'focus', function()
\r
104 if ( editor.config.startupFocus )
\r
107 // Fire instanceReady for both the editor and CKEDITOR, but
\r
108 // defer this until the whole execution has completed
\r
109 // to guarantee the editor is fully responsible.
\r
110 setTimeout( function(){
\r
111 editor.fireOnce( 'instanceReady' );
\r
112 CKEDITOR.fire( 'instanceReady', null, editor );
\r
116 editor.on( 'destroy', function ()
\r
118 // -> currentMode.unload( holderElement );
\r
120 this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );
\r
126 * The current editing mode. An editing mode is basically a viewport for
\r
127 * editing or content viewing. By default the possible values for this
\r
128 * property are "wysiwyg" and "source".
\r
131 * alert( CKEDITOR.instances.editor1.mode ); // "wysiwyg" (e.g.)
\r
133 CKEDITOR.editor.prototype.mode = '';
\r
136 * Registers an editing mode. This function is to be used mainly by plugins.
\r
137 * @param {String} mode The mode name.
\r
138 * @param {Object} modeEditor The mode editor definition.
\r
141 CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )
\r
143 modeEditor.name = mode;
\r
144 ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;
\r
148 * Sets the current editing mode in this editor instance.
\r
149 * @param {String} mode A registered mode name.
\r
151 * // Switch to "source" view.
\r
152 * CKEDITOR.instances.editor1.setMode( 'source' );
\r
154 CKEDITOR.editor.prototype.setMode = function( mode )
\r
157 holderElement = this.getThemeSpace( 'contents' ),
\r
158 isDirty = this.checkDirty();
\r
160 // Unload the previous mode.
\r
163 if ( mode == this.mode )
\r
166 this.fire( 'beforeModeUnload' );
\r
168 var currentMode = getMode( this );
\r
169 data = currentMode.getData();
\r
170 currentMode.unload( holderElement );
\r
174 holderElement.setHtml( '' );
\r
176 // Load required mode.
\r
177 var modeEditor = getMode( this, mode );
\r
179 throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';
\r
183 this.on( 'mode', function()
\r
186 this.removeListener( 'mode', arguments.callee );
\r
190 modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data);
\r
194 * Moves the selection focus to the editing are space in the editor.
\r
196 CKEDITOR.editor.prototype.focus = function()
\r
198 var mode = getMode( this );
\r
205 * The mode to load at the editor startup. It depends on the plugins
\r
206 * loaded. By default, the "wysiwyg" and "source" modes are available.
\r
208 * @default 'wysiwyg'
\r
210 * config.startupMode = 'source';
\r
212 CKEDITOR.config.startupMode = 'wysiwyg';
\r
215 * Sets whether the editor should have the focus when the page loads.
\r
219 * config.startupFocus = true;
\r
223 * Whether to render or not the editing block area in the editor interface.
\r
227 * config.editingBlock = false;
\r
229 CKEDITOR.config.editingBlock = true;
\r
232 * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.
\r
233 * @name CKEDITOR#instanceReady
\r
235 * @param {CKEDITOR.editor} editor The editor instance that has been created.
\r
239 * Fired when the CKEDITOR instance is created, fully initialized and ready for interaction.
\r
240 * @name CKEDITOR.editor#instanceReady
\r
245 * Fired before changing the editing mode
\r
246 * @name CKEDITOR.editor#beforeModeUnload
\r