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
42 // IE7 has overflow the <textarea> from wrapping table cell.
\r
43 width : CKEDITOR.env.ie7Compat ? '99%' : '100%',
\r
47 'text-align' : 'left'
\r
50 // The textarea height/width='100%' doesn't
\r
51 // constraint to the 'td' in IE strick mode
\r
52 if ( CKEDITOR.env.ie )
\r
54 if ( !CKEDITOR.env.ie8Compat )
\r
56 onResize = function()
\r
58 // Holder rectange size is stretched by textarea,
\r
59 // so hide it just for a moment.
\r
61 textarea.setStyle( 'height', holderElement.$.clientHeight + 'px' );
\r
62 // When we have proper holder size, show textarea again.
\r
65 editor.on( 'resize', onResize );
\r
66 styles.height = holderElement.$.clientHeight + 'px';
\r
71 // By some yet unknown reason, we must stop the
\r
72 // mousedown propagation for the textarea,
\r
73 // otherwise it's not possible to place the caret
\r
74 // inside of it (non IE).
\r
75 textarea.on( 'mousedown', function( evt )
\r
78 if ( evt.stopPropagation )
\r
79 evt.stopPropagation();
\r
83 // Reset the holder element and append the
\r
84 // <textarea> to it.
\r
85 holderElement.setHtml( '' );
\r
86 holderElement.append( textarea );
\r
87 textarea.setStyles( styles );
\r
89 // The editor data "may be dirty" after this point.
\r
90 editor.mayBeDirty = true;
\r
92 // Set the <textarea> value.
\r
93 this.loadData( data );
\r
95 var keystrokeHandler = editor.keystrokeHandler;
\r
96 if ( keystrokeHandler )
\r
97 keystrokeHandler.attach( textarea );
\r
99 setTimeout( function()
\r
101 editor.mode = 'source';
\r
102 editor.fire( 'mode' );
\r
104 ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ? 100 : 0 );
\r
107 loadData : function( data )
\r
109 textarea.setValue( data );
\r
112 getData : function()
\r
114 return textarea.getValue();
\r
117 getSnapshotData : function()
\r
119 return textarea.getValue();
\r
122 unload : function( holderElement )
\r
124 editor.textarea = textarea = null;
\r
127 editor.removeListener( 'resize', onResize );
\r
129 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )
\r
130 holderElement.removeStyle( 'position' );
\r
140 editor.addCommand( 'source', sourcearea.commands.source );
\r
142 if ( editor.ui.addButton )
\r
144 editor.ui.addButton( 'Source',
\r
146 label : editor.lang.source,
\r
151 editor.on( 'mode', function()
\r
153 editor.getCommand( 'source' ).setState(
\r
154 editor.mode == 'source' ?
\r
155 CKEDITOR.TRISTATE_ON :
\r
156 CKEDITOR.TRISTATE_OFF );
\r
162 * Holds the definition of commands an UI elements included with the sourcearea
\r
166 CKEDITOR.plugins.sourcearea =
\r
172 modes : { wysiwyg:1, source:1 },
\r
174 exec : function( editor )
\r
176 if ( editor.mode == 'wysiwyg' )
\r
177 editor.fire( 'saveSnapshot' );
\r
178 editor.getCommand( 'source' ).setState( CKEDITOR.TRISTATE_DISABLED );
\r
179 editor.setMode( editor.mode == 'source' ? 'wysiwyg' : 'source' );
\r