2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing
\r
8 * mode, which handles the main editing area space.
\r
13 // List of elements in which has no way to move editing focus outside.
\r
14 var nonExitableElementNames = { table:1,pre:1 };
\r
16 // Matching an empty paragraph at the end of document.
\r
17 var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| |\u00A0| )?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;
\r
19 var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );
\r
21 function checkReadOnly( selection )
\r
23 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )
\r
24 return selection.getSelectedElement().isReadOnly();
\r
26 return selection.getCommonAncestor().isReadOnly();
\r
29 function onInsertHtml( evt )
\r
31 if ( this.mode == 'wysiwyg' )
\r
35 var selection = this.getSelection();
\r
36 if ( checkReadOnly( selection ) )
\r
39 var data = evt.data;
\r
40 this.fire( 'saveSnapshot' );
\r
42 if ( this.dataProcessor )
\r
43 data = this.dataProcessor.toHtml( data );
\r
45 if ( CKEDITOR.env.ie )
\r
47 var selIsLocked = selection.isLocked;
\r
52 var $sel = selection.getNative();
\r
54 // Delete control selections to avoid IE bugs on pasteHTML.
\r
55 if ( $sel.type == 'Control' )
\r
57 else if ( selection.getType() == CKEDITOR.SELECTION_TEXT )
\r
59 // Due to IE bugs on handling contenteditable=false blocks
\r
60 // (#6005), we need to make some checks and eventually
\r
61 // delete the selection first.
\r
63 var range = selection.getRanges()[0],
\r
64 endContainer = range && range.endContainer;
\r
66 if ( endContainer &&
\r
67 endContainer.type == CKEDITOR.NODE_ELEMENT &&
\r
68 endContainer.getAttribute( 'contenteditable' ) == 'false' &&
\r
69 range.checkBoundaryOfElement( endContainer, CKEDITOR.END ) )
\r
71 range.setEndAfter( range.endContainer );
\r
72 range.deleteContents();
\r
78 $sel.createRange().pasteHTML( data );
\r
83 this.getSelection().lock();
\r
86 this.document.$.execCommand( 'inserthtml', false, data );
\r
88 // Webkit does not scroll to the cursor position after pasting (#5558)
\r
89 if ( CKEDITOR.env.webkit )
\r
91 this.document.$.execCommand( 'inserthtml', false, '<span id="cke_paste_marker" cke_temp="1"></span>' );
\r
92 var marker = this.document.getById( 'cke_paste_marker' );
\r
93 marker.scrollIntoView();
\r
98 CKEDITOR.tools.setTimeout( function()
\r
100 this.fire( 'saveSnapshot' );
\r
105 function onInsertElement( evt )
\r
107 if ( this.mode == 'wysiwyg' )
\r
111 var selection = this.getSelection();
\r
112 if ( checkReadOnly( selection ) )
\r
115 this.fire( 'saveSnapshot' );
\r
117 var ranges = selection.getRanges(),
\r
118 element = evt.data,
\r
119 elementName = element.getName(),
\r
120 isBlock = CKEDITOR.dtd.$block[ elementName ];
\r
122 var selIsLocked = selection.isLocked;
\r
125 selection.unlock();
\r
127 var range, clone, lastElement, bookmark;
\r
129 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
\r
131 range = ranges[ i ];
\r
133 // Remove the original contents.
\r
134 range.deleteContents();
\r
136 clone = !i && element || element.clone( 1 );
\r
138 // If we're inserting a block at dtd-violated position, split
\r
139 // the parent blocks until we reach blockLimit.
\r
143 while ( ( current = range.getCommonAncestor( 0, 1 ) )
\r
144 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
\r
145 && !( dtd && dtd [ elementName ] ) )
\r
147 // Split up inline elements.
\r
148 if ( current.getName() in CKEDITOR.dtd.span )
\r
149 range.splitElement( current );
\r
150 // If we're in an empty block which indicate a new paragraph,
\r
151 // simply replace it with the inserting block.(#3664)
\r
152 else if ( range.checkStartOfBlock()
\r
153 && range.checkEndOfBlock() )
\r
155 range.setStartBefore( current );
\r
156 range.collapse( true );
\r
160 range.splitBlock();
\r
164 // Insert the new node.
\r
165 range.insertNode( clone );
\r
167 // Save the last element reference so we can make the
\r
168 // selection later.
\r
169 if ( !lastElement )
\r
170 lastElement = clone;
\r
173 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
\r
175 // If we're inserting a block element immediatelly followed by
\r
176 // another block element, the selection must move there. (#3100,#5436)
\r
179 var next = lastElement.getNext( notWhitespaceEval ),
\r
180 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
\r
182 // Check if it's a block element that accepts text.
\r
183 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
\r
184 range.moveToElementEditStart( next );
\r
187 selection.selectRanges( [ range ] );
\r
190 this.getSelection().lock();
\r
192 // Save snaps after the whole execution completed.
\r
193 // This's a workaround for make DOM modification's happened after
\r
194 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
\r
196 CKEDITOR.tools.setTimeout( function(){
\r
197 this.fire( 'saveSnapshot' );
\r
202 // DOM modification here should not bother dirty flag.(#4385)
\r
203 function restoreDirty( editor )
\r
205 if ( !editor.checkDirty() )
\r
206 setTimeout( function(){ editor.resetDirty(); }, 0 );
\r
209 var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
\r
210 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
\r
212 function isNotEmpty( node )
\r
214 return isNotWhitespace( node ) && isNotBookmark( node );
\r
217 function isNbsp( node )
\r
219 return node.type == CKEDITOR.NODE_TEXT
\r
220 && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
\r
223 function restoreSelection( selection )
\r
225 if ( selection.isLocked )
\r
227 selection.unlock();
\r
228 setTimeout( function() { selection.lock(); }, 0 );
\r
232 function isBlankParagraph( block )
\r
234 return block.getOuterHtml().match( emptyParagraphRegexp );
\r
237 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
\r
239 // Gecko need a key event to 'wake up' the editing
\r
240 // ability when document is empty.(#3864, #5781)
\r
241 function activateEditing( editor )
\r
243 var win = editor.window,
\r
244 doc = editor.document,
\r
245 body = editor.document.getBody(),
\r
246 bodyChildsNum = body.getChildren().count();
\r
248 if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )
\r
250 restoreDirty( editor );
\r
252 // Memorize scroll position to restore it later (#4472).
\r
253 var hostDocument = editor.element.getDocument();
\r
254 var hostDocumentElement = hostDocument.getDocumentElement();
\r
255 var scrollTop = hostDocumentElement.$.scrollTop;
\r
256 var scrollLeft = hostDocumentElement.$.scrollLeft;
\r
258 // Simulating keyboard character input by dispatching a keydown of white-space text.
\r
259 var keyEventSimulate = doc.$.createEvent( "KeyEvents" );
\r
260 keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,
\r
261 false, false, false, 0, 32 );
\r
262 doc.$.dispatchEvent( keyEventSimulate );
\r
264 if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )
\r
265 hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );
\r
267 // Restore the original document status by placing the cursor before a bogus br created (#5021).
\r
268 bodyChildsNum && body.getFirst().remove();
\r
269 doc.getBody().appendBogus();
\r
270 var nativeRange = new CKEDITOR.dom.range( doc );
\r
271 nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );
\r
272 nativeRange.select();
\r
277 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
\r
278 * non-exitable-block by padding extra br.(#3189)
\r
280 function onSelectionChangeFixBody( evt )
\r
282 var editor = evt.editor,
\r
283 path = evt.data.path,
\r
284 blockLimit = path.blockLimit,
\r
285 selection = evt.data.selection,
\r
286 range = selection.getRanges()[0],
\r
287 body = editor.document.getBody(),
\r
288 enterMode = editor.config.enterMode;
\r
290 CKEDITOR.env.gecko && activateEditing( editor );
\r
292 // When enterMode set to block, we'll establing new paragraph only if we're
\r
293 // selecting inline contents right under body. (#3657)
\r
294 if ( enterMode != CKEDITOR.ENTER_BR
\r
296 && blockLimit.getName() == 'body'
\r
299 editor.fire( 'updateSnapshot' );
\r
300 restoreDirty( editor );
\r
301 CKEDITOR.env.ie && restoreSelection( selection );
\r
303 var fixedBlock = range.fixBlock( true,
\r
304 editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
\r
306 // For IE, we should remove any filler node which was introduced before.
\r
307 if ( CKEDITOR.env.ie )
\r
309 var first = fixedBlock.getFirst( isNotEmpty );
\r
310 first && isNbsp( first ) && first.remove();
\r
313 // If the fixed block is actually blank and is already followed by an exitable blank
\r
314 // block, we should revert the fix and move into the existed one. (#3684)
\r
315 if ( isBlankParagraph( fixedBlock ) )
\r
317 var element = fixedBlock.getNext( isNotWhitespace );
\r
319 element.type == CKEDITOR.NODE_ELEMENT &&
\r
320 !nonExitableElementNames[ element.getName() ] )
\r
322 range.moveToElementEditStart( element );
\r
323 fixedBlock.remove();
\r
327 element = fixedBlock.getPrevious( isNotWhitespace );
\r
329 element.type == CKEDITOR.NODE_ELEMENT &&
\r
330 !nonExitableElementNames[ element.getName() ] )
\r
332 range.moveToElementEditEnd( element );
\r
333 fixedBlock.remove();
\r
339 // Notify non-IE that selection has changed.
\r
340 if ( !CKEDITOR.env.ie )
\r
341 editor.selectionChange();
\r
344 // All browsers are incapable to moving cursor out of certain non-exitable
\r
345 // blocks (e.g. table, list, pre) at the end of document, make this happen by
\r
346 // place a bogus node there, which would be later removed by dataprocessor.
\r
347 var walkerRange = new CKEDITOR.dom.range( editor.document ),
\r
348 walker = new CKEDITOR.dom.walker( walkerRange );
\r
349 walkerRange.selectNodeContents( body );
\r
350 walker.evaluator = function( node )
\r
352 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
\r
354 walker.guard = function( node, isMoveout )
\r
356 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
\r
359 if ( walker.previous() )
\r
361 editor.fire( 'updateSnapshot' );
\r
362 restoreDirty( editor );
\r
363 CKEDITOR.env.ie && restoreSelection( selection );
\r
366 if ( enterMode != CKEDITOR.ENTER_BR )
\r
367 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
\r
369 paddingBlock = body;
\r
371 if ( !CKEDITOR.env.ie )
\r
372 paddingBlock.appendBogus();
\r
376 CKEDITOR.plugins.add( 'wysiwygarea',
\r
378 requires : [ 'editingblock' ],
\r
380 init : function( editor )
\r
382 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
\r
383 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
\r
385 var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
\r
387 var contentDomReadyHandler;
\r
388 editor.on( 'editingBlockReady', function()
\r
398 // Support for custom document.domain in IE.
\r
399 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
401 // Creates the iframe that holds the editable document.
\r
402 var createIFrame = function( data )
\r
409 'document.open();' +
\r
411 // The document domain must be set any time we
\r
412 // call document.open().
\r
413 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
415 'document.close();';
\r
417 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
418 ' style="width:100%;height:100%"' +
\r
419 ' frameBorder="0"' +
\r
420 ' title="' + frameLabel + '"' +
\r
421 // With IE, the custom domain has to be taken care at first,
\r
422 // for other browers, the 'src' attribute should be left empty to
\r
423 // trigger iframe's 'load' event.
\r
424 ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +
\r
425 ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +
\r
426 ' allowTransparency="true"' +
\r
429 // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)
\r
430 if ( document.location.protocol == 'chrome:' )
\r
431 CKEDITOR.event.useCapture = true;
\r
433 // With FF, it's better to load the data on iframe.load. (#3894,#4058)
\r
434 iframe.on( 'load', function( ev )
\r
437 ev.removeListener();
\r
439 var doc = iframe.getFrameDocument().$;
\r
441 // Don't leave any history log in IE. (#5657)
\r
442 doc.open( "text/html","replace" );
\r
447 // Reset adjustment back to default (#5689)
\r
448 if ( document.location.protocol == 'chrome:' )
\r
449 CKEDITOR.event.useCapture = false;
\r
451 // The container must be visible when creating the iframe in FF (#5956)
\r
452 var element = editor.element,
\r
453 isHidden = CKEDITOR.env.gecko && !element.isVisible(),
\r
454 previousStyles = {};
\r
459 position : element.getStyle( 'position' ),
\r
460 top : element.getStyle( 'top' )
\r
462 element.setStyles( { position : 'absolute', top : '-3000px' } );
\r
465 mainElement.append( iframe );
\r
469 setTimeout( function()
\r
472 element.setStyles( previousStyles );
\r
477 // The script that launches the bootstrap logic on 'domReady', so the document
\r
478 // is fully editable even before the editing iframe is fully loaded (#4455).
\r
479 contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );
\r
480 var activationScript =
\r
481 '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
\r
482 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
483 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +
\r
486 // Editing area bootstrap code.
\r
487 function contentDomReady( domWindow )
\r
489 if ( !frameLoaded )
\r
493 editor.fire( 'ariaWidget', iframe );
\r
495 var domDocument = domWindow.document,
\r
496 body = domDocument.body;
\r
498 // Remove this script from the DOM.
\r
499 var script = domDocument.getElementById( "cke_actscrpt" );
\r
500 script.parentNode.removeChild( script );
\r
502 body.spellcheck = !editor.config.disableNativeSpellChecker;
\r
504 if ( CKEDITOR.env.ie )
\r
506 // Don't display the focus border.
\r
507 body.hideFocus = true;
\r
509 // Disable and re-enable the body to avoid IE from
\r
510 // taking the editing focus at startup. (#141 / #523)
\r
511 body.disabled = true;
\r
512 body.contentEditable = true;
\r
513 body.removeAttribute( 'disabled' );
\r
517 // Avoid opening design mode in a frame window thread,
\r
518 // which will cause host page scrolling.(#4397)
\r
519 setTimeout( function()
\r
521 // Prefer 'contentEditable' instead of 'designMode'. (#3593)
\r
522 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
\r
523 || CKEDITOR.env.opera )
\r
524 domDocument.$.body.contentEditable = true;
\r
525 else if ( CKEDITOR.env.webkit )
\r
526 domDocument.$.body.parentNode.contentEditable = true;
\r
528 domDocument.$.designMode = 'on';
\r
532 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
\r
534 domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
\r
535 domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
\r
537 domDocument.on( 'dblclick', function( evt )
\r
539 var element = evt.data.getTarget(),
\r
540 data = { element : element, dialog : '' };
\r
541 editor.fire( 'doubleclick', data );
\r
542 data.dialog && editor.openDialog( data.dialog );
\r
545 // Gecko/Webkit need some help when selecting control type elements. (#3448)
\r
546 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) )
\r
548 domDocument.on( 'mousedown', function( ev )
\r
550 var control = ev.data.getTarget();
\r
551 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
\r
552 editor.getSelection().selectElement( control );
\r
556 if ( CKEDITOR.env.gecko )
\r
558 domDocument.on( 'mouseup', function( ev )
\r
560 if ( ev.data.$.button == 2 )
\r
562 var target = ev.data.getTarget();
\r
564 // Prevent right click from selecting an empty block even
\r
565 // when selection is anchored inside it. (#5845)
\r
566 if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )
\r
568 var range = new CKEDITOR.dom.range( domDocument );
\r
569 range.moveToElementEditStart( target );
\r
570 range.select( true );
\r
576 // Prevent the browser opening links in read-only blocks. (#6032)
\r
577 domDocument.on( 'click', function( ev )
\r
580 if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )
\r
581 ev.preventDefault();
\r
584 // Webkit: avoid from editing form control elements content.
\r
585 if ( CKEDITOR.env.webkit )
\r
587 // Prevent from tick checkbox/radiobox/select
\r
588 domDocument.on( 'click', function( ev )
\r
590 if ( ev.data.getTarget().is( 'input', 'select' ) )
\r
591 ev.data.preventDefault();
\r
594 // Prevent from editig textfield/textarea value.
\r
595 domDocument.on( 'mouseup', function( ev )
\r
597 if ( ev.data.getTarget().is( 'input', 'textarea' ) )
\r
598 ev.data.preventDefault();
\r
602 // IE standard compliant in editing frame doesn't focus the editor when
\r
603 // clicking outside actual content, manually apply the focus. (#1659)
\r
604 if ( CKEDITOR.env.ie
\r
605 && domDocument.$.compatMode == 'CSS1Compat'
\r
606 || CKEDITOR.env.gecko
\r
607 || CKEDITOR.env.opera )
\r
609 var htmlElement = domDocument.getDocumentElement();
\r
610 htmlElement.on( 'mousedown', function( evt )
\r
612 // Setting focus directly on editor doesn't work, we
\r
613 // have to use here a temporary element to 'redirect'
\r
615 if ( evt.data.getTarget().equals( htmlElement ) )
\r
617 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
619 focusGrabber.focus();
\r
624 domWindow.on( 'blur', function()
\r
626 editor.focusManager.blur();
\r
631 domWindow.on( 'focus', function()
\r
633 var doc = editor.document;
\r
635 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
637 else if ( CKEDITOR.env.opera )
\r
638 doc.getBody().focus();
\r
639 // Webkit needs focus for the first time on the HTML element. (#6153)
\r
640 else if ( CKEDITOR.env.webkit )
\r
644 editor.document.getDocumentElement().focus();
\r
649 editor.focusManager.focus();
\r
652 var keystrokeHandler = editor.keystrokeHandler;
\r
653 if ( keystrokeHandler )
\r
654 keystrokeHandler.attach( domDocument );
\r
656 if ( CKEDITOR.env.ie )
\r
658 domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
\r
659 // Override keystrokes which should have deletion behavior
\r
660 // on control types in IE . (#4047)
\r
661 domDocument.on( 'keydown', function( evt )
\r
663 var keyCode = evt.data.getKeystroke();
\r
665 // Backspace OR Delete.
\r
666 if ( keyCode in { 8 : 1, 46 : 1 } )
\r
668 var sel = editor.getSelection(),
\r
669 control = sel.getSelectedElement();
\r
673 // Make undo snapshot.
\r
674 editor.fire( 'saveSnapshot' );
\r
676 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
\r
677 // break up the selection, safely manage it here. (#4795)
\r
678 var bookmark = sel.getRanges()[ 0 ].createBookmark();
\r
679 // Remove the control manually.
\r
681 sel.selectBookmarks( [ bookmark ] );
\r
683 editor.fire( 'saveSnapshot' );
\r
685 evt.data.preventDefault();
\r
690 // PageUp/PageDown scrolling is broken in document
\r
691 // with standard doctype, manually fix it. (#4736)
\r
692 if ( domDocument.$.compatMode == 'CSS1Compat' )
\r
694 var pageUpDownKeys = { 33 : 1, 34 : 1 };
\r
695 domDocument.on( 'keydown', function( evt )
\r
697 if ( evt.data.getKeystroke() in pageUpDownKeys )
\r
699 setTimeout( function ()
\r
701 editor.getSelection().scrollIntoView();
\r
708 // Adds the document body as a context menu target.
\r
709 if ( editor.contextMenu )
\r
710 editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
\r
712 setTimeout( function()
\r
714 editor.fire( 'contentDom' );
\r
718 editor.mode = 'wysiwyg';
\r
719 editor.fire( 'mode' );
\r
723 isLoadingData = false;
\r
725 if ( isPendingFocus )
\r
728 isPendingFocus = false;
\r
730 setTimeout( function()
\r
732 editor.fire( 'dataReady' );
\r
735 // IE, Opera and Safari may not support it and throw errors.
\r
736 try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
\r
737 try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
\r
740 * IE BUG: IE might have rendered the iframe with invisible contents.
\r
741 * (#3623). Push some inconsequential CSS style changes to force IE to
\r
744 * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
\r
745 * fix the problem. :(
\r
747 if ( CKEDITOR.env.ie )
\r
749 setTimeout( function()
\r
751 if ( editor.document )
\r
753 var $body = editor.document.$.body;
\r
754 $body.runtimeStyle.marginBottom = '0px';
\r
755 $body.runtimeStyle.marginBottom = '';
\r
763 editor.addMode( 'wysiwyg',
\r
765 load : function( holderElement, data, isSnapshot )
\r
767 mainElement = holderElement;
\r
769 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
770 holderElement.setStyle( 'position', 'relative' );
\r
772 // The editor data "may be dirty" after this
\r
774 editor.mayBeDirty = true;
\r
779 this.loadSnapshotData( data );
\r
781 this.loadData( data );
\r
784 loadData : function( data )
\r
786 isLoadingData = true;
\r
788 var config = editor.config,
\r
789 fullPage = config.fullPage,
\r
790 docType = config.docType;
\r
792 // Build the additional stuff to be included into <head>.
\r
794 '<style type="text/css" cke_temp="1">' +
\r
795 editor._.styles.join( '\n' ) +
\r
798 !fullPage && ( headExtra =
\r
799 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
802 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
\r
806 // Search and sweep out the doctype declaration.
\r
807 data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
\r
809 editor.docType = docType = match;
\r
814 // Get the HTML version of the data.
\r
815 if ( editor.dataProcessor )
\r
816 data = editor.dataProcessor.toHtml( data, fixForBody );
\r
820 // Check if the <body> tag is available.
\r
821 if ( !(/<body[\s|>]/).test( data ) )
\r
822 data = '<body>' + data;
\r
824 // Check if the <html> tag is available.
\r
825 if ( !(/<html[\s|>]/).test( data ) )
\r
826 data = '<html>' + data + '</html>';
\r
828 // Check if the <head> tag is available.
\r
829 if ( !(/<head[\s|>]/).test( data ) )
\r
830 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
\r
831 else if ( !(/<title[\s|>]/).test( data ) )
\r
832 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;
\r
834 // The base must be the first tag in the HEAD, e.g. to get relative
\r
835 // links on styles.
\r
836 baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
\r
838 // Inject the extra stuff into <head>.
\r
839 // Attention: do not change it before testing it well. (V2)
\r
840 // This is tricky... if the head ends with <meta ... content type>,
\r
841 // Firefox will break. But, it works if we place our extra stuff as
\r
842 // the last elements in the HEAD.
\r
843 data = data.replace( /<\/head\s*>/, headExtra + '$&' );
\r
845 // Add the DOCTYPE back to it.
\r
846 data = docType + data;
\r
852 '<html dir="' + config.contentsLangDirection + '"' +
\r
853 ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +
\r
855 '<title>' + frameLabel + '</title>' +
\r
859 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
\r
860 ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
\r
866 data += activationScript;
\r
869 // The iframe is recreated on each call of setData, so we need to clear DOM objects
\r
871 createIFrame( data );
\r
874 getData : function()
\r
876 var config = editor.config,
\r
877 fullPage = config.fullPage,
\r
878 docType = fullPage && editor.docType,
\r
879 doc = iframe.getFrameDocument();
\r
881 var data = fullPage
\r
882 ? doc.getDocumentElement().getOuterHtml()
\r
883 : doc.getBody().getHtml();
\r
885 if ( editor.dataProcessor )
\r
886 data = editor.dataProcessor.toDataFormat( data, fixForBody );
\r
888 // Reset empty if the document contains only one empty paragraph.
\r
889 if ( config.ignoreEmptyParagraph )
\r
890 data = data.replace( emptyParagraphRegexp, function( match, lookback ) { return lookback; } );
\r
893 data = docType + '\n' + data;
\r
898 getSnapshotData : function()
\r
900 return iframe.getFrameDocument().getBody().getHtml();
\r
903 loadSnapshotData : function( data )
\r
905 iframe.getFrameDocument().getBody().setHtml( data );
\r
908 onDispose : function()
\r
910 if ( !editor.document )
\r
913 editor.document.getDocumentElement().clearCustomData();
\r
914 editor.document.getBody().clearCustomData();
\r
916 editor.window.clearCustomData();
\r
917 editor.document.clearCustomData();
\r
919 iframe.clearCustomData();
\r
922 * IE BUG: When destroying editor DOM with the selection remains inside
\r
923 * editing area would break IE7/8's selection system, we have to put the editing
\r
924 * iframe offline first. (#3812 and #5441)
\r
929 unload : function( holderElement )
\r
933 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
\r
935 editor.fire( 'contentDomUnload' );
\r
940 if ( isLoadingData )
\r
941 isPendingFocus = true;
\r
942 // Temporary solution caused by #6025, supposed be unified by #6154.
\r
943 else if ( CKEDITOR.env.opera && editor.document )
\r
945 // Required for Opera when switching focus
\r
946 // from another iframe, e.g. panels. (#6444)
\r
947 var iframe = editor.window.$.frameElement;
\r
948 iframe.blur(), iframe.focus();
\r
949 editor.document.getBody().focus();
\r
951 editor.selectionChange();
\r
953 else if ( !CKEDITOR.env.opera && editor.window )
\r
955 editor.window.focus();
\r
957 editor.selectionChange();
\r
962 editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
\r
963 editor.on( 'insertElement', onInsertElement, null, null, 20 );
\r
964 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
\r
965 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
\r
969 // Setting voice label as window title, backup the original one
\r
970 // and restore it before running into use.
\r
971 editor.on( 'contentDom', function()
\r
973 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
\r
974 title.setAttribute( '_cke_title', editor.document.$.title );
\r
975 editor.document.$.title = frameLabel;
\r
978 // IE8 stricts mode doesn't have 'contentEditable' in effect
\r
979 // on element unless it has layout. (#5562)
\r
980 if ( CKEDITOR.env.ie8Compat )
\r
982 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );
\r
984 var selectors = [];
\r
985 for ( var tag in CKEDITOR.dtd.$removeEmpty )
\r
986 selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );
\r
987 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );
\r
989 // Set the HTML style to 100% to have the text cursor in affect (#6341)
\r
990 else if ( CKEDITOR.env.gecko )
\r
991 editor.addCss( 'html { height: 100% !important; }' );
\r
993 // Switch on design mode for a short while and close it after then.
\r
994 function blinkCursor( retry )
\r
996 CKEDITOR.tools.tryThese(
\r
999 editor.document.$.designMode = 'on';
\r
1000 setTimeout( function()
\r
1002 editor.document.$.designMode = 'off';
\r
1003 if ( CKEDITOR.currentInstance == editor )
\r
1004 editor.document.getBody().focus();
\r
1009 // The above call is known to fail when parent DOM
\r
1010 // tree layout changes may break design mode. (#5782)
\r
1011 // Refresh the 'contentEditable' is a cue to this.
\r
1012 editor.document.$.designMode = 'off';
\r
1013 var body = editor.document.getBody();
\r
1014 body.setAttribute( 'contentEditable', false );
\r
1015 body.setAttribute( 'contentEditable', true );
\r
1016 // Try it again once..
\r
1017 !retry && blinkCursor( 1 );
\r
1021 // Create an invisible element to grab focus.
\r
1022 if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )
\r
1025 editor.on( 'uiReady', function()
\r
1027 focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
\r
1028 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
\r
1029 '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );
\r
1031 focusGrabber.on( 'focus', function()
\r
1036 editor.on( 'destroy', function()
\r
1038 CKEDITOR.tools.removeFunction( contentDomReadyHandler );
\r
1039 focusGrabber.clearCustomData();
\r
1043 // Disable form elements editing mode provided by some browers. (#5746)
\r
1044 editor.on( 'insertElement', function ( evt )
\r
1046 var element = evt.data;
\r
1047 if ( element.type == CKEDITOR.NODE_ELEMENT
\r
1048 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )
\r
1050 if ( !element.isReadOnly() )
\r
1052 element.setAttribute( 'contentEditable', false );
\r
1053 // We should flag that the element was locked by our code so
\r
1054 // it'll be editable by the editor functions (#6046).
\r
1055 element.setCustomData( '_cke_notReadOnly', 1 );
\r
1063 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
\r
1064 if ( CKEDITOR.env.gecko )
\r
1068 var body = document.body;
\r
1071 window.addEventListener( 'load', arguments.callee, false );
\r
1074 var currentHandler = body.getAttribute( 'onpageshow' );
\r
1075 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +
\r
1076 'event.persisted && (function(){' +
\r
1077 'var allInstances = CKEDITOR.instances, editor, doc;' +
\r
1078 'for ( var i in allInstances )' +
\r
1080 ' editor = allInstances[ i ];' +
\r
1081 ' doc = editor.document;' +
\r
1084 ' doc.$.designMode = "off";' +
\r
1085 ' doc.$.designMode = "on";' +
\r
1096 * Disables the ability of resize objects (image and tables) in the editing
\r
1101 * config.disableObjectResizing = true;
\r
1103 CKEDITOR.config.disableObjectResizing = false;
\r
1106 * Disables the "table tools" offered natively by the browser (currently
\r
1107 * Firefox only) to make quick table editing operations, like adding or
\r
1108 * deleting rows and columns.
\r
1112 * config.disableNativeTableHandles = false;
\r
1114 CKEDITOR.config.disableNativeTableHandles = true;
\r
1117 * Disables the built-in spell checker while typing natively available in the
\r
1118 * browser (currently Firefox and Safari only).<br /><br />
\r
1120 * Even if word suggestions will not appear in the CKEditor context menu, this
\r
1121 * feature is useful to help quickly identifying misspelled words.<br /><br />
\r
1123 * This setting is currently compatible with Firefox only due to limitations in
\r
1128 * config.disableNativeSpellChecker = false;
\r
1130 CKEDITOR.config.disableNativeSpellChecker = true;
\r
1133 * Whether the editor must output an empty value ("") if it's contents is made
\r
1134 * by an empty paragraph only.
\r
1138 * config.ignoreEmptyParagraph = false;
\r
1140 CKEDITOR.config.ignoreEmptyParagraph = true;
\r
1143 * Fired when data is loaded and ready for retrieval in an editor instance.
\r
1144 * @name CKEDITOR.editor#dataReady
\r