1 | /*
|
---|
2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing
|
---|
8 | * mode, which handles the main editing area space.
|
---|
9 | */
|
---|
10 |
|
---|
11 | (function()
|
---|
12 | {
|
---|
13 | /**
|
---|
14 | * List of elements in which has no way to move editing focus outside.
|
---|
15 | */
|
---|
16 | var nonExitableElementNames = { table:1,pre:1 };
|
---|
17 | // Matching an empty paragraph at the end of document.
|
---|
18 | var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| | )\s*(:?<\/\1>)?\s*$/gi;
|
---|
19 |
|
---|
20 | function onInsertHtml( evt )
|
---|
21 | {
|
---|
22 | if ( this.mode == 'wysiwyg' )
|
---|
23 | {
|
---|
24 | this.focus();
|
---|
25 |
|
---|
26 | var selection = this.getSelection(),
|
---|
27 | data = evt.data;
|
---|
28 |
|
---|
29 | if ( this.dataProcessor )
|
---|
30 | data = this.dataProcessor.toHtml( data );
|
---|
31 |
|
---|
32 | if ( CKEDITOR.env.ie )
|
---|
33 | {
|
---|
34 | var selIsLocked = selection.isLocked;
|
---|
35 |
|
---|
36 | if ( selIsLocked )
|
---|
37 | selection.unlock();
|
---|
38 |
|
---|
39 | var $sel = selection.getNative();
|
---|
40 | if ( $sel.type == 'Control' )
|
---|
41 | $sel.clear();
|
---|
42 | $sel.createRange().pasteHTML( data );
|
---|
43 |
|
---|
44 | if ( selIsLocked )
|
---|
45 | this.getSelection().lock();
|
---|
46 | }
|
---|
47 | else
|
---|
48 | this.document.$.execCommand( 'inserthtml', false, data );
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | function onInsertElement( evt )
|
---|
53 | {
|
---|
54 | if ( this.mode == 'wysiwyg' )
|
---|
55 | {
|
---|
56 | this.focus();
|
---|
57 | this.fire( 'saveSnapshot' );
|
---|
58 |
|
---|
59 | var element = evt.data,
|
---|
60 | elementName = element.getName(),
|
---|
61 | isBlock = CKEDITOR.dtd.$block[ elementName ];
|
---|
62 |
|
---|
63 | var selection = this.getSelection(),
|
---|
64 | ranges = selection.getRanges();
|
---|
65 |
|
---|
66 | var selIsLocked = selection.isLocked;
|
---|
67 |
|
---|
68 | if ( selIsLocked )
|
---|
69 | selection.unlock();
|
---|
70 |
|
---|
71 | var range, clone, lastElement, bookmark;
|
---|
72 |
|
---|
73 | for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
|
---|
74 | {
|
---|
75 | range = ranges[ i ];
|
---|
76 |
|
---|
77 | // Remove the original contents.
|
---|
78 | range.deleteContents();
|
---|
79 |
|
---|
80 | clone = !i && element || element.clone( true );
|
---|
81 |
|
---|
82 | // If we're inserting a block at dtd-violated position, split
|
---|
83 | // the parent blocks until we reach blockLimit.
|
---|
84 | var current, dtd;
|
---|
85 | if ( isBlock )
|
---|
86 | {
|
---|
87 | while( ( current = range.getCommonAncestor( false, true ) )
|
---|
88 | && ( dtd = CKEDITOR.dtd[ current.getName() ] )
|
---|
89 | && !( dtd && dtd [ elementName ] ) )
|
---|
90 | {
|
---|
91 | // If we're in an empty block which indicate a new paragraph,
|
---|
92 | // simply replace it with the inserting block.(#3664)
|
---|
93 | if ( range.checkStartOfBlock()
|
---|
94 | && range.checkEndOfBlock() )
|
---|
95 | {
|
---|
96 | range.setStartBefore( current );
|
---|
97 | range.collapse( true );
|
---|
98 | current.remove();
|
---|
99 | }
|
---|
100 | else
|
---|
101 | range.splitBlock();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | // Insert the new node.
|
---|
106 | range.insertNode( clone );
|
---|
107 |
|
---|
108 | // Save the last element reference so we can make the
|
---|
109 | // selection later.
|
---|
110 | if ( !lastElement )
|
---|
111 | lastElement = clone;
|
---|
112 | }
|
---|
113 |
|
---|
114 | range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
|
---|
115 |
|
---|
116 | var next = lastElement.getNextSourceNode( true );
|
---|
117 | if ( next && next.type == CKEDITOR.NODE_ELEMENT )
|
---|
118 | range.moveToElementEditStart( next );
|
---|
119 |
|
---|
120 | selection.selectRanges( [ range ] );
|
---|
121 |
|
---|
122 | if ( selIsLocked )
|
---|
123 | this.getSelection().lock();
|
---|
124 |
|
---|
125 | // Save snaps after the whole execution completed.
|
---|
126 | // This's a workaround for make DOM modification's happened after
|
---|
127 | // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
|
---|
128 | // call.
|
---|
129 | CKEDITOR.tools.setTimeout( function(){
|
---|
130 | this.fire( 'saveSnapshot' );
|
---|
131 | }, 0, this );
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | // DOM modification here should not bother dirty flag.(#4385)
|
---|
136 | function restoreDirty( editor )
|
---|
137 | {
|
---|
138 | if( !editor.checkDirty() )
|
---|
139 | setTimeout( function(){ editor.resetDirty(); } );
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
|
---|
144 | * non-exitable-block by padding extra br.(#3189)
|
---|
145 | */
|
---|
146 | function onSelectionChangeFixBody( evt )
|
---|
147 | {
|
---|
148 | var editor = evt.editor,
|
---|
149 | path = evt.data.path,
|
---|
150 | blockLimit = path.blockLimit,
|
---|
151 | selection = evt.data.selection,
|
---|
152 | range = selection.getRanges()[0],
|
---|
153 | body = editor.document.getBody(),
|
---|
154 | enterMode = editor.config.enterMode;
|
---|
155 |
|
---|
156 | // When enterMode set to block, we'll establing new paragraph only if we're
|
---|
157 | // selecting inline contents right under body. (#3657)
|
---|
158 | if ( enterMode != CKEDITOR.ENTER_BR
|
---|
159 | && range.collapsed
|
---|
160 | && blockLimit.getName() == 'body'
|
---|
161 | && !path.block )
|
---|
162 | {
|
---|
163 | restoreDirty( editor );
|
---|
164 | var bms = selection.createBookmarks(),
|
---|
165 | fixedBlock = range.fixBlock( true,
|
---|
166 | editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
|
---|
167 |
|
---|
168 | // For IE, we'll be removing any bogus br ( introduce by fixing body )
|
---|
169 | // right now to prevent it introducing visual line break.
|
---|
170 | if ( CKEDITOR.env.ie )
|
---|
171 | {
|
---|
172 | var brNodeList = fixedBlock.getElementsByTag( 'br' ), brNode;
|
---|
173 | for ( var i = 0 ; i < brNodeList.count() ; i++ )
|
---|
174 | {
|
---|
175 | if( ( brNode = brNodeList.getItem( i ) ) && brNode.hasAttribute( '_cke_bogus' ) )
|
---|
176 | brNode.remove();
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | selection.selectBookmarks( bms );
|
---|
181 |
|
---|
182 | // If the fixed block is blank and is already followed by a exitable
|
---|
183 | // block, we should drop it and move to the exist block(#3684).
|
---|
184 | var children = fixedBlock.getChildren(),
|
---|
185 | count = children.count(),
|
---|
186 | firstChild,
|
---|
187 | whitespaceGuard = CKEDITOR.dom.walker.whitespaces( true ),
|
---|
188 | previousElement = fixedBlock.getPrevious( whitespaceGuard ),
|
---|
189 | nextElement = fixedBlock.getNext( whitespaceGuard ),
|
---|
190 | enterBlock;
|
---|
191 | if ( previousElement && previousElement.getName
|
---|
192 | && !( previousElement.getName() in nonExitableElementNames ) )
|
---|
193 | enterBlock = previousElement;
|
---|
194 | else if ( nextElement && nextElement.getName
|
---|
195 | && !( nextElement.getName() in nonExitableElementNames ) )
|
---|
196 | enterBlock = nextElement;
|
---|
197 |
|
---|
198 | // Not all blocks are editable, e.g. <hr />, further checking it.(#3994)
|
---|
199 | if( ( !count
|
---|
200 | || ( firstChild = children.getItem( 0 ) ) && firstChild.is && firstChild.is( 'br' ) )
|
---|
201 | && enterBlock
|
---|
202 | && range.moveToElementEditStart( enterBlock ) )
|
---|
203 | {
|
---|
204 | fixedBlock.remove();
|
---|
205 | range.select();
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Inserting the padding-br before body if it's preceded by an
|
---|
210 | // unexitable block.
|
---|
211 | var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
|
---|
212 | if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )
|
---|
213 | {
|
---|
214 | restoreDirty( editor );
|
---|
215 | var paddingBlock = editor.document.createElement(
|
---|
216 | ( CKEDITOR.env.ie && enterMode != CKEDITOR.ENTER_BR ) ?
|
---|
217 | '<br _cke_bogus="true" />' : 'br' );
|
---|
218 | body.append( paddingBlock );
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | CKEDITOR.plugins.add( 'wysiwygarea',
|
---|
223 | {
|
---|
224 | requires : [ 'editingblock' ],
|
---|
225 |
|
---|
226 | init : function( editor )
|
---|
227 | {
|
---|
228 | var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
|
---|
229 | ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
|
---|
230 |
|
---|
231 | editor.on( 'editingBlockReady', function()
|
---|
232 | {
|
---|
233 | var mainElement,
|
---|
234 | fieldset,
|
---|
235 | iframe,
|
---|
236 | isLoadingData,
|
---|
237 | isPendingFocus,
|
---|
238 | frameLoaded,
|
---|
239 | fireMode;
|
---|
240 |
|
---|
241 | // Support for custom document.domain in IE.
|
---|
242 | var isCustomDomain = CKEDITOR.env.isCustomDomain();
|
---|
243 |
|
---|
244 | // Creates the iframe that holds the editable document.
|
---|
245 | var createIFrame = function()
|
---|
246 | {
|
---|
247 | if ( iframe )
|
---|
248 | iframe.remove();
|
---|
249 | if ( fieldset )
|
---|
250 | fieldset.remove();
|
---|
251 |
|
---|
252 | frameLoaded = 0;
|
---|
253 | // The document domain must be set within the src
|
---|
254 | // attribute;
|
---|
255 | // Defer the script execution until iframe
|
---|
256 | // has been added to main window, this is needed for some
|
---|
257 | // browsers which will begin to load the frame content
|
---|
258 | // prior to it's presentation in DOM.(#3894)
|
---|
259 | var src = 'void( '
|
---|
260 | + ( CKEDITOR.env.gecko ? 'setTimeout' : '' ) + '( function(){' +
|
---|
261 | 'document.open();' +
|
---|
262 | ( CKEDITOR.env.ie && isCustomDomain ? 'document.domain="' + document.domain + '";' : '' ) +
|
---|
263 | 'document.write( window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] );' +
|
---|
264 | 'document.close();' +
|
---|
265 | 'window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] = null;' +
|
---|
266 | '}'
|
---|
267 | + ( CKEDITOR.env.gecko ? ', 0 )' : ')()' )
|
---|
268 | + ' )';
|
---|
269 |
|
---|
270 | // Loading via src attribute does not work in Opera.
|
---|
271 | if ( CKEDITOR.env.opera )
|
---|
272 | src = 'void(0);';
|
---|
273 |
|
---|
274 | iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
|
---|
275 | ' style="width:100%;height:100%"' +
|
---|
276 | ' frameBorder="0"' +
|
---|
277 | ' tabIndex="-1"' +
|
---|
278 | ' allowTransparency="true"' +
|
---|
279 | ' src="javascript:' + encodeURIComponent( src ) + '"' +
|
---|
280 | '></iframe>' );
|
---|
281 |
|
---|
282 | var accTitle = editor.lang.editorTitle.replace( '%1', editor.name );
|
---|
283 |
|
---|
284 | if ( CKEDITOR.env.gecko )
|
---|
285 | {
|
---|
286 | // Double checking the iframe will be loaded properly(#4058).
|
---|
287 | iframe.on( 'load', function( ev )
|
---|
288 | {
|
---|
289 | ev.removeListener();
|
---|
290 | contentDomReady( iframe.$.contentWindow );
|
---|
291 | } );
|
---|
292 |
|
---|
293 | // Accessibility attributes for Firefox.
|
---|
294 | mainElement.setAttributes(
|
---|
295 | {
|
---|
296 | role : 'region',
|
---|
297 | title : accTitle
|
---|
298 | } );
|
---|
299 | iframe.setAttributes(
|
---|
300 | {
|
---|
301 | role : 'region',
|
---|
302 | title : ' '
|
---|
303 | } );
|
---|
304 | }
|
---|
305 | else if ( CKEDITOR.env.webkit )
|
---|
306 | {
|
---|
307 | iframe.setAttribute( 'title', accTitle ); // Safari 4
|
---|
308 | iframe.setAttribute( 'name', accTitle ); // Safari 3
|
---|
309 | }
|
---|
310 | else if ( CKEDITOR.env.ie )
|
---|
311 | {
|
---|
312 | // Accessibility label for IE.
|
---|
313 | fieldset = CKEDITOR.dom.element.createFromHtml(
|
---|
314 | '<fieldset style="height:100%' +
|
---|
315 | ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? ';position:relative' : '' ) +
|
---|
316 | '">' +
|
---|
317 | '<legend style="display:block;width:0;height:0;overflow:hidden;' +
|
---|
318 | ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? 'position:absolute' : '' ) +
|
---|
319 | '">' +
|
---|
320 | CKEDITOR.tools.htmlEncode( accTitle ) +
|
---|
321 | '</legend>' +
|
---|
322 | '</fieldset>'
|
---|
323 | , CKEDITOR.document );
|
---|
324 | iframe.appendTo( fieldset );
|
---|
325 | fieldset.appendTo( mainElement );
|
---|
326 | }
|
---|
327 |
|
---|
328 | if ( !CKEDITOR.env.ie )
|
---|
329 | mainElement.append( iframe );
|
---|
330 | };
|
---|
331 |
|
---|
332 | // The script that is appended to the data being loaded. It
|
---|
333 | // enables editing, and makes some
|
---|
334 | var activationScript =
|
---|
335 | '<script id="cke_actscrpt" type="text/javascript">' +
|
---|
336 | 'window.onload = function()' +
|
---|
337 | '{' +
|
---|
338 | // Call the temporary function for the editing
|
---|
339 | // boostrap.
|
---|
340 | 'window.parent.CKEDITOR._["contentDomReady' + editor.name + '"]( window );' +
|
---|
341 | '}' +
|
---|
342 | '</script>';
|
---|
343 |
|
---|
344 | // Editing area bootstrap code.
|
---|
345 | var contentDomReady = function( domWindow )
|
---|
346 | {
|
---|
347 | if ( frameLoaded )
|
---|
348 | return;
|
---|
349 |
|
---|
350 | frameLoaded = 1;
|
---|
351 |
|
---|
352 | var domDocument = domWindow.document,
|
---|
353 | body = domDocument.body;
|
---|
354 |
|
---|
355 | // Remove this script from the DOM.
|
---|
356 | var script = domDocument.getElementById( "cke_actscrpt" );
|
---|
357 | script.parentNode.removeChild( script );
|
---|
358 |
|
---|
359 | delete CKEDITOR._[ 'contentDomReady' + editor.name ];
|
---|
360 |
|
---|
361 | body.spellcheck = !editor.config.disableNativeSpellChecker;
|
---|
362 |
|
---|
363 | if ( CKEDITOR.env.ie )
|
---|
364 | {
|
---|
365 | // Don't display the focus border.
|
---|
366 | body.hideFocus = true;
|
---|
367 |
|
---|
368 | // Disable and re-enable the body to avoid IE from
|
---|
369 | // taking the editing focus at startup. (#141 / #523)
|
---|
370 | body.disabled = true;
|
---|
371 | body.contentEditable = true;
|
---|
372 | body.removeAttribute( 'disabled' );
|
---|
373 | }
|
---|
374 | else
|
---|
375 | domDocument.designMode = 'on';
|
---|
376 |
|
---|
377 | // IE, Opera and Safari may not support it and throw
|
---|
378 | // errors.
|
---|
379 | try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
|
---|
380 | try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
|
---|
381 |
|
---|
382 | domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
|
---|
383 | domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
|
---|
384 |
|
---|
385 | // Gecko/Webkit need some help when selecting control type elements. (#3448)
|
---|
386 | if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )
|
---|
387 | {
|
---|
388 | domDocument.on( 'mousedown', function( ev )
|
---|
389 | {
|
---|
390 | var control = ev.data.getTarget();
|
---|
391 | if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
|
---|
392 | editor.getSelection().selectElement( control );
|
---|
393 | } );
|
---|
394 | }
|
---|
395 |
|
---|
396 | // Webkit: avoid from editing form control elements content.
|
---|
397 | if ( CKEDITOR.env.webkit )
|
---|
398 | {
|
---|
399 | // Prevent from tick checkbox/radiobox/select
|
---|
400 | domDocument.on( 'click', function( ev )
|
---|
401 | {
|
---|
402 | if ( ev.data.getTarget().is( 'input', 'select' ) )
|
---|
403 | ev.data.preventDefault();
|
---|
404 | } );
|
---|
405 |
|
---|
406 | // Prevent from editig textfield/textarea value.
|
---|
407 | domDocument.on( 'mouseup', function( ev )
|
---|
408 | {
|
---|
409 | if ( ev.data.getTarget().is( 'input', 'textarea' ) )
|
---|
410 | ev.data.preventDefault();
|
---|
411 | } );
|
---|
412 | }
|
---|
413 |
|
---|
414 | var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?
|
---|
415 | domWindow : domDocument;
|
---|
416 |
|
---|
417 | focusTarget.on( 'blur', function()
|
---|
418 | {
|
---|
419 | editor.focusManager.blur();
|
---|
420 | });
|
---|
421 |
|
---|
422 | focusTarget.on( 'focus', function()
|
---|
423 | {
|
---|
424 | // Gecko need a key event to 'wake up' the editing
|
---|
425 | // ability when document is empty.(#3864)
|
---|
426 | if ( CKEDITOR.env.gecko )
|
---|
427 | {
|
---|
428 | var first = body;
|
---|
429 | while( first.firstChild )
|
---|
430 | first = first.firstChild;
|
---|
431 |
|
---|
432 | if( !first.nextSibling
|
---|
433 | && ( 'BR' == first.tagName )
|
---|
434 | && first.hasAttribute( '_moz_editor_bogus_node' ) )
|
---|
435 | {
|
---|
436 | var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );
|
---|
437 | keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,
|
---|
438 | false, false, false, 0, 32 );
|
---|
439 | domDocument.$.dispatchEvent( keyEventSimulate );
|
---|
440 | var bogusText = domDocument.getBody().getFirst() ;
|
---|
441 | // Compensate the line maintaining <br> if enterMode is not block.
|
---|
442 | if ( editor.config.enterMode == CKEDITOR.ENTER_BR )
|
---|
443 | domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )
|
---|
444 | .replace( bogusText );
|
---|
445 | else
|
---|
446 | bogusText.remove();
|
---|
447 | }
|
---|
448 | }
|
---|
449 |
|
---|
450 | editor.focusManager.focus();
|
---|
451 | });
|
---|
452 |
|
---|
453 | var keystrokeHandler = editor.keystrokeHandler;
|
---|
454 | if ( keystrokeHandler )
|
---|
455 | keystrokeHandler.attach( domDocument );
|
---|
456 |
|
---|
457 | // Cancel default action for backspace in IE on control types. (#4047)
|
---|
458 | if ( CKEDITOR.env.ie )
|
---|
459 | {
|
---|
460 | editor.on( 'key', function( event )
|
---|
461 | {
|
---|
462 | // Backspace.
|
---|
463 | var control = event.data.keyCode == 8
|
---|
464 | && editor.getSelection().getSelectedElement();
|
---|
465 | if ( control )
|
---|
466 | {
|
---|
467 | // Make undo snapshot.
|
---|
468 | editor.fire( 'saveSnapshot' );
|
---|
469 | // Remove manually.
|
---|
470 | control.remove();
|
---|
471 | editor.fire( 'saveSnapshot' );
|
---|
472 | event.cancel();
|
---|
473 | }
|
---|
474 | } );
|
---|
475 | }
|
---|
476 |
|
---|
477 | // Adds the document body as a context menu target.
|
---|
478 | if ( editor.contextMenu )
|
---|
479 | editor.contextMenu.addTarget( domDocument );
|
---|
480 |
|
---|
481 | setTimeout( function()
|
---|
482 | {
|
---|
483 | editor.fire( 'contentDom' );
|
---|
484 |
|
---|
485 | if ( fireMode )
|
---|
486 | {
|
---|
487 | editor.mode = 'wysiwyg';
|
---|
488 | editor.fire( 'mode' );
|
---|
489 | fireMode = false;
|
---|
490 | }
|
---|
491 |
|
---|
492 | isLoadingData = false;
|
---|
493 |
|
---|
494 | if ( isPendingFocus )
|
---|
495 | {
|
---|
496 | editor.focus();
|
---|
497 | isPendingFocus = false;
|
---|
498 | }
|
---|
499 | setTimeout( function()
|
---|
500 | {
|
---|
501 | editor.fire( 'dataReady' );
|
---|
502 | }, 0 );
|
---|
503 |
|
---|
504 | /*
|
---|
505 | * IE BUG: IE might have rendered the iframe with invisible contents.
|
---|
506 | * (#3623). Push some inconsequential CSS style changes to force IE to
|
---|
507 | * refresh it.
|
---|
508 | *
|
---|
509 | * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
|
---|
510 | * fix the problem. :(
|
---|
511 | */
|
---|
512 | if ( CKEDITOR.env.ie )
|
---|
513 | {
|
---|
514 | setTimeout( function()
|
---|
515 | {
|
---|
516 | if ( editor.document )
|
---|
517 | {
|
---|
518 | var $body = editor.document.$.body;
|
---|
519 | $body.runtimeStyle.marginBottom = '0px';
|
---|
520 | $body.runtimeStyle.marginBottom = '';
|
---|
521 | }
|
---|
522 | }, 1000 );
|
---|
523 | }
|
---|
524 | },
|
---|
525 | 0 );
|
---|
526 | };
|
---|
527 |
|
---|
528 | editor.addMode( 'wysiwyg',
|
---|
529 | {
|
---|
530 | load : function( holderElement, data, isSnapshot )
|
---|
531 | {
|
---|
532 | mainElement = holderElement;
|
---|
533 |
|
---|
534 | if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
|
---|
535 | holderElement.setStyle( 'position', 'relative' );
|
---|
536 |
|
---|
537 | // The editor data "may be dirty" after this
|
---|
538 | // point.
|
---|
539 | editor.mayBeDirty = true;
|
---|
540 |
|
---|
541 | fireMode = true;
|
---|
542 |
|
---|
543 | if ( isSnapshot )
|
---|
544 | this.loadSnapshotData( data );
|
---|
545 | else
|
---|
546 | this.loadData( data );
|
---|
547 | },
|
---|
548 |
|
---|
549 | loadData : function( data )
|
---|
550 | {
|
---|
551 | isLoadingData = true;
|
---|
552 |
|
---|
553 | // Get the HTML version of the data.
|
---|
554 | if ( editor.dataProcessor )
|
---|
555 | {
|
---|
556 | data = editor.dataProcessor.toHtml( data, fixForBody );
|
---|
557 | }
|
---|
558 |
|
---|
559 | data =
|
---|
560 | editor.config.docType +
|
---|
561 | '<html dir="' + editor.config.contentsLangDirection + '">' +
|
---|
562 | '<head>' +
|
---|
563 | '<link type="text/css" rel="stylesheet" href="' +
|
---|
564 | [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +
|
---|
565 | '">' +
|
---|
566 | '<style type="text/css" _fcktemp="true">' +
|
---|
567 | editor._.styles.join( '\n' ) +
|
---|
568 | '</style>'+
|
---|
569 | '</head>' +
|
---|
570 | '<body>' +
|
---|
571 | data +
|
---|
572 | '</body>' +
|
---|
573 | '</html>' +
|
---|
574 | activationScript;
|
---|
575 |
|
---|
576 | window[ '_cke_htmlToLoad_' + editor.name ] = data;
|
---|
577 | CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;
|
---|
578 | createIFrame();
|
---|
579 |
|
---|
580 | // Opera must use the old method for loading contents.
|
---|
581 | if ( CKEDITOR.env.opera )
|
---|
582 | {
|
---|
583 | var doc = iframe.$.contentWindow.document;
|
---|
584 | doc.open();
|
---|
585 | doc.write( data );
|
---|
586 | doc.close();
|
---|
587 | }
|
---|
588 | },
|
---|
589 |
|
---|
590 | getData : function()
|
---|
591 | {
|
---|
592 | var data = iframe.getFrameDocument().getBody().getHtml();
|
---|
593 |
|
---|
594 | if ( editor.dataProcessor )
|
---|
595 | data = editor.dataProcessor.toDataFormat( data, fixForBody );
|
---|
596 |
|
---|
597 | // Strip the last blank paragraph within document.
|
---|
598 | if ( editor.config.ignoreEmptyParagraph )
|
---|
599 | data = data.replace( emptyParagraphRegexp, '' );
|
---|
600 |
|
---|
601 | return data;
|
---|
602 | },
|
---|
603 |
|
---|
604 | getSnapshotData : function()
|
---|
605 | {
|
---|
606 | return iframe.getFrameDocument().getBody().getHtml();
|
---|
607 | },
|
---|
608 |
|
---|
609 | loadSnapshotData : function( data )
|
---|
610 | {
|
---|
611 | iframe.getFrameDocument().getBody().setHtml( data );
|
---|
612 | },
|
---|
613 |
|
---|
614 | unload : function( holderElement )
|
---|
615 | {
|
---|
616 | editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
|
---|
617 |
|
---|
618 | editor.fire( 'contentDomUnload' );
|
---|
619 | },
|
---|
620 |
|
---|
621 | focus : function()
|
---|
622 | {
|
---|
623 | if ( isLoadingData )
|
---|
624 | isPendingFocus = true;
|
---|
625 | else if ( editor.window )
|
---|
626 | {
|
---|
627 | editor.window.focus();
|
---|
628 | editor.selectionChange();
|
---|
629 | }
|
---|
630 | }
|
---|
631 | });
|
---|
632 |
|
---|
633 | editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
|
---|
634 | editor.on( 'insertElement', onInsertElement, null, null, 20 );
|
---|
635 | // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
|
---|
636 | editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
|
---|
637 | });
|
---|
638 | }
|
---|
639 | });
|
---|
640 | })();
|
---|
641 |
|
---|
642 | /**
|
---|
643 | * Disables the ability of resize objects (image and tables) in the editing
|
---|
644 | * area.
|
---|
645 | * @type Boolean
|
---|
646 | * @default false
|
---|
647 | * @example
|
---|
648 | * config.disableObjectResizing = true;
|
---|
649 | */
|
---|
650 | CKEDITOR.config.disableObjectResizing = false;
|
---|
651 |
|
---|
652 | /**
|
---|
653 | * Disables the "table tools" offered natively by the browser (currently
|
---|
654 | * Firefox only) to make quick table editing operations, like adding or
|
---|
655 | * deleting rows and columns.
|
---|
656 | * @type Boolean
|
---|
657 | * @default true
|
---|
658 | * @example
|
---|
659 | * config.disableNativeTableHandles = false;
|
---|
660 | */
|
---|
661 | CKEDITOR.config.disableNativeTableHandles = true;
|
---|
662 |
|
---|
663 | /**
|
---|
664 | * Disables the built-in spell checker while typing natively available in the
|
---|
665 | * browser (currently Firefox and Safari only).<br /><br />
|
---|
666 | *
|
---|
667 | * Even if word suggestions will not appear in the CKEditor context menu, this
|
---|
668 | * feature is useful to help quickly identifying misspelled words.<br /><br />
|
---|
669 | *
|
---|
670 | * This setting is currently compatible with Firefox only due to limitations in
|
---|
671 | * other browsers.
|
---|
672 | * @type Boolean
|
---|
673 | * @default true
|
---|
674 | * @example
|
---|
675 | * config.disableNativeSpellChecker = false;
|
---|
676 | */
|
---|
677 | CKEDITOR.config.disableNativeSpellChecker = true;
|
---|
678 |
|
---|
679 | /**
|
---|
680 | * Whether the editor must output an empty value ("") if it's contents is made
|
---|
681 | * by an empty paragraph only.
|
---|
682 | * @type Boolean
|
---|
683 | * @default true
|
---|
684 | * @example
|
---|
685 | * config.ignoreEmptyParagraph = false;
|
---|
686 | */
|
---|
687 | CKEDITOR.config.ignoreEmptyParagraph = true;
|
---|