X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Feditingblock%2Fplugin.js;h=4d5cfe2835b0a18ff78fb4b4f48c802b835cf2ec;hb=refs%2Ftags%2Fv3.6.2;hp=05d78b6a35f0ca50d213e6f79d9f59db7b6cb605;hpb=4e90e78dc97789709ee7404359a5517540c27553;p=ckeditor.git diff --git a/_source/plugins/editingblock/plugin.js b/_source/plugins/editingblock/plugin.js index 05d78b6..4d5cfe2 100644 --- a/_source/plugins/editingblock/plugin.js +++ b/_source/plugins/editingblock/plugin.js @@ -10,11 +10,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - var getMode = function( editor, mode ) - { - return editor._.modes && editor._.modes[ mode || editor.mode ]; - }; - // This is a semaphore used to avoid recursive calls between // the following data handling functions. var isHandlingData; @@ -49,7 +44,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function setData() { isHandlingData = true; - getMode( editor ).loadData( editor.getData() ); + editor.getMode().loadData( editor.getData() ); isHandlingData = false; } @@ -59,8 +54,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { editor.on( 'mode', function() { - setData(); - editor.removeListener( 'mode', arguments.callee ); + if ( editor.mode ) + { + setData(); + editor.removeListener( 'mode', arguments.callee ); + } }); } } @@ -71,7 +69,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !isHandlingData && editor.mode ) { isHandlingData = true; - editor.setData( getMode( editor ).getData(), null, 1 ); + editor.setData( editor.getMode().getData(), null, 1 ); isHandlingData = false; } }); @@ -79,13 +77,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'getSnapshot', function( event ) { if ( editor.mode ) - event.data = getMode( editor ).getSnapshotData(); + event.data = editor.getMode().getSnapshotData(); }); editor.on( 'loadSnapshot', function( event ) { if ( editor.mode ) - getMode( editor ).loadSnapshotData( event.data ); + editor.getMode().loadSnapshotData( event.data ); }); // For the first "mode" call, we'll also fire the "instanceReady" @@ -165,9 +163,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( mode == this.mode ) return; + this._.previousMode = this.mode; + this.fire( 'beforeModeUnload' ); - var currentMode = getMode( this ); + var currentMode = this.getMode(); data = currentMode.getData(); currentMode.unload( holderElement ); this.mode = ''; @@ -176,7 +176,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license holderElement.setHtml( '' ); // Load required mode. - var modeEditor = getMode( this, mode ); + var modeEditor = this.getMode( mode ); if ( !modeEditor ) throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".'; @@ -189,7 +189,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }); } - modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data); + modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data ); + }; + + /** + * Gets the current or any of the objects that represent the editing + * area modes. The two most common editing modes are "wysiwyg" and "source". + * @param {String} [mode] The mode to be retrieved. If not specified, the + * current one is returned. + */ + CKEDITOR.editor.prototype.getMode = function( mode ) + { + return this._.modes && this._.modes[ mode || this.mode ]; }; /** @@ -198,7 +209,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.editor.prototype.focus = function() { this.forceNextSelectionCheck(); - var mode = getMode( this ); + var mode = this.getMode(); if ( mode ) mode.focus(); }; @@ -246,15 +257,22 @@ CKEDITOR.config.editingBlock = true; */ /** - * Fired before changing the editing mode. + * Fired before changing the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#mode * @name CKEDITOR.editor#beforeModeUnload * @event */ /** - * Fired before the editor mode is set. + * Fired before the editor mode is set. See also CKEDITOR.editor#mode and CKEDITOR.editor#beforeModeUnload * @name CKEDITOR.editor#beforeSetMode * @event * @since 3.5.3 * @param {String} newMode The name of the mode which is about to be set. */ + +/** + * Fired after setting the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#beforeModeUnload + * @name CKEDITOR.editor#mode + * @event + * @param {String} previousMode The previous mode of the editor. + */