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 "sourcearea" plugin. It registers the "source" editing
 24  *		mode, which displays the raw data being edited in the editor.
 25  */
 26
 27 CKEDITOR.plugins.add( 'sourcearea',
 28 {
 29 	init : function( editor, pluginPath )
 30 	{
 31 		var sourcearea = CKEDITOR.plugins.sourcearea;
 32
 33 		editor.on( 'editingBlockReady', function()
 34 			{
 35 				var textarea;
 36
 37 				editor.addMode( 'source',
 38 					{
 39 						load : function( holderElement, data )
 40 						{
 41 							// Create the source area <textarea>.
 42 							textarea = new CKEDITOR.dom.element( 'textarea' );
 43 							textarea.setAttribute( 'dir', 'ltr' );
 44 							textarea.addClass( 'cke_source' );
 45 							textarea.setStyles({
 46 								width	: '100%',
 47 								height	: '100%',
 48 								resize	: 'none',
 49 								outline	: 'none',
 50 								'text-align' : 'left' });
 51
 52 							// Set the <textarea> value.
 53 							this.loadData( data );
 54
 55 							// Reset the holder element and append the
 56 							// <textarea> to it.
 57 							holderElement.setHtml( '' );
 58 							holderElement.append( textarea );
 59 						},
 60
 61 						loadData : function( data )
 62 						{
 63 							textarea.setValue( data );
 64 						},
 65
 66 						getData : function()
 67 						{
 68 							return textarea.getValue();
 69 						},
 70
 71 						getSnapshotData : function()
 72 						{
 73 							return textarea.getValue();
 74 						},
 75
 76 						unload : function( holderElement )
 77 						{
 78 							textarea = null;
 79 						},
 80
 81 						focus : function()
 82 						{
 83 							textarea.focus();
 84 						}
 85 					});
 86 			});
 87
 88 		editor.addCommand( 'source', sourcearea.commands.source );
 89 		editor.ui.addButton( 'Source', sourcearea.ui.source );
 90 	}
 91 });
 92
 93 /**
 94  * Holds the definition of commands an UI elements included with the sourcearea
 95  * plugin.
 96  * @example
 97  */
 98 CKEDITOR.plugins.sourcearea =
 99 {
100 	commands :
101 	{
102 		source :
103 		{
104 			exec : function( editor )
105 			{
106 				editor.setMode( editor.mode == 'source' ? 'wysiwyg' : 'source' );
107 			}
108 		}
109 	},
110
111 	ui :
112 	{
113 		source :
114 		{
115 			label : 'Source',
116 			command : 'source'
117 		}
118 	}
119 };
120