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 // Elements that could have empty new line around, including table, pre-formatted block, hr, page-break. (#6554)
\r
22 function nonExitable( element )
\r
24 return ( element.getName() in nonExitableElementNames )
\r
25 || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];
\r
28 function checkReadOnly( selection )
\r
30 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )
\r
31 return selection.getSelectedElement().isReadOnly();
\r
33 return selection.getCommonAncestor().isReadOnly();
\r
36 function onInsertHtml( evt )
\r
38 if ( this.mode == 'wysiwyg' )
\r
42 var selection = this.getSelection();
\r
43 if ( checkReadOnly( selection ) )
\r
46 var data = evt.data;
\r
47 this.fire( 'saveSnapshot' );
\r
49 if ( this.dataProcessor )
\r
50 data = this.dataProcessor.toHtml( data );
\r
52 if ( CKEDITOR.env.ie )
\r
54 var selIsLocked = selection.isLocked;
\r
59 var $sel = selection.getNative();
\r
61 // Delete control selections to avoid IE bugs on pasteHTML.
\r
62 if ( $sel.type == 'Control' )
\r
64 else if ( selection.getType() == CKEDITOR.SELECTION_TEXT )
\r
66 // Due to IE bugs on handling contenteditable=false blocks
\r
67 // (#6005), we need to make some checks and eventually
\r
68 // delete the selection first.
\r
70 var range = selection.getRanges()[0],
\r
71 endContainer = range && range.endContainer;
\r
73 if ( endContainer &&
\r
74 endContainer.type == CKEDITOR.NODE_ELEMENT &&
\r
75 endContainer.getAttribute( 'contenteditable' ) == 'false' &&
\r
76 range.checkBoundaryOfElement( endContainer, CKEDITOR.END ) )
\r
78 range.setEndAfter( range.endContainer );
\r
79 range.deleteContents();
\r
85 $sel.createRange().pasteHTML( data );
\r
90 this.getSelection().lock();
\r
93 this.document.$.execCommand( 'inserthtml', false, data );
\r
95 // Webkit does not scroll to the cursor position after pasting (#5558)
\r
96 if ( CKEDITOR.env.webkit )
\r
98 this.document.$.execCommand( 'inserthtml', false, '<span id="cke_paste_marker" cke_temp="1"></span>' );
\r
99 var marker = this.document.getById( 'cke_paste_marker' );
\r
100 marker.scrollIntoView();
\r
105 CKEDITOR.tools.setTimeout( function()
\r
107 this.fire( 'saveSnapshot' );
\r
112 function onInsertElement( evt )
\r
114 if ( this.mode == 'wysiwyg' )
\r
118 var selection = this.getSelection();
\r
119 if ( checkReadOnly( selection ) )
\r
122 this.fire( 'saveSnapshot' );
\r
124 var ranges = selection.getRanges(),
\r
125 element = evt.data,
\r
126 elementName = element.getName(),
\r
127 isBlock = CKEDITOR.dtd.$block[ elementName ];
\r
129 var selIsLocked = selection.isLocked;
\r
132 selection.unlock();
\r
134 var range, clone, lastElement, bookmark;
\r
136 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
\r
138 range = ranges[ i ];
\r
140 // Remove the original contents.
\r
141 range.deleteContents();
\r
143 clone = !i && element || element.clone( 1 );
\r
145 // If we're inserting a block at dtd-violated position, split
\r
146 // the parent blocks until we reach blockLimit.
\r
150 while ( ( current = range.getCommonAncestor( 0, 1 ) )
\r
151 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
\r
152 && !( dtd && dtd [ elementName ] ) )
\r
154 // Split up inline elements.
\r
155 if ( current.getName() in CKEDITOR.dtd.span )
\r
156 range.splitElement( current );
\r
157 // If we're in an empty block which indicate a new paragraph,
\r
158 // simply replace it with the inserting block.(#3664)
\r
159 else if ( range.checkStartOfBlock()
\r
160 && range.checkEndOfBlock() )
\r
162 range.setStartBefore( current );
\r
163 range.collapse( true );
\r
167 range.splitBlock();
\r
171 // Insert the new node.
\r
172 range.insertNode( clone );
\r
174 // Save the last element reference so we can make the
\r
175 // selection later.
\r
176 if ( !lastElement )
\r
177 lastElement = clone;
\r
180 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
\r
182 // If we're inserting a block element immediatelly followed by
\r
183 // another block element, the selection must move there. (#3100,#5436)
\r
186 var next = lastElement.getNext( notWhitespaceEval ),
\r
187 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
\r
189 // Check if it's a block element that accepts text.
\r
190 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
\r
191 range.moveToElementEditStart( next );
\r
194 selection.selectRanges( [ range ] );
\r
197 this.getSelection().lock();
\r
199 // Save snaps after the whole execution completed.
\r
200 // This's a workaround for make DOM modification's happened after
\r
201 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
\r
203 CKEDITOR.tools.setTimeout( function(){
\r
204 this.fire( 'saveSnapshot' );
\r
209 // DOM modification here should not bother dirty flag.(#4385)
\r
210 function restoreDirty( editor )
\r
212 if ( !editor.checkDirty() )
\r
213 setTimeout( function(){ editor.resetDirty(); }, 0 );
\r
216 var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
\r
217 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
\r
219 function isNotEmpty( node )
\r
221 return isNotWhitespace( node ) && isNotBookmark( node );
\r
224 function isNbsp( node )
\r
226 return node.type == CKEDITOR.NODE_TEXT
\r
227 && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
\r
230 function restoreSelection( selection )
\r
232 if ( selection.isLocked )
\r
234 selection.unlock();
\r
235 setTimeout( function() { selection.lock(); }, 0 );
\r
239 function isBlankParagraph( block )
\r
241 return block.getOuterHtml().match( emptyParagraphRegexp );
\r
244 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
\r
246 // Gecko need a key event to 'wake up' the editing
\r
247 // ability when document is empty.(#3864, #5781)
\r
248 function activateEditing( editor )
\r
250 var win = editor.window,
\r
251 doc = editor.document,
\r
252 body = editor.document.getBody(),
\r
253 bodyChildsNum = body.getChildren().count();
\r
255 if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )
\r
257 restoreDirty( editor );
\r
259 // Memorize scroll position to restore it later (#4472).
\r
260 var hostDocument = editor.element.getDocument();
\r
261 var hostDocumentElement = hostDocument.getDocumentElement();
\r
262 var scrollTop = hostDocumentElement.$.scrollTop;
\r
263 var scrollLeft = hostDocumentElement.$.scrollLeft;
\r
265 // Simulating keyboard character input by dispatching a keydown of white-space text.
\r
266 var keyEventSimulate = doc.$.createEvent( "KeyEvents" );
\r
267 keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,
\r
268 false, false, false, 0, 32 );
\r
269 doc.$.dispatchEvent( keyEventSimulate );
\r
271 if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )
\r
272 hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );
\r
274 // Restore the original document status by placing the cursor before a bogus br created (#5021).
\r
275 bodyChildsNum && body.getFirst().remove();
\r
276 doc.getBody().appendBogus();
\r
277 var nativeRange = new CKEDITOR.dom.range( doc );
\r
278 nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );
\r
279 nativeRange.select();
\r
284 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
\r
285 * non-exitable-block by padding extra br.(#3189)
\r
287 function onSelectionChangeFixBody( evt )
\r
289 var editor = evt.editor,
\r
290 path = evt.data.path,
\r
291 blockLimit = path.blockLimit,
\r
292 selection = evt.data.selection,
\r
293 range = selection.getRanges()[0],
\r
294 body = editor.document.getBody(),
\r
295 enterMode = editor.config.enterMode;
\r
297 CKEDITOR.env.gecko && activateEditing( editor );
\r
299 // When enterMode set to block, we'll establing new paragraph only if we're
\r
300 // selecting inline contents right under body. (#3657)
\r
301 if ( enterMode != CKEDITOR.ENTER_BR
\r
303 && blockLimit.getName() == 'body'
\r
306 editor.fire( 'updateSnapshot' );
\r
307 restoreDirty( editor );
\r
308 CKEDITOR.env.ie && restoreSelection( selection );
\r
310 var fixedBlock = range.fixBlock( true,
\r
311 editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
\r
313 // For IE, we should remove any filler node which was introduced before.
\r
314 if ( CKEDITOR.env.ie )
\r
316 var first = fixedBlock.getFirst( isNotEmpty );
\r
317 first && isNbsp( first ) && first.remove();
\r
320 // If the fixed block is actually blank and is already followed by an exitable blank
\r
321 // block, we should revert the fix and move into the existed one. (#3684)
\r
322 if ( isBlankParagraph( fixedBlock ) )
\r
324 var element = fixedBlock.getNext( isNotWhitespace );
\r
326 element.type == CKEDITOR.NODE_ELEMENT &&
\r
327 !nonExitable( element ) )
\r
329 range.moveToElementEditStart( element );
\r
330 fixedBlock.remove();
\r
334 element = fixedBlock.getPrevious( isNotWhitespace );
\r
336 element.type == CKEDITOR.NODE_ELEMENT &&
\r
337 !nonExitable( element ) )
\r
339 range.moveToElementEditEnd( element );
\r
340 fixedBlock.remove();
\r
346 // Notify non-IE that selection has changed.
\r
347 if ( !CKEDITOR.env.ie )
\r
348 editor.selectionChange();
\r
351 // All browsers are incapable to moving cursor out of certain non-exitable
\r
352 // blocks (e.g. table, list, pre) at the end of document, make this happen by
\r
353 // place a bogus node there, which would be later removed by dataprocessor.
\r
354 var walkerRange = new CKEDITOR.dom.range( editor.document ),
\r
355 walker = new CKEDITOR.dom.walker( walkerRange );
\r
356 walkerRange.selectNodeContents( body );
\r
357 walker.evaluator = function( node )
\r
359 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
\r
361 walker.guard = function( node, isMoveout )
\r
363 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
\r
366 if ( walker.previous() )
\r
368 editor.fire( 'updateSnapshot' );
\r
369 restoreDirty( editor );
\r
370 CKEDITOR.env.ie && restoreSelection( selection );
\r
373 if ( enterMode != CKEDITOR.ENTER_BR )
\r
374 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
\r
376 paddingBlock = body;
\r
378 if ( !CKEDITOR.env.ie )
\r
379 paddingBlock.appendBogus();
\r
383 CKEDITOR.plugins.add( 'wysiwygarea',
\r
385 requires : [ 'editingblock' ],
\r
387 init : function( editor )
\r
389 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
\r
390 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
\r
392 var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
\r
394 var contentDomReadyHandler;
\r
395 editor.on( 'editingBlockReady', function()
\r
405 // Support for custom document.domain in IE.
\r
406 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
408 // Creates the iframe that holds the editable document.
\r
409 var createIFrame = function( data )
\r
416 'document.open();' +
\r
418 // The document domain must be set any time we
\r
419 // call document.open().
\r
420 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
422 'document.close();';
\r
424 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
425 ' style="width:100%;height:100%"' +
\r
426 ' frameBorder="0"' +
\r
427 ' title="' + frameLabel + '"' +
\r
428 // With IE, the custom domain has to be taken care at first,
\r
429 // for other browers, the 'src' attribute should be left empty to
\r
430 // trigger iframe's 'load' event.
\r
431 ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +
\r
432 ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +
\r
433 ' allowTransparency="true"' +
\r
436 // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)
\r
437 if ( document.location.protocol == 'chrome:' )
\r
438 CKEDITOR.event.useCapture = true;
\r
440 // With FF, it's better to load the data on iframe.load. (#3894,#4058)
\r
441 iframe.on( 'load', function( ev )
\r
444 ev.removeListener();
\r
446 var doc = iframe.getFrameDocument().$;
\r
448 // Don't leave any history log in IE. (#5657)
\r
449 doc.open( "text/html","replace" );
\r
454 // Reset adjustment back to default (#5689)
\r
455 if ( document.location.protocol == 'chrome:' )
\r
456 CKEDITOR.event.useCapture = false;
\r
458 // The container must be visible when creating the iframe in FF (#5956)
\r
459 var element = editor.element,
\r
460 isHidden = CKEDITOR.env.gecko && !element.isVisible(),
\r
461 previousStyles = {};
\r
466 position : element.getStyle( 'position' ),
\r
467 top : element.getStyle( 'top' )
\r
469 element.setStyles( { position : 'absolute', top : '-3000px' } );
\r
472 mainElement.append( iframe );
\r
476 setTimeout( function()
\r
479 element.setStyles( previousStyles );
\r
484 // The script that launches the bootstrap logic on 'domReady', so the document
\r
485 // is fully editable even before the editing iframe is fully loaded (#4455).
\r
486 contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );
\r
487 var activationScript =
\r
488 '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
\r
489 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
490 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +
\r
493 // Editing area bootstrap code.
\r
494 function contentDomReady( domWindow )
\r
496 if ( !frameLoaded )
\r
500 editor.fire( 'ariaWidget', iframe );
\r
502 var domDocument = domWindow.document,
\r
503 body = domDocument.body;
\r
505 // Remove this script from the DOM.
\r
506 var script = domDocument.getElementById( "cke_actscrpt" );
\r
507 script.parentNode.removeChild( script );
\r
509 body.spellcheck = !editor.config.disableNativeSpellChecker;
\r
511 if ( CKEDITOR.env.ie )
\r
513 // Don't display the focus border.
\r
514 body.hideFocus = true;
\r
516 // Disable and re-enable the body to avoid IE from
\r
517 // taking the editing focus at startup. (#141 / #523)
\r
518 body.disabled = true;
\r
519 body.contentEditable = true;
\r
520 body.removeAttribute( 'disabled' );
\r
524 // Avoid opening design mode in a frame window thread,
\r
525 // which will cause host page scrolling.(#4397)
\r
526 setTimeout( function()
\r
528 // Prefer 'contentEditable' instead of 'designMode'. (#3593)
\r
529 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
\r
530 || CKEDITOR.env.opera )
\r
531 domDocument.$.body.contentEditable = true;
\r
532 else if ( CKEDITOR.env.webkit )
\r
533 domDocument.$.body.parentNode.contentEditable = true;
\r
535 domDocument.$.designMode = 'on';
\r
539 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
\r
541 domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
\r
542 domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
\r
544 domDocument.on( 'dblclick', function( evt )
\r
546 var element = evt.data.getTarget(),
\r
547 data = { element : element, dialog : '' };
\r
548 editor.fire( 'doubleclick', data );
\r
549 data.dialog && editor.openDialog( data.dialog );
\r
552 // Gecko/Webkit need some help when selecting control type elements. (#3448)
\r
553 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) )
\r
555 domDocument.on( 'mousedown', function( ev )
\r
557 var control = ev.data.getTarget();
\r
558 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
\r
559 editor.getSelection().selectElement( control );
\r
563 if ( CKEDITOR.env.gecko )
\r
565 domDocument.on( 'mouseup', function( ev )
\r
567 if ( ev.data.$.button == 2 )
\r
569 var target = ev.data.getTarget();
\r
571 // Prevent right click from selecting an empty block even
\r
572 // when selection is anchored inside it. (#5845)
\r
573 if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )
\r
575 var range = new CKEDITOR.dom.range( domDocument );
\r
576 range.moveToElementEditStart( target );
\r
577 range.select( true );
\r
583 // Prevent the browser opening links in read-only blocks. (#6032)
\r
584 domDocument.on( 'click', function( ev )
\r
587 if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )
\r
588 ev.preventDefault();
\r
591 // Webkit: avoid from editing form control elements content.
\r
592 if ( CKEDITOR.env.webkit )
\r
594 // Prevent from tick checkbox/radiobox/select
\r
595 domDocument.on( 'click', function( ev )
\r
597 if ( ev.data.getTarget().is( 'input', 'select' ) )
\r
598 ev.data.preventDefault();
\r
601 // Prevent from editig textfield/textarea value.
\r
602 domDocument.on( 'mouseup', function( ev )
\r
604 if ( ev.data.getTarget().is( 'input', 'textarea' ) )
\r
605 ev.data.preventDefault();
\r
609 // IE standard compliant in editing frame doesn't focus the editor when
\r
610 // clicking outside actual content, manually apply the focus. (#1659)
\r
611 if ( CKEDITOR.env.ie
\r
612 && domDocument.$.compatMode == 'CSS1Compat'
\r
613 || CKEDITOR.env.gecko
\r
614 || CKEDITOR.env.opera )
\r
616 var htmlElement = domDocument.getDocumentElement();
\r
617 htmlElement.on( 'mousedown', function( evt )
\r
619 // Setting focus directly on editor doesn't work, we
\r
620 // have to use here a temporary element to 'redirect'
\r
622 if ( evt.data.getTarget().equals( htmlElement ) )
\r
624 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
626 focusGrabber.focus();
\r
631 domWindow.on( 'blur', function()
\r
633 editor.focusManager.blur();
\r
638 domWindow.on( 'focus', function()
\r
640 var doc = editor.document;
\r
642 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
644 else if ( CKEDITOR.env.opera )
\r
645 doc.getBody().focus();
\r
646 // Webkit needs focus for the first time on the HTML element. (#6153)
\r
647 else if ( CKEDITOR.env.webkit )
\r
651 editor.document.getDocumentElement().focus();
\r
656 editor.focusManager.focus();
\r
659 var keystrokeHandler = editor.keystrokeHandler;
\r
660 if ( keystrokeHandler )
\r
661 keystrokeHandler.attach( domDocument );
\r
663 if ( CKEDITOR.env.ie )
\r
665 domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
\r
666 // Override keystrokes which should have deletion behavior
\r
667 // on control types in IE . (#4047)
\r
668 domDocument.on( 'keydown', function( evt )
\r
670 var keyCode = evt.data.getKeystroke();
\r
672 // Backspace OR Delete.
\r
673 if ( keyCode in { 8 : 1, 46 : 1 } )
\r
675 var sel = editor.getSelection(),
\r
676 control = sel.getSelectedElement();
\r
680 // Make undo snapshot.
\r
681 editor.fire( 'saveSnapshot' );
\r
683 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
\r
684 // break up the selection, safely manage it here. (#4795)
\r
685 var bookmark = sel.getRanges()[ 0 ].createBookmark();
\r
686 // Remove the control manually.
\r
688 sel.selectBookmarks( [ bookmark ] );
\r
690 editor.fire( 'saveSnapshot' );
\r
692 evt.data.preventDefault();
\r
697 // PageUp/PageDown scrolling is broken in document
\r
698 // with standard doctype, manually fix it. (#4736)
\r
699 if ( domDocument.$.compatMode == 'CSS1Compat' )
\r
701 var pageUpDownKeys = { 33 : 1, 34 : 1 };
\r
702 domDocument.on( 'keydown', function( evt )
\r
704 if ( evt.data.getKeystroke() in pageUpDownKeys )
\r
706 setTimeout( function ()
\r
708 editor.getSelection().scrollIntoView();
\r
715 // Adds the document body as a context menu target.
\r
716 if ( editor.contextMenu )
\r
717 editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
\r
719 setTimeout( function()
\r
721 editor.fire( 'contentDom' );
\r
725 editor.mode = 'wysiwyg';
\r
726 editor.fire( 'mode' );
\r
730 isLoadingData = false;
\r
732 if ( isPendingFocus )
\r
735 isPendingFocus = false;
\r
737 setTimeout( function()
\r
739 editor.fire( 'dataReady' );
\r
742 // IE, Opera and Safari may not support it and throw errors.
\r
743 try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
\r
744 try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
\r
747 * IE BUG: IE might have rendered the iframe with invisible contents.
\r
748 * (#3623). Push some inconsequential CSS style changes to force IE to
\r
751 * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
\r
752 * fix the problem. :(
\r
754 if ( CKEDITOR.env.ie )
\r
756 setTimeout( function()
\r
758 if ( editor.document )
\r
760 var $body = editor.document.$.body;
\r
761 $body.runtimeStyle.marginBottom = '0px';
\r
762 $body.runtimeStyle.marginBottom = '';
\r
770 editor.addMode( 'wysiwyg',
\r
772 load : function( holderElement, data, isSnapshot )
\r
774 mainElement = holderElement;
\r
776 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
777 holderElement.setStyle( 'position', 'relative' );
\r
779 // The editor data "may be dirty" after this
\r
781 editor.mayBeDirty = true;
\r
786 this.loadSnapshotData( data );
\r
788 this.loadData( data );
\r
791 loadData : function( data )
\r
793 isLoadingData = true;
\r
795 var config = editor.config,
\r
796 fullPage = config.fullPage,
\r
797 docType = config.docType;
\r
799 // Build the additional stuff to be included into <head>.
\r
801 '<style type="text/css" cke_temp="1">' +
\r
802 editor._.styles.join( '\n' ) +
\r
805 !fullPage && ( headExtra =
\r
806 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
809 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
\r
813 // Search and sweep out the doctype declaration.
\r
814 data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
\r
816 editor.docType = docType = match;
\r
821 // Get the HTML version of the data.
\r
822 if ( editor.dataProcessor )
\r
823 data = editor.dataProcessor.toHtml( data, fixForBody );
\r
827 // Check if the <body> tag is available.
\r
828 if ( !(/<body[\s|>]/).test( data ) )
\r
829 data = '<body>' + data;
\r
831 // Check if the <html> tag is available.
\r
832 if ( !(/<html[\s|>]/).test( data ) )
\r
833 data = '<html>' + data + '</html>';
\r
835 // Check if the <head> tag is available.
\r
836 if ( !(/<head[\s|>]/).test( data ) )
\r
837 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
\r
838 else if ( !(/<title[\s|>]/).test( data ) )
\r
839 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;
\r
841 // The base must be the first tag in the HEAD, e.g. to get relative
\r
842 // links on styles.
\r
843 baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
\r
845 // Inject the extra stuff into <head>.
\r
846 // Attention: do not change it before testing it well. (V2)
\r
847 // This is tricky... if the head ends with <meta ... content type>,
\r
848 // Firefox will break. But, it works if we place our extra stuff as
\r
849 // the last elements in the HEAD.
\r
850 data = data.replace( /<\/head\s*>/, headExtra + '$&' );
\r
852 // Add the DOCTYPE back to it.
\r
853 data = docType + data;
\r
859 '<html dir="' + config.contentsLangDirection + '"' +
\r
860 ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +
\r
862 '<title>' + frameLabel + '</title>' +
\r
866 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
\r
867 ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
\r
873 data += activationScript;
\r
876 // The iframe is recreated on each call of setData, so we need to clear DOM objects
\r
878 createIFrame( data );
\r
881 getData : function()
\r
883 var config = editor.config,
\r
884 fullPage = config.fullPage,
\r
885 docType = fullPage && editor.docType,
\r
886 doc = iframe.getFrameDocument();
\r
888 var data = fullPage
\r
889 ? doc.getDocumentElement().getOuterHtml()
\r
890 : doc.getBody().getHtml();
\r
892 if ( editor.dataProcessor )
\r
893 data = editor.dataProcessor.toDataFormat( data, fixForBody );
\r
895 // Reset empty if the document contains only one empty paragraph.
\r
896 if ( config.ignoreEmptyParagraph )
\r
897 data = data.replace( emptyParagraphRegexp, function( match, lookback ) { return lookback; } );
\r
900 data = docType + '\n' + data;
\r
905 getSnapshotData : function()
\r
907 return iframe.getFrameDocument().getBody().getHtml();
\r
910 loadSnapshotData : function( data )
\r
912 iframe.getFrameDocument().getBody().setHtml( data );
\r
915 onDispose : function()
\r
917 if ( !editor.document )
\r
920 editor.document.getDocumentElement().clearCustomData();
\r
921 editor.document.getBody().clearCustomData();
\r
923 editor.window.clearCustomData();
\r
924 editor.document.clearCustomData();
\r
926 iframe.clearCustomData();
\r
929 * IE BUG: When destroying editor DOM with the selection remains inside
\r
930 * editing area would break IE7/8's selection system, we have to put the editing
\r
931 * iframe offline first. (#3812 and #5441)
\r
936 unload : function( holderElement )
\r
940 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
\r
942 editor.fire( 'contentDomUnload' );
\r
947 if ( isLoadingData )
\r
948 isPendingFocus = true;
\r
949 // Temporary solution caused by #6025, supposed be unified by #6154.
\r
950 else if ( CKEDITOR.env.opera && editor.document )
\r
952 // Required for Opera when switching focus
\r
953 // from another iframe, e.g. panels. (#6444)
\r
954 var iframe = editor.window.$.frameElement;
\r
955 iframe.blur(), iframe.focus();
\r
956 editor.document.getBody().focus();
\r
958 editor.selectionChange();
\r
960 else if ( !CKEDITOR.env.opera && editor.window )
\r
962 editor.window.focus();
\r
964 editor.selectionChange();
\r
969 editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
\r
970 editor.on( 'insertElement', onInsertElement, null, null, 20 );
\r
971 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
\r
972 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
\r
976 // Setting voice label as window title, backup the original one
\r
977 // and restore it before running into use.
\r
978 editor.on( 'contentDom', function()
\r
980 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
\r
981 title.setAttribute( '_cke_title', editor.document.$.title );
\r
982 editor.document.$.title = frameLabel;
\r
985 // IE8 stricts mode doesn't have 'contentEditable' in effect
\r
986 // on element unless it has layout. (#5562)
\r
987 if ( CKEDITOR.env.ie8Compat )
\r
989 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );
\r
991 var selectors = [];
\r
992 for ( var tag in CKEDITOR.dtd.$removeEmpty )
\r
993 selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );
\r
994 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );
\r
996 // Set the HTML style to 100% to have the text cursor in affect (#6341)
\r
997 else if ( CKEDITOR.env.gecko )
\r
998 editor.addCss( 'html { height: 100% !important; }' );
\r
1000 // Switch on design mode for a short while and close it after then.
\r
1001 function blinkCursor( retry )
\r
1003 CKEDITOR.tools.tryThese(
\r
1006 editor.document.$.designMode = 'on';
\r
1007 setTimeout( function()
\r
1009 editor.document.$.designMode = 'off';
\r
1010 if ( CKEDITOR.currentInstance == editor )
\r
1011 editor.document.getBody().focus();
\r
1016 // The above call is known to fail when parent DOM
\r
1017 // tree layout changes may break design mode. (#5782)
\r
1018 // Refresh the 'contentEditable' is a cue to this.
\r
1019 editor.document.$.designMode = 'off';
\r
1020 var body = editor.document.getBody();
\r
1021 body.setAttribute( 'contentEditable', false );
\r
1022 body.setAttribute( 'contentEditable', true );
\r
1023 // Try it again once..
\r
1024 !retry && blinkCursor( 1 );
\r
1028 // Create an invisible element to grab focus.
\r
1029 if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )
\r
1032 editor.on( 'uiReady', function()
\r
1034 focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
\r
1035 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
\r
1036 '<span tabindex="-1" style="position:absolute;" role="presentation"></span>' ) );
\r
1038 focusGrabber.on( 'focus', function()
\r
1043 editor.on( 'destroy', function()
\r
1045 CKEDITOR.tools.removeFunction( contentDomReadyHandler );
\r
1046 focusGrabber.clearCustomData();
\r
1050 // Disable form elements editing mode provided by some browers. (#5746)
\r
1051 editor.on( 'insertElement', function ( evt )
\r
1053 var element = evt.data;
\r
1054 if ( element.type == CKEDITOR.NODE_ELEMENT
\r
1055 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )
\r
1057 if ( !element.isReadOnly() )
\r
1059 element.setAttribute( 'contentEditable', false );
\r
1060 // We should flag that the element was locked by our code so
\r
1061 // it'll be editable by the editor functions (#6046).
\r
1062 element.setCustomData( '_cke_notReadOnly', 1 );
\r
1070 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
\r
1071 if ( CKEDITOR.env.gecko )
\r
1075 var body = document.body;
\r
1078 window.addEventListener( 'load', arguments.callee, false );
\r
1081 var currentHandler = body.getAttribute( 'onpageshow' );
\r
1082 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +
\r
1083 'event.persisted && (function(){' +
\r
1084 'var allInstances = CKEDITOR.instances, editor, doc;' +
\r
1085 'for ( var i in allInstances )' +
\r
1087 ' editor = allInstances[ i ];' +
\r
1088 ' doc = editor.document;' +
\r
1091 ' doc.$.designMode = "off";' +
\r
1092 ' doc.$.designMode = "on";' +
\r
1103 * Disables the ability of resize objects (image and tables) in the editing
\r
1108 * config.disableObjectResizing = true;
\r
1110 CKEDITOR.config.disableObjectResizing = false;
\r
1113 * Disables the "table tools" offered natively by the browser (currently
\r
1114 * Firefox only) to make quick table editing operations, like adding or
\r
1115 * deleting rows and columns.
\r
1119 * config.disableNativeTableHandles = false;
\r
1121 CKEDITOR.config.disableNativeTableHandles = true;
\r
1124 * Disables the built-in spell checker while typing natively available in the
\r
1125 * browser (currently Firefox and Safari only).<br /><br />
\r
1127 * Even if word suggestions will not appear in the CKEditor context menu, this
\r
1128 * feature is useful to help quickly identifying misspelled words.<br /><br />
\r
1130 * This setting is currently compatible with Firefox only due to limitations in
\r
1135 * config.disableNativeSpellChecker = false;
\r
1137 CKEDITOR.config.disableNativeSpellChecker = true;
\r
1140 * Whether the editor must output an empty value ("") if it's contents is made
\r
1141 * by an empty paragraph only.
\r
1145 * config.ignoreEmptyParagraph = false;
\r
1147 CKEDITOR.config.ignoreEmptyParagraph = true;
\r
1150 * Fired when data is loaded and ready for retrieval in an editor instance.
\r
1151 * @name CKEDITOR.editor#dataReady
\r