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 "wysiwygarea" plugin. It registers the "wysiwyg" editing
 24  *		mode, which handles the main editing area space.
 25  */
 26
 27 CKEDITOR.plugins.add( 'wysiwygarea',
 28 {
 29 	init : function( editor, pluginPath )
 30 	{
 31 		editor.on( 'editingBlockReady', function()
 32 			{
 33 				var mainElement,
 34 					iframe;
 35
 36 				// The following information is needed for IE only.
 37 				var isCustomDomain = CKEDITOR.env.ie && document.domain != window.location.hostname;
 38
 39 				// Creates the iframe that holds the editable document.
 40 				var createIFrame = function()
 41 				{
 42 					if ( iframe )
 43 						iframe.remove();
 44
 45 					iframe = new CKEDITOR.dom.element( 'iframe' );
 46 					iframe.setAttributes({
 47 						frameBorder : 0,
 48 						allowTransparency : true });
 49 					iframe.setStyles({
 50 						width : '100%',
 51 						height : '100%' });
 52
 53 					if ( CKEDITOR.env.ie )
 54 					{
 55 						if ( isCustomDomain )
 56 						{
 57 							// The document domain must be set within the src
 58 							// attribute.
 59 							iframe.setAttribute( 'src',
 60 								'javascript:void( (function(){' +
 61 									'document.open();' +
 62 									'document.domain="' + document.domain + '";' +
 63 									'document.write( window.parent._cke_htmlToLoad_' + editor.name + ' );' +
 64 									'document.close();' +
 65 									'window.parent._cke_htmlToLoad_' + editor.name + ' = null;' +
 66 								'})() )' );
 67 						}
 68 						else
 69 							// To avoid HTTPS warnings.
 70 							iframe.setAttribute( 'src', 'javascript:void(0)' );
 71 					}
 72
 73 					// Append the new IFRAME to the main element. For IE, it
 74 					// must be done after setting the "src", to avoid the
 75 					// "secure/unsecure" message under HTTPS.
 76 					mainElement.append( iframe );
 77 				};
 78
 79 				// The script that is appended to the data being loaded. It
 80 				// enables editing, and makes some
 81 				var activationScript =
 82 					'<script id="cke_actscrpt" type="text/javascript">' +
 83 						'window.onload = function()' +
 84 						'{' +
 85 							// Remove this script from the DOM.
 86 							'var s = document.getElementById( "cke_actscrpt" );' +
 87 							's.parentNode.removeChild( s );' +
 88
 89 							// Call the temporary function for the editing
 90 							// boostrap.
 91 							'window.parent.CKEDITOR.instances.' + editor.name + '._.contentDomReady( window );' +
 92 						'}' +
 93 					'</script>';
 94
 95 				// Editing area bootstrap code.
 96 				var contentDomReady = function( domWindow )
 97 				{
 98 					delete editor._.contentDomReady;
 99
100 					var domDocument = domWindow.document,
101 						body = domDocument.body;
102
103 					body.spellcheck = !editor.config.disableNativeSpellChecker;
104
105 					if ( CKEDITOR.env.ie )
106 					{
107 						// Disable and re-enable the body to avoid IE from
108 						// taking the editing focus at startup. (#141 / #523)
109 						body.disabled = true;
110 						body.contentEditable = true;
111 						body.removeAttribute( 'disabled' );
112 					}
113 					else
114 						domDocument.designMode = 'on';
115
116 					// IE, Opera and Safari may not support it and throw
117 					// errors.
118 					try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
119 					try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
120
121 					editor.window	= new CKEDITOR.dom.window( domWindow );
122 					editor.document	= new CKEDITOR.dom.document( domDocument );
123
124 					editor.fire( 'contentDom' );
125 				};
126
127 				editor.addMode( 'wysiwyg',
128 					{
129 						load : function( holderElement, data )
130 						{
131 							mainElement = holderElement;
132
133 							// Create the iframe at load for all browsers
134 							// except FF and IE with custom domain.
135 							if ( !isCustomDomain || !CKEDITOR.env.gecko )
136 								createIFrame();
137
138 							this.loadData( data );
139 						},
140
141 						loadData : function( data )
142 						{
143 							data =
144 								CKEDITOR.config.docType +
145 								'<html dir="' + CKEDITOR.config.contentLangDirection + '">' +
146 								'<head>' +
147 									'<link href="' + CKEDITOR.config.contentsCss + '" type="text/css" rel="stylesheet" _fcktemp="true"/>' +
148 								'</head>' +
149 								'<body>' +
150 									editor.dataProcessor.toHtml( data ) +
151 								'</body>' +
152 								'</html>' +
153 								activationScript;
154
155 							// For custom domain in IE, set the global variable
156 							// that will temporarily hold the editor data. This
157 							// reference will be used in the ifram src.
158 							if ( isCustomDomain )
159 								window[ '_cke_htmlToLoad_' + editor.name ] = data;
160
161 							editor._.contentDomReady = contentDomReady;
162
163 							// We need to recreate the iframe in FF for every
164 							// data load, otherwise the following spellcheck
165 							// and execCommand features will be active only for
166 							// the first time.
167 							// The same is valid for IE with custom domain,
168 							// because the iframe src must be reset every time.
169 							if ( isCustomDomain || CKEDITOR.env.gecko )
170 								createIFrame();
171
172 							// For custom domain in IE, the data loading is
173 							// done through the src attribute of the iframe.
174 							if ( !isCustomDomain )
175 							{
176 								var doc = iframe.$.contentWindow.document;
177 								doc.open();
178 								doc.write( data );
179 								doc.close();
180 							}
181 						},
182
183 						getData : function()
184 						{
185 							return editor.dataProcessor.toDataFormat( new CKEDITOR.dom.element( iframe.$.contentWindow.document.body ) );
186 						},
187
188 						unload : function( holderElement )
189 						{
190 							editor.window = editor.document = iframe = mainElement = null;
191
192 							editor.fire( 'contentDomUnload' );
193 						}
194 					});
195 			});
196 	}
197 });
198
199 /**
200  * Disables the ability of resize objects (image and tables) in the editing
201  * area
202  * @type Boolean
203  * @default false
204  * @example
205  * config.disableObjectResizing = true;
206  */
207 CKEDITOR.config.disableObjectResizing = false;
208
209 /**
210  * Disables the "table tools" offered natively by the browser (currently
211  * Firefox only) to make quick table editing operations, like adding or
212  * deleting rows and columns.
213  * @type Boolean
214  * @default true
215  * @example
216  * config.disableNativeTableHandles = false;
217  */
218 CKEDITOR.config.disableNativeTableHandles = true;
219
220 /**
221  * Disables the built-in spell checker while typing natively available in the
222  * browser (currently Firefox and Safari only).<br /><br />
223  *
224  * Even if word suggestions will not appear in the FCKeditor context menu, this
225  * feature is useful to help quickly identifying misspelled words.<br /><br />
226  *
227  * This setting is currently compatible with Firefox only due to limitations in
228  * other browsers.
229  * @type Boolean
230  * @default true
231  * @example
232  * config.disableNativeSpellChecker = false;
233  */
234 CKEDITOR.config.disableNativeSpellChecker = true;
235