1 /*
  2  * CKEditor - The text editor for Internet - http://ckeditor.com
  3  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
  4  *
  5  * == BEGIN LICENSE ==
  6  *
  7  * Licensed under the terms of any of the following licenses at your
  8  * choice:
  9  *
 10  *  - GNU General Public License Version 2 or later (the "GPL")
 11  *    http://www.gnu.org/licenses/gpl.html
 12  *
 13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  *    http://www.gnu.org/licenses/lgpl.html
 15  *
 16  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  *
 19  * == END LICENSE ==
 20  */
 21
 22 /**
 23  * @fileOverview The default editing block plugin, which holds the editing area
 24  *		and source view.
 25  */
 26
 27 CKEDITOR.plugins.add( 'editingblock',
 28 {
 29 	init : function( editor, pluginPath )
 30 	{
 31 		editor.on( 'themespace', function( event )
 32 			{
 33 				if ( event.data.space == 'middle' )
 34 					event.data.html += '<br>';
 35 			});
 36
 37 		editor.on( 'themeloaded', function()
 38 			{
 39 				editor.fireOnce( 'editingblockready' );
 40 			});
 41
 42 		editor.on( 'uiready', function()
 43 			{
 44 				editor.setMode( CKEDITOR.config.startupMode );
 45 			});
 46 	}
 47 });
 48
 49 (function()
 50 {
 51 	var getMode = function( editor, mode )
 52 	{
 53 		return editor._.modes && editor._.modes[ mode ];
 54 	};
 55
 56 	/**
 57 	 * The current editing mode. An editing mode is basically a viewport for
 58 	 * editing or content viewing. By default the possible values for this
 59 	 * property are "wysiwyg" and "source".
 60 	 * @type String
 61 	 * @example
 62 	 * alert( CKEDITOR.instances.editor1.mode );  // "wysiwyg" (e.g.)
 63 	 */
 64 	CKEDITOR.editor.prototype.mode = '';
 65
 66 	/**
 67 	 * Registers an editing mode. This function is to be used mainly by plugins.
 68 	 * @param {String} mode The mode name.
 69 	 * @param {Object} modeEditor The mode editor definition.
 70 	 * @type undefined
 71 	 * @example
 72 	 */
 73 	CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )
 74 	{
 75 		modeEditor.name = mode;
 76 		( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;
 77 	};
 78
 79 	/**
 80 	 * Sets the current editing mode in this editor instance.
 81 	 * @param {String} mode A registered mode name.
 82 	 * @type undefined
 83 	 * @example
 84 	 * // Switch to "source" view.
 85 	 * CKEDITOR.instances.editor1.setMode( 'source' );
 86 	 */
 87 	CKEDITOR.editor.prototype.setMode = function( mode )
 88 	{
 89 		var holderElement = this.getThemeSpace( 'middle' );
 90
 91 		// Unload previous mode.
 92 		if ( this.mode )
 93 			getMode( this, this.mode ).unload( holderElement );
 94
 95 		// Load required mode.
 96 		var modeEditor = getMode( this, mode );
 97 		if ( !modeEditor )
 98 			throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';
 99
100 		this.mode = mode;
101
102 		modeEditor.load( holderElement );
103 	};
104 })();
105