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.fire( 'beforeModeUnload' );
168 var currentMode
= this.getMode();
169 data
= currentMode
.getData();
170 currentMode
.unload( holderElement
);
174 holderElement
.setHtml( '' );
176 // Load required mode.
177 var modeEditor
= this.getMode( mode
);
179 throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode
+ '".';
183 this.on( 'mode', function()
186 this.removeListener( 'mode', arguments
.callee
);
190 modeEditor
.load( holderElement
, ( typeof data
) != 'string' ? this.getData() : data
);
194 * Gets the current or any of the objects that represent the editing
195 * area modes. The two most common editing modes are "wysiwyg" and "source".
196 * @param {String} [mode] The mode to be retrieved. If not specified, the
197 * current one is returned.
199 CKEDITOR
.editor
.prototype.getMode = function( mode
)
201 return this._
.modes
&& this._
.modes
[ mode
|| this.mode
];
205 * Moves the selection focus to the editing are space in the editor.
207 CKEDITOR
.editor
.prototype.focus = function()
209 this.forceNextSelectionCheck();
210 var mode
= this.getMode();
217 * The mode to load at the editor startup. It depends on the plugins
218 * loaded. By default, the "wysiwyg" and "source" modes are available.
222 * config.startupMode = 'source';
224 CKEDITOR
.config
.startupMode
= 'wysiwyg';
227 * Sets whether the editor should have the focus when the page loads.
228 * @name CKEDITOR.config.startupFocus
232 * config.startupFocus = true;
236 * Whether to render or not the editing block area in the editor interface.
240 * config.editingBlock = false;
242 CKEDITOR
.config
.editingBlock
= true;
245 * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.
246 * @name CKEDITOR#instanceReady
248 * @param {CKEDITOR.editor} editor The editor instance that has been created.
252 * Fired when the CKEDITOR instance is created, fully initialized and ready for interaction.
253 * @name CKEDITOR.editor#instanceReady
258 * Fired before changing the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#mode
259 * @name CKEDITOR.editor#beforeModeUnload
264 * Fired before the editor mode is set. See also CKEDITOR.editor#mode and CKEDITOR.editor#beforeModeUnload
265 * @name CKEDITOR.editor#beforeSetMode
268 * @param {String} newMode The name of the mode which is about to be set.
272 * Fired after setting the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#beforeModeUnload
273 * @name CKEDITOR.editor#mode