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 = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| |\u00A0| )?\s*(:?<\/\1>)?(?=\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
97 CKEDITOR.tools.setTimeout( function()
\r
99 this.fire( 'saveSnapshot' );
\r
104 function onInsertElement( evt )
\r
106 if ( this.mode == 'wysiwyg' )
\r
110 var selection = this.getSelection();
\r
111 if ( checkReadOnly( selection ) )
\r
114 this.fire( 'saveSnapshot' );
\r
116 var ranges = selection.getRanges(),
\r
117 element = evt.data,
\r
118 elementName = element.getName(),
\r
119 isBlock = CKEDITOR.dtd.$block[ elementName ];
\r
121 var selIsLocked = selection.isLocked;
\r
124 selection.unlock();
\r
126 var range, clone, lastElement, bookmark;
\r
128 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
\r
130 range = ranges[ i ];
\r
132 // Remove the original contents.
\r
133 range.deleteContents();
\r
135 clone = !i && element || element.clone( true );
\r
137 // If we're inserting a block at dtd-violated position, split
\r
138 // the parent blocks until we reach blockLimit.
\r
142 while ( ( current = range.getCommonAncestor( false, true ) )
\r
143 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
\r
144 && !( dtd && dtd [ elementName ] ) )
\r
146 // Split up inline elements.
\r
147 if ( current.getName() in CKEDITOR.dtd.span )
\r
148 range.splitElement( current );
\r
149 // If we're in an empty block which indicate a new paragraph,
\r
150 // simply replace it with the inserting block.(#3664)
\r
151 else if ( range.checkStartOfBlock()
\r
152 && range.checkEndOfBlock() )
\r
154 range.setStartBefore( current );
\r
155 range.collapse( true );
\r
159 range.splitBlock();
\r
163 // Insert the new node.
\r
164 range.insertNode( clone );
\r
166 // Save the last element reference so we can make the
\r
167 // selection later.
\r
168 if ( !lastElement )
\r
169 lastElement = clone;
\r
172 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
\r
174 // If we're inserting a block element immediatelly followed by
\r
175 // another block element, the selection must move there. (#3100,#5436)
\r
178 var next = lastElement.getNext( notWhitespaceEval ),
\r
179 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
\r
181 // Check if it's a block element that accepts text.
\r
182 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
\r
183 range.moveToElementEditStart( next );
\r
186 selection.selectRanges( [ range ] );
\r
189 this.getSelection().lock();
\r
191 // Save snaps after the whole execution completed.
\r
192 // This's a workaround for make DOM modification's happened after
\r
193 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
\r
195 CKEDITOR.tools.setTimeout( function(){
\r
196 this.fire( 'saveSnapshot' );
\r
201 // DOM modification here should not bother dirty flag.(#4385)
\r
202 function restoreDirty( editor )
\r
204 if ( !editor.checkDirty() )
\r
205 setTimeout( function(){ editor.resetDirty(); }, 0 );
\r
208 var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
\r
209 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
\r
211 function isNotEmpty( node )
\r
213 return isNotWhitespace( node ) && isNotBookmark( node );
\r
216 function isNbsp( node )
\r
218 return node.type == CKEDITOR.NODE_TEXT
\r
219 && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
\r
222 function restoreSelection( selection )
\r
224 if ( selection.isLocked )
\r
226 selection.unlock();
\r
227 setTimeout( function() { selection.lock(); }, 0 );
\r
231 function isBlankParagraph( block )
\r
233 return block.getOuterHtml().match( emptyParagraphRegexp );
\r
236 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
\r
238 // Gecko need a key event to 'wake up' the editing
\r
239 // ability when document is empty.(#3864, #5781)
\r
240 function activateEditing( editor )
\r
242 var win = editor.window,
\r
243 doc = editor.document,
\r
244 body = editor.document.getBody(),
\r
245 bodyChildsNum = body.getChildren().count();
\r
247 if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )
\r
249 restoreDirty( editor );
\r
251 // Memorize scroll position to restore it later (#4472).
\r
252 var hostDocument = editor.element.getDocument();
\r
253 var hostDocumentElement = hostDocument.getDocumentElement();
\r
254 var scrollTop = hostDocumentElement.$.scrollTop;
\r
255 var scrollLeft = hostDocumentElement.$.scrollLeft;
\r
257 // Simulating keyboard character input by dispatching a keydown of white-space text.
\r
258 var keyEventSimulate = doc.$.createEvent( "KeyEvents" );
\r
259 keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,
\r
260 false, false, false, 0, 32 );
\r
261 doc.$.dispatchEvent( keyEventSimulate );
\r
263 if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )
\r
264 hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );
\r
266 // Restore the original document status by placing the cursor before a bogus br created (#5021).
\r
267 bodyChildsNum && body.getFirst().remove();
\r
268 doc.getBody().appendBogus();
\r
269 var nativeRange = new CKEDITOR.dom.range( doc );
\r
270 nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );
\r
271 nativeRange.select();
\r
276 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
\r
277 * non-exitable-block by padding extra br.(#3189)
\r
279 function onSelectionChangeFixBody( evt )
\r
281 var editor = evt.editor,
\r
282 path = evt.data.path,
\r
283 blockLimit = path.blockLimit,
\r
284 selection = evt.data.selection,
\r
285 range = selection.getRanges()[0],
\r
286 body = editor.document.getBody(),
\r
287 enterMode = editor.config.enterMode;
\r
289 CKEDITOR.env.gecko && activateEditing( editor );
\r
291 // When enterMode set to block, we'll establing new paragraph only if we're
\r
292 // selecting inline contents right under body. (#3657)
\r
293 if ( enterMode != CKEDITOR.ENTER_BR
\r
295 && blockLimit.getName() == 'body'
\r
298 editor.fire( 'updateSnapshot' );
\r
299 restoreDirty( editor );
\r
300 CKEDITOR.env.ie && restoreSelection( selection );
\r
302 var fixedBlock = range.fixBlock( true,
\r
303 editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
\r
305 // For IE, we should remove any filler node which was introduced before.
\r
306 if ( CKEDITOR.env.ie )
\r
308 var first = fixedBlock.getFirst( isNotEmpty );
\r
309 first && isNbsp( first ) && first.remove();
\r
312 // If the fixed block is actually blank and is already followed by an exitable blank
\r
313 // block, we should revert the fix and move into the existed one. (#3684)
\r
314 if ( isBlankParagraph( fixedBlock ) )
\r
316 var element = fixedBlock.getNext( isNotWhitespace );
\r
318 element.type == CKEDITOR.NODE_ELEMENT &&
\r
319 !nonExitableElementNames[ element.getName() ] )
\r
321 range.moveToElementEditStart( element );
\r
322 fixedBlock.remove();
\r
326 element = fixedBlock.getPrevious( isNotWhitespace );
\r
328 element.type == CKEDITOR.NODE_ELEMENT &&
\r
329 !nonExitableElementNames[ element.getName() ] )
\r
331 range.moveToElementEditEnd( element );
\r
332 fixedBlock.remove();
\r
338 // Notify non-IE that selection has changed.
\r
339 if ( !CKEDITOR.env.ie )
\r
340 editor.selectionChange();
\r
343 // All browsers are incapable to moving cursor out of certain non-exitable
\r
344 // blocks (e.g. table, list, pre) at the end of document, make this happen by
\r
345 // place a bogus node there, which would be later removed by dataprocessor.
\r
346 var walkerRange = new CKEDITOR.dom.range( editor.document ),
\r
347 walker = new CKEDITOR.dom.walker( walkerRange );
\r
348 walkerRange.selectNodeContents( body );
\r
349 walker.evaluator = function( node )
\r
351 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
\r
353 walker.guard = function( node, isMoveout )
\r
355 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
\r
358 if ( walker.previous() )
\r
360 editor.fire( 'updateSnapshot' );
\r
361 restoreDirty( editor );
\r
362 CKEDITOR.env.ie && restoreSelection( selection );
\r
365 if ( enterMode != CKEDITOR.ENTER_BR )
\r
366 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
\r
368 paddingBlock = body;
\r
370 if ( !CKEDITOR.env.ie )
\r
371 paddingBlock.appendBogus();
\r
375 CKEDITOR.plugins.add( 'wysiwygarea',
\r
377 requires : [ 'editingblock' ],
\r
379 init : function( editor )
\r
381 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
\r
382 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
\r
384 var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
\r
386 var contentDomReadyHandler;
\r
387 editor.on( 'editingBlockReady', function()
\r
397 // Support for custom document.domain in IE.
\r
398 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
400 // Creates the iframe that holds the editable document.
\r
401 var createIFrame = function( data )
\r
408 'document.open();' +
\r
410 // The document domain must be set any time we
\r
411 // call document.open().
\r
412 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
414 'document.close();';
\r
416 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
417 ' style="width:100%;height:100%"' +
\r
418 ' frameBorder="0"' +
\r
419 ' title="' + frameLabel + '"' +
\r
420 // With IE, the custom domain has to be taken care at first,
\r
421 // for other browers, the 'src' attribute should be left empty to
\r
422 // trigger iframe's 'load' event.
\r
423 ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +
\r
424 ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +
\r
425 ' allowTransparency="true"' +
\r
428 // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)
\r
429 if ( document.location.protocol == 'chrome:' )
\r
430 CKEDITOR.event.useCapture = true;
\r
432 // With FF, it's better to load the data on iframe.load. (#3894,#4058)
\r
433 iframe.on( 'load', function( ev )
\r
436 ev.removeListener();
\r
438 var doc = iframe.getFrameDocument().$;
\r
440 // Don't leave any history log in IE. (#5657)
\r
441 doc.open( "text/html","replace" );
\r
446 // Reset adjustment back to default (#5689)
\r
447 if ( document.location.protocol == 'chrome:' )
\r
448 CKEDITOR.event.useCapture = false;
\r
450 // The container must be visible when creating the iframe in FF (#5956)
\r
451 var element = editor.element,
\r
452 isHidden = CKEDITOR.env.gecko && !element.isVisible(),
\r
453 previousStyles = {};
\r
458 position : element.getStyle( 'position' ),
\r
459 top : element.getStyle( 'top' )
\r
461 element.setStyles( { position : 'absolute', top : '-3000px' } );
\r
464 mainElement.append( iframe );
\r
468 setTimeout( function()
\r
471 element.setStyles( previousStyles );
\r
476 // The script that launches the bootstrap logic on 'domReady', so the document
\r
477 // is fully editable even before the editing iframe is fully loaded (#4455).
\r
478 contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );
\r
479 var activationScript =
\r
480 '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
\r
481 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
482 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +
\r
485 // Editing area bootstrap code.
\r
486 function contentDomReady( domWindow )
\r
488 if ( !frameLoaded )
\r
492 editor.fire( 'ariaWidget', iframe );
\r
494 var domDocument = domWindow.document,
\r
495 body = domDocument.body;
\r
497 // Remove this script from the DOM.
\r
498 var script = domDocument.getElementById( "cke_actscrpt" );
\r
499 script.parentNode.removeChild( script );
\r
501 body.spellcheck = !editor.config.disableNativeSpellChecker;
\r
503 if ( CKEDITOR.env.ie )
\r
505 // Don't display the focus border.
\r
506 body.hideFocus = true;
\r
508 // Disable and re-enable the body to avoid IE from
\r
509 // taking the editing focus at startup. (#141 / #523)
\r
510 body.disabled = true;
\r
511 body.contentEditable = true;
\r
512 body.removeAttribute( 'disabled' );
\r
516 // Avoid opening design mode in a frame window thread,
\r
517 // which will cause host page scrolling.(#4397)
\r
518 setTimeout( function()
\r
520 // Prefer 'contentEditable' instead of 'designMode'. (#3593)
\r
521 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
\r
522 || CKEDITOR.env.opera )
\r
523 domDocument.$.body.contentEditable = true;
\r
524 else if ( CKEDITOR.env.webkit )
\r
525 domDocument.$.body.parentNode.contentEditable = true;
\r
527 domDocument.$.designMode = 'on';
\r
531 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
\r
533 domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
\r
534 domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
\r
536 domDocument.on( 'dblclick', function( evt )
\r
538 var element = evt.data.getTarget(),
\r
539 data = { element : element, dialog : '' };
\r
540 editor.fire( 'doubleclick', data );
\r
541 data.dialog && editor.openDialog( data.dialog );
\r
544 // Gecko/Webkit need some help when selecting control type elements. (#3448)
\r
545 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )
\r
547 domDocument.on( 'mousedown', function( ev )
\r
549 var control = ev.data.getTarget();
\r
550 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
\r
551 editor.getSelection().selectElement( control );
\r
555 if ( CKEDITOR.env.gecko )
\r
557 domDocument.on( 'mouseup', function( ev )
\r
559 if ( ev.data.$.button == 2 )
\r
561 var target = ev.data.getTarget();
\r
563 // Prevent right click from selecting an empty block even
\r
564 // when selection is anchored inside it. (#5845)
\r
565 if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )
\r
567 var range = new CKEDITOR.dom.range( domDocument );
\r
568 range.moveToElementEditStart( target );
\r
569 range.select( true );
\r
575 // Prevent the browser opening links in read-only blocks. (#6032)
\r
576 domDocument.on( 'click', function( ev )
\r
579 if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )
\r
580 ev.preventDefault();
\r
583 // Webkit: avoid from editing form control elements content.
\r
584 if ( CKEDITOR.env.webkit )
\r
586 // Prevent from tick checkbox/radiobox/select
\r
587 domDocument.on( 'click', function( ev )
\r
589 if ( ev.data.getTarget().is( 'input', 'select' ) )
\r
590 ev.data.preventDefault();
\r
593 // Prevent from editig textfield/textarea value.
\r
594 domDocument.on( 'mouseup', function( ev )
\r
596 if ( ev.data.getTarget().is( 'input', 'textarea' ) )
\r
597 ev.data.preventDefault();
\r
601 // IE standard compliant in editing frame doesn't focus the editor when
\r
602 // clicking outside actual content, manually apply the focus. (#1659)
\r
603 if ( CKEDITOR.env.ie
\r
604 && domDocument.$.compatMode == 'CSS1Compat'
\r
605 || CKEDITOR.env.gecko
\r
606 || CKEDITOR.env.opera )
\r
608 var htmlElement = domDocument.getDocumentElement();
\r
609 htmlElement.on( 'mousedown', function( evt )
\r
611 // Setting focus directly on editor doesn't work, we
\r
612 // have to use here a temporary element to 'redirect'
\r
614 if ( evt.data.getTarget().equals( htmlElement ) )
\r
616 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
618 focusGrabber.focus();
\r
623 domWindow.on( 'blur', function()
\r
625 editor.focusManager.blur();
\r
628 domWindow.on( 'focus', function()
\r
630 var doc = editor.document;
\r
632 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
634 else if ( CKEDITOR.env.opera )
\r
635 doc.getBody().focus();
\r
637 editor.focusManager.focus();
\r
640 var keystrokeHandler = editor.keystrokeHandler;
\r
641 if ( keystrokeHandler )
\r
642 keystrokeHandler.attach( domDocument );
\r
644 if ( CKEDITOR.env.ie )
\r
646 domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
\r
647 // Override keystrokes which should have deletion behavior
\r
648 // on control types in IE . (#4047)
\r
649 domDocument.on( 'keydown', function( evt )
\r
651 var keyCode = evt.data.getKeystroke();
\r
653 // Backspace OR Delete.
\r
654 if ( keyCode in { 8 : 1, 46 : 1 } )
\r
656 var sel = editor.getSelection(),
\r
657 control = sel.getSelectedElement();
\r
661 // Make undo snapshot.
\r
662 editor.fire( 'saveSnapshot' );
\r
664 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
\r
665 // break up the selection, safely manage it here. (#4795)
\r
666 var bookmark = sel.getRanges()[ 0 ].createBookmark();
\r
667 // Remove the control manually.
\r
669 sel.selectBookmarks( [ bookmark ] );
\r
671 editor.fire( 'saveSnapshot' );
\r
673 evt.data.preventDefault();
\r
678 // PageUp/PageDown scrolling is broken in document
\r
679 // with standard doctype, manually fix it. (#4736)
\r
680 if ( domDocument.$.compatMode == 'CSS1Compat' )
\r
682 var pageUpDownKeys = { 33 : 1, 34 : 1 };
\r
683 domDocument.on( 'keydown', function( evt )
\r
685 if ( evt.data.getKeystroke() in pageUpDownKeys )
\r
687 setTimeout( function ()
\r
689 editor.getSelection().scrollIntoView();
\r
696 // Adds the document body as a context menu target.
\r
697 if ( editor.contextMenu )
\r
698 editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
\r
700 setTimeout( function()
\r
702 editor.fire( 'contentDom' );
\r
706 editor.mode = 'wysiwyg';
\r
707 editor.fire( 'mode' );
\r
711 isLoadingData = false;
\r
713 if ( isPendingFocus )
\r
716 isPendingFocus = false;
\r
718 setTimeout( function()
\r
720 editor.fire( 'dataReady' );
\r
723 // IE, Opera and Safari may not support it and throw errors.
\r
724 try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
\r
725 try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
\r
728 * IE BUG: IE might have rendered the iframe with invisible contents.
\r
729 * (#3623). Push some inconsequential CSS style changes to force IE to
\r
732 * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
\r
733 * fix the problem. :(
\r
735 if ( CKEDITOR.env.ie )
\r
737 setTimeout( function()
\r
739 if ( editor.document )
\r
741 var $body = editor.document.$.body;
\r
742 $body.runtimeStyle.marginBottom = '0px';
\r
743 $body.runtimeStyle.marginBottom = '';
\r
751 editor.addMode( 'wysiwyg',
\r
753 load : function( holderElement, data, isSnapshot )
\r
755 mainElement = holderElement;
\r
757 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
758 holderElement.setStyle( 'position', 'relative' );
\r
760 // The editor data "may be dirty" after this
\r
762 editor.mayBeDirty = true;
\r
767 this.loadSnapshotData( data );
\r
769 this.loadData( data );
\r
772 loadData : function( data )
\r
774 isLoadingData = true;
\r
776 var config = editor.config,
\r
777 fullPage = config.fullPage,
\r
778 docType = config.docType;
\r
780 // Build the additional stuff to be included into <head>.
\r
782 '<style type="text/css" cke_temp="1">' +
\r
783 editor._.styles.join( '\n' ) +
\r
786 !fullPage && ( headExtra =
\r
787 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
790 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
\r
794 // Search and sweep out the doctype declaration.
\r
795 data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
\r
797 editor.docType = docType = match;
\r
802 // Get the HTML version of the data.
\r
803 if ( editor.dataProcessor )
\r
804 data = editor.dataProcessor.toHtml( data, fixForBody );
\r
808 // Check if the <body> tag is available.
\r
809 if ( !(/<body[\s|>]/).test( data ) )
\r
810 data = '<body>' + data;
\r
812 // Check if the <html> tag is available.
\r
813 if ( !(/<html[\s|>]/).test( data ) )
\r
814 data = '<html>' + data + '</html>';
\r
816 // Check if the <head> tag is available.
\r
817 if ( !(/<head[\s|>]/).test( data ) )
\r
818 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
\r
819 else if ( !(/<title[\s|>]/).test( data ) )
\r
820 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;
\r
822 // The base must be the first tag in the HEAD, e.g. to get relative
\r
823 // links on styles.
\r
824 baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
\r
826 // Inject the extra stuff into <head>.
\r
827 // Attention: do not change it before testing it well. (V2)
\r
828 // This is tricky... if the head ends with <meta ... content type>,
\r
829 // Firefox will break. But, it works if we place our extra stuff as
\r
830 // the last elements in the HEAD.
\r
831 data = data.replace( /<\/head\s*>/, headExtra + '$&' );
\r
833 // Add the DOCTYPE back to it.
\r
834 data = docType + data;
\r
840 '<html dir="' + config.contentsLangDirection + '"' +
\r
841 ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +
\r
843 '<title>' + frameLabel + '</title>' +
\r
847 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
\r
848 ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
\r
854 data += activationScript;
\r
857 // The iframe is recreated on each call of setData, so we need to clear DOM objects
\r
859 createIFrame( data );
\r
862 getData : function()
\r
864 var config = editor.config,
\r
865 fullPage = config.fullPage,
\r
866 docType = fullPage && editor.docType,
\r
867 doc = iframe.getFrameDocument();
\r
869 var data = fullPage
\r
870 ? doc.getDocumentElement().getOuterHtml()
\r
871 : doc.getBody().getHtml();
\r
873 if ( editor.dataProcessor )
\r
874 data = editor.dataProcessor.toDataFormat( data, fixForBody );
\r
876 // Strip the last blank paragraph within document.
\r
877 if ( config.ignoreEmptyParagraph )
\r
878 data = data.replace( emptyParagraphRegexp, '' );
\r
881 data = docType + '\n' + data;
\r
886 getSnapshotData : function()
\r
888 return iframe.getFrameDocument().getBody().getHtml();
\r
891 loadSnapshotData : function( data )
\r
893 iframe.getFrameDocument().getBody().setHtml( data );
\r
896 onDispose : function()
\r
898 if ( !editor.document )
\r
901 editor.document.getDocumentElement().clearCustomData();
\r
902 editor.document.getBody().clearCustomData();
\r
904 editor.window.clearCustomData();
\r
905 editor.document.clearCustomData();
\r
907 iframe.clearCustomData();
\r
910 * IE BUG: When destroying editor DOM with the selection remains inside
\r
911 * editing area would break IE7/8's selection system, we have to put the editing
\r
912 * iframe offline first. (#3812 and #5441)
\r
917 unload : function( holderElement )
\r
921 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
\r
923 editor.fire( 'contentDomUnload' );
\r
928 if ( isLoadingData )
\r
929 isPendingFocus = true;
\r
930 // Temporary solution caused by #6025, supposed be unified by #6154.
\r
931 else if ( CKEDITOR.env.opera && editor.document )
\r
933 editor.document.getBody().focus();
\r
935 editor.selectionChange();
\r
937 else if ( !CKEDITOR.env.opera && editor.window )
\r
939 editor.window.focus();
\r
941 editor.selectionChange();
\r
946 editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
\r
947 editor.on( 'insertElement', onInsertElement, null, null, 20 );
\r
948 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
\r
949 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
\r
953 // Setting voice label as window title, backup the original one
\r
954 // and restore it before running into use.
\r
955 editor.on( 'contentDom', function ()
\r
957 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
\r
958 title.setAttribute( '_cke_title', editor.document.$.title );
\r
959 editor.document.$.title = frameLabel;
\r
962 // IE8 stricts mode doesn't have 'contentEditable' in effect
\r
963 // on element unless it has layout. (#5562)
\r
964 if ( CKEDITOR.env.ie8Compat )
\r
966 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );
\r
968 var selectors = [];
\r
969 for ( var tag in CKEDITOR.dtd.$removeEmpty )
\r
970 selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );
\r
971 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );
\r
974 // Switch on design mode for a short while and close it after then.
\r
975 function blinkCursor( retry )
\r
977 CKEDITOR.tools.tryThese(
\r
980 editor.document.$.designMode = 'on';
\r
981 setTimeout( function ()
\r
983 editor.document.$.designMode = 'off';
\r
984 editor.document.getBody().focus();
\r
989 // The above call is known to fail when parent DOM
\r
990 // tree layout changes may break design mode. (#5782)
\r
991 // Refresh the 'contentEditable' is a cue to this.
\r
992 editor.document.$.designMode = 'off';
\r
993 var body = editor.document.getBody();
\r
994 body.setAttribute( 'contentEditable', false );
\r
995 body.setAttribute( 'contentEditable', true );
\r
996 // Try it again once..
\r
997 !retry && blinkCursor( 1 );
\r
1001 // Create an invisible element to grab focus.
\r
1002 if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )
\r
1005 editor.on( 'uiReady', function()
\r
1007 focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
\r
1008 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
\r
1009 '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );
\r
1011 focusGrabber.on( 'focus', function()
\r
1016 editor.on( 'destroy', function()
\r
1018 CKEDITOR.tools.removeFunction( contentDomReadyHandler );
\r
1019 focusGrabber.clearCustomData();
\r
1023 // Disable form elements editing mode provided by some browers. (#5746)
\r
1024 editor.on( 'insertElement', function ( evt )
\r
1026 var element = evt.data;
\r
1027 if ( element.type == CKEDITOR.NODE_ELEMENT
\r
1028 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )
\r
1030 if ( !element.isReadOnly() )
\r
1032 element.setAttribute( 'contentEditable', false );
\r
1033 // We should flag that the element was locked by our code so
\r
1034 // it'll be editable by the editor functions (#6046).
\r
1035 element.setCustomData( '_cke_notReadOnly', 1 );
\r
1043 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
\r
1044 if ( CKEDITOR.env.gecko )
\r
1048 var body = document.body;
\r
1051 window.addEventListener( 'load', arguments.callee, false );
\r
1054 var currentHandler = body.getAttribute( 'onpageshow' );
\r
1055 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +
\r
1056 'event.persisted && (function(){' +
\r
1057 'var allInstances = CKEDITOR.instances, editor, doc;' +
\r
1058 'for ( var i in allInstances )' +
\r
1060 ' editor = allInstances[ i ];' +
\r
1061 ' doc = editor.document;' +
\r
1064 ' doc.$.designMode = "off";' +
\r
1065 ' doc.$.designMode = "on";' +
\r
1076 * Disables the ability of resize objects (image and tables) in the editing
\r
1081 * config.disableObjectResizing = true;
\r
1083 CKEDITOR.config.disableObjectResizing = false;
\r
1086 * Disables the "table tools" offered natively by the browser (currently
\r
1087 * Firefox only) to make quick table editing operations, like adding or
\r
1088 * deleting rows and columns.
\r
1092 * config.disableNativeTableHandles = false;
\r
1094 CKEDITOR.config.disableNativeTableHandles = true;
\r
1097 * Disables the built-in spell checker while typing natively available in the
\r
1098 * browser (currently Firefox and Safari only).<br /><br />
\r
1100 * Even if word suggestions will not appear in the CKEditor context menu, this
\r
1101 * feature is useful to help quickly identifying misspelled words.<br /><br />
\r
1103 * This setting is currently compatible with Firefox only due to limitations in
\r
1108 * config.disableNativeSpellChecker = false;
\r
1110 CKEDITOR.config.disableNativeSpellChecker = true;
\r
1113 * Whether the editor must output an empty value ("") if it's contents is made
\r
1114 * by an empty paragraph only.
\r
1118 * config.ignoreEmptyParagraph = false;
\r
1120 CKEDITOR.config.ignoreEmptyParagraph = true;
\r
1123 * Fired when data is loaded and ready for retrieval in an editor instance.
\r
1124 * @name CKEDITOR.editor#dataReady
\r