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 /**
 50  * The mode to load at the editor startup. It depends on the plugins
 51  * loaded. By default, the "wysiwyg" and "source" modes are available.
 52  * @type String
 53  * @default 'wysiwyg'
 54  * @example
 55  * config.toolbarLocation = 'source';
 56  */
 57 CKEDITOR.config.startupMode = 'wysiwyg';
 58
 59 (function()
 60 {
 61 	var getMode = function( editor, mode )
 62 	{
 63 		return editor._.modes && editor._.modes[ mode ];
 64 	};
 65
 66 	/**
 67 	 * The current editing mode. An editing mode is basically a viewport for
 68 	 * editing or content viewing. By default the possible values for this
 69 	 * property are "wysiwyg" and "source".
 70 	 * @type String
 71 	 * @example
 72 	 * alert( CKEDITOR.instances.editor1.mode );  // "wysiwyg" (e.g.)
 73 	 */
 74 	CKEDITOR.editor.prototype.mode = '';
 75
 76 	/**
 77 	 * Registers an editing mode. This function is to be used mainly by plugins.
 78 	 * @param {String} mode The mode name.
 79 	 * @param {Object} modeEditor The mode editor definition.
 80 	 * @type undefined
 81 	 * @example
 82 	 */
 83 	CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )
 84 	{
 85 		modeEditor.name = mode;
 86 		( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;
 87 	};
 88
 89 	/**
 90 	 * Sets the current editing mode in this editor instance.
 91 	 * @param {String} mode A registered mode name.
 92 	 * @type undefined
 93 	 * @example
 94 	 * // Switch to "source" view.
 95 	 * CKEDITOR.instances.editor1.setMode( 'source' );
 96 	 */
 97 	CKEDITOR.editor.prototype.setMode = function( mode )
 98 	{
 99 		var holderElement = this.getThemeSpace( 'middle' );
100
101 		// Unload previous mode.
102 		if ( this.mode )
103 			getMode( this, this.mode ).unload( holderElement );
104
105 		// Load required mode.
106 		var modeEditor = getMode( this, mode );
107 		if ( !modeEditor )
108 			throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';
109
110 		this.mode = mode;
111
112 		modeEditor.load( holderElement );
113 	};
114 })();
115