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 (function() 28 { 29 var getMode = function( editor, mode ) 30 { 31 return editor._.modes && editor._.modes[ mode || editor.mode ]; 32 }; 33 34 // This is a semaphore used to avoid recursive calls between 35 // the following data handling functions. 36 var isHandlingData; 37 38 CKEDITOR.plugins.add( 'editingblock', 39 { 40 init : function( editor, pluginPath ) 41 { 42 editor.on( 'themeSpace', function( event ) 43 { 44 if ( event.data.space == 'contents' ) 45 event.data.html += '<br>'; 46 }); 47 48 editor.on( 'themeLoaded', function() 49 { 50 editor.fireOnce( 'editingBlockReady' ); 51 }); 52 53 editor.on( 'uiReady', function() 54 { 55 editor.setMode( editor.config.startupMode ); 56 }); 57 58 editor.on( 'afterSetData', function() 59 { 60 if ( !isHandlingData && editor.mode ) 61 { 62 isHandlingData = true; 63 getMode( editor ).loadData( editor.getData() ); 64 isHandlingData = false; 65 } 66 }); 67 68 editor.on( 'beforeGetData', function() 69 { 70 if ( !isHandlingData && editor.mode ) 71 { 72 isHandlingData = true; 73 editor.setData( getMode( editor ).getData() ); 74 isHandlingData = false; 75 } 76 }); 77 } 78 }); 79 80 /** 81 * The current editing mode. An editing mode is basically a viewport for 82 * editing or content viewing. By default the possible values for this 83 * property are "wysiwyg" and "source". 84 * @type String 85 * @example 86 * alert( CKEDITOR.instances.editor1.mode ); // "wysiwyg" (e.g.) 87 */ 88 CKEDITOR.editor.prototype.mode = ''; 89 90 /** 91 * Registers an editing mode. This function is to be used mainly by plugins. 92 * @param {String} mode The mode name. 93 * @param {Object} modeEditor The mode editor definition. 94 * @example 95 */ 96 CKEDITOR.editor.prototype.addMode = function( mode, modeEditor ) 97 { 98 modeEditor.name = mode; 99 ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor; 100 }; 101 102 /** 103 * Sets the current editing mode in this editor instance. 104 * @param {String} mode A registered mode name. 105 * @example 106 * // Switch to "source" view. 107 * CKEDITOR.instances.editor1.setMode( 'source' ); 108 */ 109 CKEDITOR.editor.prototype.setMode = function( mode ) 110 { 111 var data, 112 holderElement = this.getThemeSpace( 'contents' ); 113 114 // Unload the previous mode. 115 if ( this.mode ) 116 { 117 if ( mode == this.mode ) 118 return; 119 120 var currentMode = getMode( this ); 121 data = currentMode.getData(); 122 currentMode.unload( holderElement ); 123 this.mode = ''; 124 } 125 126 holderElement.setHtml( '' ); 127 128 // Load required mode. 129 var modeEditor = getMode( this, mode ); 130 if ( !modeEditor ) 131 throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".'; 132 133 modeEditor.load( holderElement, data || this.getData() ); 134 135 this.mode = mode; 136 }; 137 })(); 138 139 /** 140 * The mode to load at the editor startup. It depends on the plugins 141 * loaded. By default, the "wysiwyg" and "source" modes are available. 142 * @type String 143 * @default 'wysiwyg' 144 * @example 145 * config.toolbarLocation = 'source'; 146 */ 147 CKEDITOR.config.startupMode = 'wysiwyg'; 148