2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The "sourcearea" plugin. It registers the "source" editing
\r
8 * mode, which displays the raw data being edited in the editor.
\r
11 CKEDITOR.plugins.add( 'sourcearea',
\r
13 requires : [ 'editingblock' ],
\r
15 init : function( editor )
\r
17 var sourcearea = CKEDITOR.plugins.sourcearea;
\r
19 editor.on( 'editingBlockReady', function()
\r
24 editor.addMode( 'source',
\r
26 load : function( holderElement, data )
\r
28 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )
\r
29 holderElement.setStyle( 'position', 'relative' );
\r
31 // Create the source area <textarea>.
\r
32 editor.textarea = textarea = new CKEDITOR.dom.element( 'textarea' );
\r
33 textarea.setAttributes(
\r
38 textarea.addClass( 'cke_source' );
\r
39 textarea.addClass( 'cke_enable_context_menu' );
\r
43 // IE7 has overflow the <textarea> from wrapping table cell.
\r
44 width : CKEDITOR.env.ie7Compat ? '99%' : '100%',
\r
48 'text-align' : 'left'
\r
51 // The textarea height/width='100%' doesn't
\r
52 // constraint to the 'td' in IE strick mode
\r
53 if ( CKEDITOR.env.ie )
\r
55 if ( !CKEDITOR.env.ie8Compat )
\r
57 onResize = function()
\r
59 // Holder rectange size is stretched by textarea,
\r
60 // so hide it just for a moment.
\r
62 textarea.setStyle( 'height', holderElement.$.clientHeight + 'px' );
\r
63 // When we have proper holder size, show textarea again.
\r
66 editor.on( 'resize', onResize );
\r
67 editor.on( 'afterCommandExec', function( event )
\r
69 if ( event.data.name == 'toolbarCollapse' )
\r
72 styles.height = holderElement.$.clientHeight + 'px';
\r
77 // By some yet unknown reason, we must stop the
\r
78 // mousedown propagation for the textarea,
\r
79 // otherwise it's not possible to place the caret
\r
80 // inside of it (non IE).
\r
81 textarea.on( 'mousedown', function( evt )
\r
83 evt.data.stopPropagation();
\r
87 // Reset the holder element and append the
\r
88 // <textarea> to it.
\r
89 holderElement.setHtml( '' );
\r
90 holderElement.append( textarea );
\r
91 textarea.setStyles( styles );
\r
93 textarea.on( 'blur', function()
\r
95 editor.focusManager.blur();
\r
98 textarea.on( 'focus', function()
\r
100 editor.focusManager.focus();
\r
103 // The editor data "may be dirty" after this point.
\r
104 editor.mayBeDirty = true;
\r
106 // Set the <textarea> value.
\r
107 this.loadData( data );
\r
109 var keystrokeHandler = editor.keystrokeHandler;
\r
110 if ( keystrokeHandler )
\r
111 keystrokeHandler.attach( textarea );
\r
113 setTimeout( function()
\r
115 editor.mode = 'source';
\r
116 editor.fire( 'mode' );
\r
118 ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ? 100 : 0 );
\r
121 loadData : function( data )
\r
123 textarea.setValue( data );
\r
124 editor.fire( 'dataReady' );
\r
127 getData : function()
\r
129 return textarea.getValue();
\r
132 getSnapshotData : function()
\r
134 return textarea.getValue();
\r
137 unload : function( holderElement )
\r
139 editor.textarea = textarea = null;
\r
142 editor.removeListener( 'resize', onResize );
\r
144 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )
\r
145 holderElement.removeStyle( 'position' );
\r
155 editor.addCommand( 'source', sourcearea.commands.source );
\r
157 if ( editor.ui.addButton )
\r
159 editor.ui.addButton( 'Source',
\r
161 label : editor.lang.source,
\r
166 editor.on( 'mode', function()
\r
168 editor.getCommand( 'source' ).setState(
\r
169 editor.mode == 'source' ?
\r
170 CKEDITOR.TRISTATE_ON :
\r
171 CKEDITOR.TRISTATE_OFF );
\r
177 * Holds the definition of commands an UI elements included with the sourcearea
\r
181 CKEDITOR.plugins.sourcearea =
\r
187 modes : { wysiwyg:1, source:1 },
\r
189 exec : function( editor )
\r
191 if ( editor.mode == 'wysiwyg' )
\r
192 editor.fire( 'saveSnapshot' );
\r
193 editor.getCommand( 'source' ).setState( CKEDITOR.TRISTATE_DISABLED );
\r
194 editor.setMode( editor.mode == 'source' ? 'wysiwyg' : 'source' );
\r