1 | /*
|
---|
2 | Copyright (c) 2003-2010, 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 | // List of elements in which has no way to move editing focus outside.
|
---|
14 | var nonExitableElementNames = { table:1,pre:1 };
|
---|
15 |
|
---|
16 | // Matching an empty paragraph at the end of document.
|
---|
17 | var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| |\u00A0| )?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi;
|
---|
18 |
|
---|
19 | function onInsertHtml( evt )
|
---|
20 | {
|
---|
21 | if ( this.mode == 'wysiwyg' )
|
---|
22 | {
|
---|
23 | this.focus();
|
---|
24 | this.fire( 'saveSnapshot' );
|
---|
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 | CKEDITOR.tools.setTimeout( function()
|
---|
51 | {
|
---|
52 | this.fire( 'saveSnapshot' );
|
---|
53 | }, 0, this );
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | function onInsertElement( evt )
|
---|
58 | {
|
---|
59 | if ( this.mode == 'wysiwyg' )
|
---|
60 | {
|
---|
61 | this.focus();
|
---|
62 | this.fire( 'saveSnapshot' );
|
---|
63 |
|
---|
64 | var element = evt.data,
|
---|
65 | elementName = element.getName(),
|
---|
66 | isBlock = CKEDITOR.dtd.$block[ elementName ];
|
---|
67 |
|
---|
68 | var selection = this.getSelection(),
|
---|
69 | ranges = selection.getRanges();
|
---|
70 |
|
---|
71 | var selIsLocked = selection.isLocked;
|
---|
72 |
|
---|
73 | if ( selIsLocked )
|
---|
74 | selection.unlock();
|
---|
75 |
|
---|
76 | var range, clone, lastElement, bookmark;
|
---|
77 |
|
---|
78 | for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
|
---|
79 | {
|
---|
80 | range = ranges[ i ];
|
---|
81 |
|
---|
82 | // Remove the original contents.
|
---|
83 | range.deleteContents();
|
---|
84 |
|
---|
85 | clone = !i && element || element.clone( true );
|
---|
86 |
|
---|
87 | // If we're inserting a block at dtd-violated position, split
|
---|
88 | // the parent blocks until we reach blockLimit.
|
---|
89 | var current, dtd;
|
---|
90 | if ( isBlock )
|
---|
91 | {
|
---|
92 | while ( ( current = range.getCommonAncestor( false, true ) )
|
---|
93 | && ( dtd = CKEDITOR.dtd[ current.getName() ] )
|
---|
94 | && !( dtd && dtd [ elementName ] ) )
|
---|
95 | {
|
---|
96 | // Split up inline elements.
|
---|
97 | if ( current.getName() in CKEDITOR.dtd.span )
|
---|
98 | range.splitElement( current );
|
---|
99 | // If we're in an empty block which indicate a new paragraph,
|
---|
100 | // simply replace it with the inserting block.(#3664)
|
---|
101 | else if ( range.checkStartOfBlock()
|
---|
102 | && range.checkEndOfBlock() )
|
---|
103 | {
|
---|
104 | range.setStartBefore( current );
|
---|
105 | range.collapse( true );
|
---|
106 | current.remove();
|
---|
107 | }
|
---|
108 | else
|
---|
109 | range.splitBlock();
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | // Insert the new node.
|
---|
114 | range.insertNode( clone );
|
---|
115 |
|
---|
116 | // Save the last element reference so we can make the
|
---|
117 | // selection later.
|
---|
118 | if ( !lastElement )
|
---|
119 | lastElement = clone;
|
---|
120 | }
|
---|
121 |
|
---|
122 | range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
|
---|
123 |
|
---|
124 | var next = lastElement.getNextSourceNode( true );
|
---|
125 | if ( next && next.type == CKEDITOR.NODE_ELEMENT )
|
---|
126 | range.moveToElementEditStart( next );
|
---|
127 |
|
---|
128 | selection.selectRanges( [ range ] );
|
---|
129 |
|
---|
130 | if ( selIsLocked )
|
---|
131 | this.getSelection().lock();
|
---|
132 |
|
---|
133 | // Save snaps after the whole execution completed.
|
---|
134 | // This's a workaround for make DOM modification's happened after
|
---|
135 | // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
|
---|
136 | // call.
|
---|
137 | CKEDITOR.tools.setTimeout( function(){
|
---|
138 | this.fire( 'saveSnapshot' );
|
---|
139 | }, 0, this );
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | // DOM modification here should not bother dirty flag.(#4385)
|
---|
144 | function restoreDirty( editor )
|
---|
145 | {
|
---|
146 | if ( !editor.checkDirty() )
|
---|
147 | setTimeout( function(){ editor.resetDirty(); } );
|
---|
148 | }
|
---|
149 |
|
---|
150 | var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
|
---|
151 | isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
|
---|
152 |
|
---|
153 | function isNotEmpty( node )
|
---|
154 | {
|
---|
155 | return isNotWhitespace( node ) && isNotBookmark( node );
|
---|
156 | }
|
---|
157 |
|
---|
158 | function isNbsp( node )
|
---|
159 | {
|
---|
160 | return node.type == CKEDITOR.NODE_TEXT
|
---|
161 | && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
|
---|
162 | }
|
---|
163 |
|
---|
164 | function restoreSelection( selection )
|
---|
165 | {
|
---|
166 | if ( selection.isLocked )
|
---|
167 | {
|
---|
168 | selection.unlock();
|
---|
169 | setTimeout( function() { selection.lock(); }, 0 );
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
|
---|
175 | * non-exitable-block by padding extra br.(#3189)
|
---|
176 | */
|
---|
177 | function onSelectionChangeFixBody( evt )
|
---|
178 | {
|
---|
179 | var editor = evt.editor,
|
---|
180 | path = evt.data.path,
|
---|
181 | blockLimit = path.blockLimit,
|
---|
182 | selection = evt.data.selection,
|
---|
183 | range = selection.getRanges()[0],
|
---|
184 | body = editor.document.getBody(),
|
---|
185 | enterMode = editor.config.enterMode;
|
---|
186 |
|
---|
187 | // When enterMode set to block, we'll establing new paragraph only if we're
|
---|
188 | // selecting inline contents right under body. (#3657)
|
---|
189 | if ( enterMode != CKEDITOR.ENTER_BR
|
---|
190 | && range.collapsed
|
---|
191 | && blockLimit.getName() == 'body'
|
---|
192 | && !path.block )
|
---|
193 | {
|
---|
194 | restoreDirty( editor );
|
---|
195 | CKEDITOR.env.ie && restoreSelection( selection );
|
---|
196 |
|
---|
197 | var fixedBlock = range.fixBlock( true,
|
---|
198 | editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
|
---|
199 |
|
---|
200 | // For IE, we should remove any filler node which was introduced before.
|
---|
201 | if ( CKEDITOR.env.ie )
|
---|
202 | {
|
---|
203 | var first = fixedBlock.getFirst( isNotEmpty );
|
---|
204 | first && isNbsp( first ) && first.remove();
|
---|
205 | }
|
---|
206 |
|
---|
207 | // If the fixed block is blank and already followed by a exitable
|
---|
208 | // block, we should revert the fix. (#3684)
|
---|
209 | if ( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )
|
---|
210 | {
|
---|
211 | var previousElement = fixedBlock.getPrevious( isNotWhitespace ),
|
---|
212 | nextElement = fixedBlock.getNext( isNotWhitespace );
|
---|
213 |
|
---|
214 | if ( previousElement && previousElement.getName
|
---|
215 | && !( previousElement.getName() in nonExitableElementNames )
|
---|
216 | && range.moveToElementEditStart( previousElement )
|
---|
217 | || nextElement && nextElement.getName
|
---|
218 | && !( nextElement.getName() in nonExitableElementNames )
|
---|
219 | && range.moveToElementEditStart( nextElement ) )
|
---|
220 | {
|
---|
221 | fixedBlock.remove();
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | range.select();
|
---|
226 | // Notify non-IE that selection has changed.
|
---|
227 | if ( !CKEDITOR.env.ie )
|
---|
228 | editor.selectionChange();
|
---|
229 | }
|
---|
230 |
|
---|
231 | // All browsers are incapable to moving cursor out of certain non-exitable
|
---|
232 | // blocks (e.g. table, list, pre) at the end of document, make this happen by
|
---|
233 | // place a bogus node there, which would be later removed by dataprocessor.
|
---|
234 | var walkerRange = new CKEDITOR.dom.range( editor.document ),
|
---|
235 | walker = new CKEDITOR.dom.walker( walkerRange );
|
---|
236 | walkerRange.selectNodeContents( body );
|
---|
237 | walker.evaluator = function( node )
|
---|
238 | {
|
---|
239 | return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
|
---|
240 | };
|
---|
241 | walker.guard = function( node, isMoveout )
|
---|
242 | {
|
---|
243 | return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
|
---|
244 | };
|
---|
245 |
|
---|
246 | if ( walker.previous() )
|
---|
247 | {
|
---|
248 | restoreDirty( editor );
|
---|
249 | CKEDITOR.env.ie && restoreSelection( selection );
|
---|
250 |
|
---|
251 | var paddingBlock;
|
---|
252 | if ( enterMode != CKEDITOR.ENTER_BR )
|
---|
253 | paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
|
---|
254 | else
|
---|
255 | paddingBlock = body;
|
---|
256 |
|
---|
257 | if ( !CKEDITOR.env.ie )
|
---|
258 | paddingBlock.appendBogus();
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | CKEDITOR.plugins.add( 'wysiwygarea',
|
---|
263 | {
|
---|
264 | requires : [ 'editingblock' ],
|
---|
265 |
|
---|
266 | init : function( editor )
|
---|
267 | {
|
---|
268 | var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
|
---|
269 | ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
|
---|
270 |
|
---|
271 | var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
|
---|
272 |
|
---|
273 | editor.on( 'editingBlockReady', function()
|
---|
274 | {
|
---|
275 | var mainElement,
|
---|
276 | iframe,
|
---|
277 | isLoadingData,
|
---|
278 | isPendingFocus,
|
---|
279 | frameLoaded,
|
---|
280 | fireMode;
|
---|
281 |
|
---|
282 |
|
---|
283 | // Support for custom document.domain in IE.
|
---|
284 | var isCustomDomain = CKEDITOR.env.isCustomDomain();
|
---|
285 |
|
---|
286 | // Creates the iframe that holds the editable document.
|
---|
287 | var createIFrame = function( data )
|
---|
288 | {
|
---|
289 | if ( iframe )
|
---|
290 | iframe.remove();
|
---|
291 |
|
---|
292 | frameLoaded = 0;
|
---|
293 |
|
---|
294 | var setDataFn = !CKEDITOR.env.gecko && CKEDITOR.tools.addFunction( function( doc )
|
---|
295 | {
|
---|
296 | CKEDITOR.tools.removeFunction( setDataFn );
|
---|
297 | doc.write( data );
|
---|
298 | });
|
---|
299 |
|
---|
300 | var srcScript =
|
---|
301 | 'document.open();' +
|
---|
302 |
|
---|
303 | // The document domain must be set any time we
|
---|
304 | // call document.open().
|
---|
305 | ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
|
---|
306 |
|
---|
307 | ( ( 'parent.CKEDITOR.tools.callFunction(' + setDataFn + ',document);' ) ) +
|
---|
308 |
|
---|
309 | 'document.close();';
|
---|
310 |
|
---|
311 | iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
|
---|
312 | ' style="width:100%;height:100%"' +
|
---|
313 | ' frameBorder="0"' +
|
---|
314 | ' title="' + frameLabel + '"' +
|
---|
315 | // With FF, the 'src' attribute should be left empty to
|
---|
316 | // trigger iframe's 'load' event.
|
---|
317 | ' src="' + ( CKEDITOR.env.gecko ? '' : 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' ) + '"' +
|
---|
318 | ' tabIndex="' + editor.tabIndex + '"' +
|
---|
319 | ' allowTransparency="true"' +
|
---|
320 | '></iframe>' );
|
---|
321 |
|
---|
322 | // With FF, it's better to load the data on iframe.load. (#3894,#4058)
|
---|
323 | CKEDITOR.env.gecko && iframe.on( 'load', function( ev )
|
---|
324 | {
|
---|
325 | ev.removeListener();
|
---|
326 |
|
---|
327 | var doc = iframe.getFrameDocument().$;
|
---|
328 |
|
---|
329 | doc.open();
|
---|
330 | doc.write( data );
|
---|
331 | doc.close();
|
---|
332 | });
|
---|
333 |
|
---|
334 | mainElement.append( iframe );
|
---|
335 | };
|
---|
336 |
|
---|
337 | // The script that launches the bootstrap logic on 'domReady', so the document
|
---|
338 | // is fully editable even before the editing iframe is fully loaded (#4455).
|
---|
339 | var activationScript =
|
---|
340 | '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
|
---|
341 | ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
|
---|
342 | 'parent.CKEDITOR._["contentDomReady' + editor.name + '"]( window );' +
|
---|
343 | '</script>';
|
---|
344 |
|
---|
345 | // Editing area bootstrap code.
|
---|
346 | var contentDomReady = function( domWindow )
|
---|
347 | {
|
---|
348 | if ( frameLoaded )
|
---|
349 | return;
|
---|
350 | frameLoaded = 1;
|
---|
351 |
|
---|
352 | editor.fire( 'ariaWidget', iframe );
|
---|
353 |
|
---|
354 | var domDocument = domWindow.document,
|
---|
355 | body = domDocument.body;
|
---|
356 |
|
---|
357 | // Remove this script from the DOM.
|
---|
358 | var script = domDocument.getElementById( "cke_actscrpt" );
|
---|
359 | script.parentNode.removeChild( script );
|
---|
360 |
|
---|
361 | delete CKEDITOR._[ 'contentDomReady' + editor.name ];
|
---|
362 |
|
---|
363 | body.spellcheck = !editor.config.disableNativeSpellChecker;
|
---|
364 |
|
---|
365 | if ( CKEDITOR.env.ie )
|
---|
366 | {
|
---|
367 | // Don't display the focus border.
|
---|
368 | body.hideFocus = true;
|
---|
369 |
|
---|
370 | // Disable and re-enable the body to avoid IE from
|
---|
371 | // taking the editing focus at startup. (#141 / #523)
|
---|
372 | body.disabled = true;
|
---|
373 | body.contentEditable = true;
|
---|
374 | body.removeAttribute( 'disabled' );
|
---|
375 | }
|
---|
376 | else
|
---|
377 | domDocument.designMode = 'on';
|
---|
378 |
|
---|
379 | // IE, Opera and Safari may not support it and throw
|
---|
380 | // errors.
|
---|
381 | try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
|
---|
382 | try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
|
---|
383 |
|
---|
384 | domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
|
---|
385 | domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
|
---|
386 |
|
---|
387 | // Gecko/Webkit need some help when selecting control type elements. (#3448)
|
---|
388 | if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )
|
---|
389 | {
|
---|
390 | domDocument.on( 'mousedown', function( ev )
|
---|
391 | {
|
---|
392 | var control = ev.data.getTarget();
|
---|
393 | if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
|
---|
394 | editor.getSelection().selectElement( control );
|
---|
395 | } );
|
---|
396 | }
|
---|
397 |
|
---|
398 | // Webkit: avoid from editing form control elements content.
|
---|
399 | if ( CKEDITOR.env.webkit )
|
---|
400 | {
|
---|
401 | // Prevent from tick checkbox/radiobox/select
|
---|
402 | domDocument.on( 'click', function( ev )
|
---|
403 | {
|
---|
404 | if ( ev.data.getTarget().is( 'input', 'select' ) )
|
---|
405 | ev.data.preventDefault();
|
---|
406 | } );
|
---|
407 |
|
---|
408 | // Prevent from editig textfield/textarea value.
|
---|
409 | domDocument.on( 'mouseup', function( ev )
|
---|
410 | {
|
---|
411 | if ( ev.data.getTarget().is( 'input', 'textarea' ) )
|
---|
412 | ev.data.preventDefault();
|
---|
413 | } );
|
---|
414 | }
|
---|
415 |
|
---|
416 | // IE standard compliant in editing frame doesn't focus the editor when
|
---|
417 | // clicking outside actual content, manually apply the focus. (#1659)
|
---|
418 | if ( CKEDITOR.env.ie
|
---|
419 | && domDocument.$.compatMode == 'CSS1Compat' )
|
---|
420 | {
|
---|
421 | var htmlElement = domDocument.getDocumentElement();
|
---|
422 | htmlElement.on( 'mousedown', function( evt )
|
---|
423 | {
|
---|
424 | // Setting focus directly on editor doesn't work, we
|
---|
425 | // have to use here a temporary element to 'redirect'
|
---|
426 | // the focus.
|
---|
427 | if ( evt.data.getTarget().equals( htmlElement ) )
|
---|
428 | ieFocusGrabber.focus();
|
---|
429 | } );
|
---|
430 | }
|
---|
431 |
|
---|
432 | var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?
|
---|
433 | domWindow : domDocument;
|
---|
434 |
|
---|
435 | focusTarget.on( 'blur', function()
|
---|
436 | {
|
---|
437 | editor.focusManager.blur();
|
---|
438 | });
|
---|
439 |
|
---|
440 | focusTarget.on( 'focus', function()
|
---|
441 | {
|
---|
442 | // Gecko need a key event to 'wake up' the editing
|
---|
443 | // ability when document is empty.(#3864)
|
---|
444 | if ( CKEDITOR.env.gecko )
|
---|
445 | {
|
---|
446 | var first = body;
|
---|
447 | while ( first.firstChild )
|
---|
448 | first = first.firstChild;
|
---|
449 |
|
---|
450 | if ( !first.nextSibling
|
---|
451 | && ( 'BR' == first.tagName )
|
---|
452 | && first.hasAttribute( '_moz_editor_bogus_node' ) )
|
---|
453 | {
|
---|
454 | restoreDirty( editor );
|
---|
455 | var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );
|
---|
456 | keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,
|
---|
457 | false, false, false, 0, 32 );
|
---|
458 | domDocument.$.dispatchEvent( keyEventSimulate );
|
---|
459 | var bogusText = domDocument.getBody().getFirst() ;
|
---|
460 | // Compensate the line maintaining <br> if enterMode is not block.
|
---|
461 | if ( editor.config.enterMode == CKEDITOR.ENTER_BR )
|
---|
462 | domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )
|
---|
463 | .replace( bogusText );
|
---|
464 | else
|
---|
465 | bogusText.remove();
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | editor.focusManager.focus();
|
---|
470 | });
|
---|
471 |
|
---|
472 | var keystrokeHandler = editor.keystrokeHandler;
|
---|
473 | if ( keystrokeHandler )
|
---|
474 | keystrokeHandler.attach( domDocument );
|
---|
475 |
|
---|
476 | if ( CKEDITOR.env.ie )
|
---|
477 | {
|
---|
478 | // Override keystrokes which should have deletion behavior
|
---|
479 | // on control types in IE . (#4047)
|
---|
480 | domDocument.on( 'keydown', function( evt )
|
---|
481 | {
|
---|
482 | var keyCode = evt.data.getKeystroke();
|
---|
483 |
|
---|
484 | // Backspace OR Delete.
|
---|
485 | if ( keyCode in { 8 : 1, 46 : 1 } )
|
---|
486 | {
|
---|
487 | var sel = editor.getSelection(),
|
---|
488 | control = sel.getSelectedElement();
|
---|
489 |
|
---|
490 | if ( control )
|
---|
491 | {
|
---|
492 | // Make undo snapshot.
|
---|
493 | editor.fire( 'saveSnapshot' );
|
---|
494 |
|
---|
495 | // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
|
---|
496 | // break up the selection, safely manage it here. (#4795)
|
---|
497 | var bookmark = sel.getRanges()[ 0 ].createBookmark();
|
---|
498 | // Remove the control manually.
|
---|
499 | control.remove();
|
---|
500 | sel.selectBookmarks( [ bookmark ] );
|
---|
501 |
|
---|
502 | editor.fire( 'saveSnapshot' );
|
---|
503 |
|
---|
504 | evt.data.preventDefault();
|
---|
505 | }
|
---|
506 | }
|
---|
507 | } );
|
---|
508 |
|
---|
509 | // PageUp/PageDown scrolling is broken in document
|
---|
510 | // with standard doctype, manually fix it. (#4736)
|
---|
511 | if ( domDocument.$.compatMode == 'CSS1Compat' )
|
---|
512 | {
|
---|
513 | var pageUpDownKeys = { 33 : 1, 34 : 1 };
|
---|
514 | domDocument.on( 'keydown', function( evt )
|
---|
515 | {
|
---|
516 | if ( evt.data.getKeystroke() in pageUpDownKeys )
|
---|
517 | {
|
---|
518 | setTimeout( function ()
|
---|
519 | {
|
---|
520 | editor.getSelection().scrollIntoView();
|
---|
521 | }, 0 );
|
---|
522 | }
|
---|
523 | } );
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | // Adds the document body as a context menu target.
|
---|
528 | if ( editor.contextMenu )
|
---|
529 | editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
|
---|
530 |
|
---|
531 | setTimeout( function()
|
---|
532 | {
|
---|
533 | editor.fire( 'contentDom' );
|
---|
534 |
|
---|
535 | if ( fireMode )
|
---|
536 | {
|
---|
537 | editor.mode = 'wysiwyg';
|
---|
538 | editor.fire( 'mode' );
|
---|
539 | fireMode = false;
|
---|
540 | }
|
---|
541 |
|
---|
542 | isLoadingData = false;
|
---|
543 |
|
---|
544 | if ( isPendingFocus )
|
---|
545 | {
|
---|
546 | editor.focus();
|
---|
547 | isPendingFocus = false;
|
---|
548 | }
|
---|
549 | setTimeout( function()
|
---|
550 | {
|
---|
551 | editor.fire( 'dataReady' );
|
---|
552 | }, 0 );
|
---|
553 |
|
---|
554 | /*
|
---|
555 | * IE BUG: IE might have rendered the iframe with invisible contents.
|
---|
556 | * (#3623). Push some inconsequential CSS style changes to force IE to
|
---|
557 | * refresh it.
|
---|
558 | *
|
---|
559 | * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
|
---|
560 | * fix the problem. :(
|
---|
561 | */
|
---|
562 | if ( CKEDITOR.env.ie )
|
---|
563 | {
|
---|
564 | setTimeout( function()
|
---|
565 | {
|
---|
566 | if ( editor.document )
|
---|
567 | {
|
---|
568 | var $body = editor.document.$.body;
|
---|
569 | $body.runtimeStyle.marginBottom = '0px';
|
---|
570 | $body.runtimeStyle.marginBottom = '';
|
---|
571 | }
|
---|
572 | }, 1000 );
|
---|
573 | }
|
---|
574 | },
|
---|
575 | 0 );
|
---|
576 | };
|
---|
577 |
|
---|
578 | editor.addMode( 'wysiwyg',
|
---|
579 | {
|
---|
580 | load : function( holderElement, data, isSnapshot )
|
---|
581 | {
|
---|
582 | mainElement = holderElement;
|
---|
583 |
|
---|
584 | if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
|
---|
585 | holderElement.setStyle( 'position', 'relative' );
|
---|
586 |
|
---|
587 | // The editor data "may be dirty" after this
|
---|
588 | // point.
|
---|
589 | editor.mayBeDirty = true;
|
---|
590 |
|
---|
591 | fireMode = true;
|
---|
592 |
|
---|
593 | if ( isSnapshot )
|
---|
594 | this.loadSnapshotData( data );
|
---|
595 | else
|
---|
596 | this.loadData( data );
|
---|
597 | },
|
---|
598 |
|
---|
599 | loadData : function( data )
|
---|
600 | {
|
---|
601 | isLoadingData = true;
|
---|
602 |
|
---|
603 | var config = editor.config,
|
---|
604 | fullPage = config.fullPage,
|
---|
605 | docType = config.docType;
|
---|
606 |
|
---|
607 | // Build the additional stuff to be included into <head>.
|
---|
608 | var headExtra =
|
---|
609 | '<style type="text/css" cke_temp="1">' +
|
---|
610 | editor._.styles.join( '\n' ) +
|
---|
611 | '</style>';
|
---|
612 |
|
---|
613 | !fullPage && ( headExtra =
|
---|
614 | CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
|
---|
615 | headExtra );
|
---|
616 |
|
---|
617 | var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
|
---|
618 |
|
---|
619 | if ( fullPage )
|
---|
620 | {
|
---|
621 | // Search and sweep out the doctype declaration.
|
---|
622 | data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
|
---|
623 | {
|
---|
624 | editor.docType = docType = match;
|
---|
625 | return '';
|
---|
626 | });
|
---|
627 | }
|
---|
628 |
|
---|
629 | // Get the HTML version of the data.
|
---|
630 | if ( editor.dataProcessor )
|
---|
631 | data = editor.dataProcessor.toHtml( data, fixForBody );
|
---|
632 |
|
---|
633 | if ( fullPage )
|
---|
634 | {
|
---|
635 | // Check if the <body> tag is available.
|
---|
636 | if ( !(/<body[\s|>]/).test( data ) )
|
---|
637 | data = '<body>' + data;
|
---|
638 |
|
---|
639 | // Check if the <html> tag is available.
|
---|
640 | if ( !(/<html[\s|>]/).test( data ) )
|
---|
641 | data = '<html>' + data + '</html>';
|
---|
642 |
|
---|
643 | // Check if the <head> tag is available.
|
---|
644 | if ( !(/<head[\s|>]/).test( data ) )
|
---|
645 | data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
|
---|
646 |
|
---|
647 | // The base must be the first tag in the HEAD, e.g. to get relative
|
---|
648 | // links on styles.
|
---|
649 | baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
|
---|
650 |
|
---|
651 | // Inject the extra stuff into <head>.
|
---|
652 | // Attention: do not change it before testing it well. (V2)
|
---|
653 | // This is tricky... if the head ends with <meta ... content type>,
|
---|
654 | // Firefox will break. But, it works if we place our extra stuff as
|
---|
655 | // the last elements in the HEAD.
|
---|
656 | data = data.replace( /<\/head\s*>/, headExtra + '$&' );
|
---|
657 |
|
---|
658 | // Add the DOCTYPE back to it.
|
---|
659 | data = docType + data;
|
---|
660 | }
|
---|
661 | else
|
---|
662 | {
|
---|
663 | data =
|
---|
664 | config.docType +
|
---|
665 | '<html dir="' + config.contentsLangDirection + '">' +
|
---|
666 | '<title>' + frameLabel + '</title>' +
|
---|
667 | '<head>' +
|
---|
668 | baseTag +
|
---|
669 | headExtra +
|
---|
670 | '</head>' +
|
---|
671 | '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
|
---|
672 | ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
|
---|
673 | '>' +
|
---|
674 | data +
|
---|
675 | '</html>';
|
---|
676 | }
|
---|
677 |
|
---|
678 | data += activationScript;
|
---|
679 |
|
---|
680 | CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;
|
---|
681 |
|
---|
682 | // The iframe is recreated on each call of setData, so we need to clear DOM objects
|
---|
683 | this.onDispose();
|
---|
684 | createIFrame( data );
|
---|
685 | },
|
---|
686 |
|
---|
687 | getData : function()
|
---|
688 | {
|
---|
689 | var config = editor.config,
|
---|
690 | fullPage = config.fullPage,
|
---|
691 | docType = fullPage && editor.docType,
|
---|
692 | doc = iframe.getFrameDocument();
|
---|
693 |
|
---|
694 | var data = fullPage
|
---|
695 | ? doc.getDocumentElement().getOuterHtml()
|
---|
696 | : doc.getBody().getHtml();
|
---|
697 |
|
---|
698 | if ( editor.dataProcessor )
|
---|
699 | data = editor.dataProcessor.toDataFormat( data, fixForBody );
|
---|
700 |
|
---|
701 | // Strip the last blank paragraph within document.
|
---|
702 | if ( config.ignoreEmptyParagraph )
|
---|
703 | data = data.replace( emptyParagraphRegexp, '' );
|
---|
704 |
|
---|
705 | if ( docType )
|
---|
706 | data = docType + '\n' + data;
|
---|
707 |
|
---|
708 | return data;
|
---|
709 | },
|
---|
710 |
|
---|
711 | getSnapshotData : function()
|
---|
712 | {
|
---|
713 | return iframe.getFrameDocument().getBody().getHtml();
|
---|
714 | },
|
---|
715 |
|
---|
716 | loadSnapshotData : function( data )
|
---|
717 | {
|
---|
718 | iframe.getFrameDocument().getBody().setHtml( data );
|
---|
719 | },
|
---|
720 |
|
---|
721 | onDispose : function()
|
---|
722 | {
|
---|
723 | if ( !editor.document )
|
---|
724 | return;
|
---|
725 |
|
---|
726 | editor.document.getDocumentElement().clearCustomData();
|
---|
727 | editor.document.getBody().clearCustomData();
|
---|
728 |
|
---|
729 | editor.window.clearCustomData();
|
---|
730 | editor.document.clearCustomData();
|
---|
731 |
|
---|
732 | iframe.clearCustomData();
|
---|
733 | },
|
---|
734 |
|
---|
735 | unload : function( holderElement )
|
---|
736 | {
|
---|
737 | this.onDispose();
|
---|
738 |
|
---|
739 | editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
|
---|
740 |
|
---|
741 | editor.fire( 'contentDomUnload' );
|
---|
742 | },
|
---|
743 |
|
---|
744 | focus : function()
|
---|
745 | {
|
---|
746 | if ( isLoadingData )
|
---|
747 | isPendingFocus = true;
|
---|
748 | else if ( editor.window )
|
---|
749 | {
|
---|
750 | editor.window.focus();
|
---|
751 | editor.selectionChange();
|
---|
752 | }
|
---|
753 | }
|
---|
754 | });
|
---|
755 |
|
---|
756 | editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
|
---|
757 | editor.on( 'insertElement', onInsertElement, null, null, 20 );
|
---|
758 | // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
|
---|
759 | editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
|
---|
760 | });
|
---|
761 |
|
---|
762 | var titleBackup;
|
---|
763 | // Setting voice label as window title, backup the original one
|
---|
764 | // and restore it before running into use.
|
---|
765 | editor.on( 'contentDom', function ()
|
---|
766 | {
|
---|
767 | var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
|
---|
768 | title.setAttribute( '_cke_title', editor.document.$.title );
|
---|
769 | editor.document.$.title = frameLabel;
|
---|
770 | });
|
---|
771 |
|
---|
772 |
|
---|
773 | // Create an invisible element to grab focus.
|
---|
774 | if ( CKEDITOR.env.ie )
|
---|
775 | {
|
---|
776 | var ieFocusGrabber;
|
---|
777 | editor.on( 'uiReady', function()
|
---|
778 | {
|
---|
779 | ieFocusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
|
---|
780 | // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
|
---|
781 | '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );
|
---|
782 |
|
---|
783 | ieFocusGrabber.on( 'focus', function()
|
---|
784 | {
|
---|
785 | editor.focus();
|
---|
786 | } );
|
---|
787 | } );
|
---|
788 | editor.on( 'destroy', function()
|
---|
789 | {
|
---|
790 | ieFocusGrabber.clearCustomData();
|
---|
791 | } );
|
---|
792 | }
|
---|
793 | }
|
---|
794 | });
|
---|
795 |
|
---|
796 | // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
|
---|
797 | if ( CKEDITOR.env.gecko )
|
---|
798 | {
|
---|
799 | ( function ()
|
---|
800 | {
|
---|
801 | var body = document.body;
|
---|
802 |
|
---|
803 | if ( !body )
|
---|
804 | window.addEventListener( 'load', arguments.callee, false );
|
---|
805 | else
|
---|
806 | {
|
---|
807 | body.setAttribute( 'onpageshow', body.getAttribute( 'onpageshow' )
|
---|
808 | + ';event.persisted && CKEDITOR.tools.callFunction(' +
|
---|
809 | CKEDITOR.tools.addFunction( function()
|
---|
810 | {
|
---|
811 | var allInstances = CKEDITOR.instances,
|
---|
812 | editor,
|
---|
813 | doc;
|
---|
814 | for ( var i in allInstances )
|
---|
815 | if ( ! ( i in Object.prototype ) )
|
---|
816 | {
|
---|
817 | editor = allInstances[ i ];
|
---|
818 | doc = editor.document;
|
---|
819 | if ( doc )
|
---|
820 | {
|
---|
821 | doc.$.designMode = 'off';
|
---|
822 | doc.$.designMode = 'on';
|
---|
823 | }
|
---|
824 | }
|
---|
825 | } ) + ')' );
|
---|
826 | }
|
---|
827 | } )();
|
---|
828 |
|
---|
829 | }
|
---|
830 | })();
|
---|
831 |
|
---|
832 | /**
|
---|
833 | * Disables the ability of resize objects (image and tables) in the editing
|
---|
834 | * area.
|
---|
835 | * @type Boolean
|
---|
836 | * @default false
|
---|
837 | * @example
|
---|
838 | * config.disableObjectResizing = true;
|
---|
839 | */
|
---|
840 | CKEDITOR.config.disableObjectResizing = false;
|
---|
841 |
|
---|
842 | /**
|
---|
843 | * Disables the "table tools" offered natively by the browser (currently
|
---|
844 | * Firefox only) to make quick table editing operations, like adding or
|
---|
845 | * deleting rows and columns.
|
---|
846 | * @type Boolean
|
---|
847 | * @default true
|
---|
848 | * @example
|
---|
849 | * config.disableNativeTableHandles = false;
|
---|
850 | */
|
---|
851 | CKEDITOR.config.disableNativeTableHandles = true;
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Disables the built-in spell checker while typing natively available in the
|
---|
855 | * browser (currently Firefox and Safari only).<br /><br />
|
---|
856 | *
|
---|
857 | * Even if word suggestions will not appear in the CKEditor context menu, this
|
---|
858 | * feature is useful to help quickly identifying misspelled words.<br /><br />
|
---|
859 | *
|
---|
860 | * This setting is currently compatible with Firefox only due to limitations in
|
---|
861 | * other browsers.
|
---|
862 | * @type Boolean
|
---|
863 | * @default true
|
---|
864 | * @example
|
---|
865 | * config.disableNativeSpellChecker = false;
|
---|
866 | */
|
---|
867 | CKEDITOR.config.disableNativeSpellChecker = true;
|
---|
868 |
|
---|
869 | /**
|
---|
870 | * Whether the editor must output an empty value ("") if it's contents is made
|
---|
871 | * by an empty paragraph only.
|
---|
872 | * @type Boolean
|
---|
873 | * @default true
|
---|
874 | * @example
|
---|
875 | * config.ignoreEmptyParagraph = false;
|
---|
876 | */
|
---|
877 | CKEDITOR.config.ignoreEmptyParagraph = true;
|
---|
878 |
|
---|
879 | /**
|
---|
880 | * Fired when data is loaded and ready for retrieval in an editor instance.
|
---|
881 | * @name CKEDITOR.editor#dataReady
|
---|
882 | * @event
|
---|
883 | */
|
---|