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|li)[^>]*>\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
76 $sel.createRange().pasteHTML( data );
\r
79 this.getSelection().lock();
\r
82 this.document.$.execCommand( 'inserthtml', false, data );
\r
84 // Webkit does not scroll to the cursor position after pasting (#5558)
\r
85 if ( CKEDITOR.env.webkit )
\r
87 this.document.$.execCommand( 'inserthtml', false, '<span id="cke_paste_marker" cke_temp="1"></span>' );
\r
88 var marker = this.document.getById( 'cke_paste_marker' );
\r
89 marker.scrollIntoView();
\r
93 CKEDITOR.tools.setTimeout( function()
\r
95 this.fire( 'saveSnapshot' );
\r
100 function onInsertElement( evt )
\r
102 if ( this.mode == 'wysiwyg' )
\r
106 var selection = this.getSelection();
\r
107 if ( checkReadOnly( selection ) )
\r
110 this.fire( 'saveSnapshot' );
\r
112 var ranges = selection.getRanges(),
\r
113 element = evt.data,
\r
114 elementName = element.getName(),
\r
115 isBlock = CKEDITOR.dtd.$block[ elementName ];
\r
117 var selIsLocked = selection.isLocked;
\r
120 selection.unlock();
\r
122 var range, clone, lastElement, bookmark;
\r
124 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
\r
126 range = ranges[ i ];
\r
128 // Remove the original contents.
\r
129 range.deleteContents();
\r
131 clone = !i && element || element.clone( true );
\r
133 // If we're inserting a block at dtd-violated position, split
\r
134 // the parent blocks until we reach blockLimit.
\r
138 while ( ( current = range.getCommonAncestor( false, true ) )
\r
139 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
\r
140 && !( dtd && dtd [ elementName ] ) )
\r
142 // Split up inline elements.
\r
143 if ( current.getName() in CKEDITOR.dtd.span )
\r
144 range.splitElement( current );
\r
145 // If we're in an empty block which indicate a new paragraph,
\r
146 // simply replace it with the inserting block.(#3664)
\r
147 else if ( range.checkStartOfBlock()
\r
148 && range.checkEndOfBlock() )
\r
150 range.setStartBefore( current );
\r
151 range.collapse( true );
\r
155 range.splitBlock();
\r
159 // Insert the new node.
\r
160 range.insertNode( clone );
\r
162 // Save the last element reference so we can make the
\r
163 // selection later.
\r
164 if ( !lastElement )
\r
165 lastElement = clone;
\r
168 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
\r
170 // If we're inserting a block element immediatelly followed by
\r
171 // another block element, the selection must move there. (#3100,#5436)
\r
174 var next = lastElement.getNext( notWhitespaceEval ),
\r
175 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
\r
177 // Check if it's a block element that accepts text.
\r
178 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
\r
179 range.moveToElementEditStart( next );
\r
182 selection.selectRanges( [ range ] );
\r
185 this.getSelection().lock();
\r
187 // Save snaps after the whole execution completed.
\r
188 // This's a workaround for make DOM modification's happened after
\r
189 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
\r
191 CKEDITOR.tools.setTimeout( function(){
\r
192 this.fire( 'saveSnapshot' );
\r
197 // DOM modification here should not bother dirty flag.(#4385)
\r
198 function restoreDirty( editor )
\r
200 if ( !editor.checkDirty() )
\r
201 setTimeout( function(){ editor.resetDirty(); } );
\r
204 var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
\r
205 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
\r
207 function isNotEmpty( node )
\r
209 return isNotWhitespace( node ) && isNotBookmark( node );
\r
212 function isNbsp( node )
\r
214 return node.type == CKEDITOR.NODE_TEXT
\r
215 && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
\r
218 function restoreSelection( selection )
\r
220 if ( selection.isLocked )
\r
222 selection.unlock();
\r
223 setTimeout( function() { selection.lock(); }, 0 );
\r
227 function isBlankParagraph( block )
\r
229 return block.getOuterHtml().match( emptyParagraphRegexp );
\r
232 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
\r
234 // Gecko need a key event to 'wake up' the editing
\r
235 // ability when document is empty.(#3864, #5781)
\r
236 function activateEditing( editor )
\r
238 var win = editor.window,
\r
239 doc = editor.document,
\r
240 body = editor.document.getBody(),
\r
241 bodyChildsNum = body.getChildren().count();
\r
243 if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )
\r
245 restoreDirty( editor );
\r
247 // Simulating keyboard character input by dispatching a keydown of white-space text.
\r
248 var keyEventSimulate = doc.$.createEvent( "KeyEvents" );
\r
249 keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,
\r
250 false, false, false, 0, 32 );
\r
251 doc.$.dispatchEvent( keyEventSimulate );
\r
253 // Restore the original document status by placing the cursor before a bogus br created (#5021).
\r
254 bodyChildsNum && body.getFirst().remove();
\r
255 doc.getBody().appendBogus();
\r
256 var nativeRange = new CKEDITOR.dom.range( doc );
\r
257 nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );
\r
258 nativeRange.select();
\r
263 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
\r
264 * non-exitable-block by padding extra br.(#3189)
\r
266 function onSelectionChangeFixBody( evt )
\r
268 var editor = evt.editor,
\r
269 path = evt.data.path,
\r
270 blockLimit = path.blockLimit,
\r
271 selection = evt.data.selection,
\r
272 range = selection.getRanges()[0],
\r
273 body = editor.document.getBody(),
\r
274 enterMode = editor.config.enterMode;
\r
276 CKEDITOR.env.gecko && activateEditing( editor );
\r
278 // When enterMode set to block, we'll establing new paragraph only if we're
\r
279 // selecting inline contents right under body. (#3657)
\r
280 if ( enterMode != CKEDITOR.ENTER_BR
\r
282 && blockLimit.getName() == 'body'
\r
285 editor.fire( 'updateSnapshot' );
\r
286 restoreDirty( editor );
\r
287 CKEDITOR.env.ie && restoreSelection( selection );
\r
289 var fixedBlock = range.fixBlock( true,
\r
290 editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
\r
292 // For IE, we should remove any filler node which was introduced before.
\r
293 if ( CKEDITOR.env.ie )
\r
295 var first = fixedBlock.getFirst( isNotEmpty );
\r
296 first && isNbsp( first ) && first.remove();
\r
299 // If the fixed block is actually blank and is already followed by an exitable blank
\r
300 // block, we should revert the fix and move into the existed one. (#3684)
\r
301 if ( isBlankParagraph( fixedBlock ) )
\r
303 var element = fixedBlock.getNext( isNotWhitespace );
\r
305 element.type == CKEDITOR.NODE_ELEMENT &&
\r
306 !nonExitableElementNames[ element.getName() ] )
\r
308 range.moveToElementEditStart( element );
\r
309 fixedBlock.remove();
\r
313 element = fixedBlock.getPrevious( isNotWhitespace );
\r
315 element.type == CKEDITOR.NODE_ELEMENT &&
\r
316 !nonExitableElementNames[ element.getName() ] )
\r
318 range.moveToElementEditEnd( element );
\r
319 fixedBlock.remove();
\r
325 // Notify non-IE that selection has changed.
\r
326 if ( !CKEDITOR.env.ie )
\r
327 editor.selectionChange();
\r
330 // All browsers are incapable to moving cursor out of certain non-exitable
\r
331 // blocks (e.g. table, list, pre) at the end of document, make this happen by
\r
332 // place a bogus node there, which would be later removed by dataprocessor.
\r
333 var walkerRange = new CKEDITOR.dom.range( editor.document ),
\r
334 walker = new CKEDITOR.dom.walker( walkerRange );
\r
335 walkerRange.selectNodeContents( body );
\r
336 walker.evaluator = function( node )
\r
338 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
\r
340 walker.guard = function( node, isMoveout )
\r
342 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
\r
345 if ( walker.previous() )
\r
347 editor.fire( 'updateSnapshot' );
\r
348 restoreDirty( editor );
\r
349 CKEDITOR.env.ie && restoreSelection( selection );
\r
352 if ( enterMode != CKEDITOR.ENTER_BR )
\r
353 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
\r
355 paddingBlock = body;
\r
357 if ( !CKEDITOR.env.ie )
\r
358 paddingBlock.appendBogus();
\r
362 CKEDITOR.plugins.add( 'wysiwygarea',
\r
364 requires : [ 'editingblock' ],
\r
366 init : function( editor )
\r
368 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
\r
369 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
\r
371 var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
\r
373 var contentDomReadyHandler;
\r
374 editor.on( 'editingBlockReady', function()
\r
384 // Support for custom document.domain in IE.
\r
385 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
387 // Creates the iframe that holds the editable document.
\r
388 var createIFrame = function( data )
\r
395 'document.open();' +
\r
397 // The document domain must be set any time we
\r
398 // call document.open().
\r
399 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
401 'document.close();';
\r
403 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
404 ' style="width:100%;height:100%"' +
\r
405 ' frameBorder="0"' +
\r
406 ' title="' + frameLabel + '"' +
\r
407 // With IE, the custom domain has to be taken care at first,
\r
408 // for other browers, the 'src' attribute should be left empty to
\r
409 // trigger iframe's 'load' event.
\r
410 ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +
\r
411 ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +
\r
412 ' allowTransparency="true"' +
\r
415 // #5689 Running inside of Firefox chrome the load event doesn't bubble like in a normal page
\r
416 if (document.location.protocol == 'chrome:')
\r
417 CKEDITOR.event.useCapture = true;
\r
419 // With FF, it's better to load the data on iframe.load. (#3894,#4058)
\r
420 iframe.on( 'load', function( ev )
\r
423 ev.removeListener();
\r
425 var doc = iframe.getFrameDocument().$;
\r
427 // Don't leave any history log in IE. (#5657)
\r
428 doc.open( "text/html","replace" );
\r
433 // #5689 Reset adjustment back to default
\r
434 if (document.location.protocol == 'chrome:')
\r
435 CKEDITOR.event.useCapture = false;
\r
437 mainElement.append( iframe );
\r
440 // The script that launches the bootstrap logic on 'domReady', so the document
\r
441 // is fully editable even before the editing iframe is fully loaded (#4455).
\r
442 contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );
\r
443 var activationScript =
\r
444 '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
\r
445 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
446 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +
\r
449 // Editing area bootstrap code.
\r
450 function contentDomReady( domWindow )
\r
452 if ( !frameLoaded )
\r
456 editor.fire( 'ariaWidget', iframe );
\r
458 var domDocument = domWindow.document,
\r
459 body = domDocument.body;
\r
461 // Remove this script from the DOM.
\r
462 var script = domDocument.getElementById( "cke_actscrpt" );
\r
463 script.parentNode.removeChild( script );
\r
465 body.spellcheck = !editor.config.disableNativeSpellChecker;
\r
467 if ( CKEDITOR.env.ie )
\r
469 // Don't display the focus border.
\r
470 body.hideFocus = true;
\r
472 // Disable and re-enable the body to avoid IE from
\r
473 // taking the editing focus at startup. (#141 / #523)
\r
474 body.disabled = true;
\r
475 body.contentEditable = true;
\r
476 body.removeAttribute( 'disabled' );
\r
480 // Avoid opening design mode in a frame window thread,
\r
481 // which will cause host page scrolling.(#4397)
\r
482 setTimeout( function()
\r
484 // Prefer 'contentEditable' instead of 'designMode'. (#3593)
\r
485 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
\r
486 || CKEDITOR.env.opera )
\r
487 domDocument.$.body.contentEditable = true;
\r
488 else if ( CKEDITOR.env.webkit )
\r
489 domDocument.$.body.parentNode.contentEditable = true;
\r
491 domDocument.$.designMode = 'on';
\r
495 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
\r
497 domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
\r
498 domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
\r
500 domDocument.on( 'dblclick', function( evt )
\r
502 var element = evt.data.getTarget(),
\r
503 data = { element : element, dialog : '' };
\r
504 editor.fire( 'doubleclick', data );
\r
505 data.dialog && editor.openDialog( data.dialog );
\r
508 // Gecko/Webkit need some help when selecting control type elements. (#3448)
\r
509 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )
\r
511 domDocument.on( 'mousedown', function( ev )
\r
513 var control = ev.data.getTarget();
\r
514 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
\r
515 editor.getSelection().selectElement( control );
\r
519 if ( CKEDITOR.env.gecko )
\r
521 domDocument.on( 'mouseup', function( ev )
\r
523 if ( ev.data.$.button == 2 )
\r
525 var target = ev.data.getTarget();
\r
527 // Prevent right click from selecting an empty block even
\r
528 // when selection is anchored inside it. (#5845)
\r
529 if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )
\r
531 var range = new CKEDITOR.dom.range( domDocument );
\r
532 range.moveToElementEditStart( target );
\r
533 range.select( true );
\r
539 // Prevent the browser opening links in read-only blocks. (#6032)
\r
540 domDocument.on( 'click', function( ev )
\r
543 if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )
\r
544 ev.preventDefault();
\r
547 // Webkit: avoid from editing form control elements content.
\r
548 if ( CKEDITOR.env.webkit )
\r
550 // Prevent from tick checkbox/radiobox/select
\r
551 domDocument.on( 'click', function( ev )
\r
553 if ( ev.data.getTarget().is( 'input', 'select' ) )
\r
554 ev.data.preventDefault();
\r
557 // Prevent from editig textfield/textarea value.
\r
558 domDocument.on( 'mouseup', function( ev )
\r
560 if ( ev.data.getTarget().is( 'input', 'textarea' ) )
\r
561 ev.data.preventDefault();
\r
565 // IE standard compliant in editing frame doesn't focus the editor when
\r
566 // clicking outside actual content, manually apply the focus. (#1659)
\r
567 if ( CKEDITOR.env.ie
\r
568 && domDocument.$.compatMode == 'CSS1Compat'
\r
569 || CKEDITOR.env.gecko
\r
570 || CKEDITOR.env.opera )
\r
572 var htmlElement = domDocument.getDocumentElement();
\r
573 htmlElement.on( 'mousedown', function( evt )
\r
575 // Setting focus directly on editor doesn't work, we
\r
576 // have to use here a temporary element to 'redirect'
\r
578 if ( evt.data.getTarget().equals( htmlElement ) )
\r
580 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
582 focusGrabber.focus();
\r
587 domWindow.on( 'blur', function()
\r
589 editor.focusManager.blur();
\r
592 domWindow.on( 'focus', function()
\r
594 var doc = editor.document;
\r
596 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
598 else if ( CKEDITOR.env.opera )
\r
599 doc.getBody().focus();
\r
601 editor.focusManager.focus();
\r
604 var keystrokeHandler = editor.keystrokeHandler;
\r
605 if ( keystrokeHandler )
\r
606 keystrokeHandler.attach( domDocument );
\r
608 if ( CKEDITOR.env.ie )
\r
610 domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
\r
611 // Override keystrokes which should have deletion behavior
\r
612 // on control types in IE . (#4047)
\r
613 domDocument.on( 'keydown', function( evt )
\r
615 var keyCode = evt.data.getKeystroke();
\r
617 // Backspace OR Delete.
\r
618 if ( keyCode in { 8 : 1, 46 : 1 } )
\r
620 var sel = editor.getSelection(),
\r
621 control = sel.getSelectedElement();
\r
625 // Make undo snapshot.
\r
626 editor.fire( 'saveSnapshot' );
\r
628 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
\r
629 // break up the selection, safely manage it here. (#4795)
\r
630 var bookmark = sel.getRanges()[ 0 ].createBookmark();
\r
631 // Remove the control manually.
\r
633 sel.selectBookmarks( [ bookmark ] );
\r
635 editor.fire( 'saveSnapshot' );
\r
637 evt.data.preventDefault();
\r
642 // PageUp/PageDown scrolling is broken in document
\r
643 // with standard doctype, manually fix it. (#4736)
\r
644 if ( domDocument.$.compatMode == 'CSS1Compat' )
\r
646 var pageUpDownKeys = { 33 : 1, 34 : 1 };
\r
647 domDocument.on( 'keydown', function( evt )
\r
649 if ( evt.data.getKeystroke() in pageUpDownKeys )
\r
651 setTimeout( function ()
\r
653 editor.getSelection().scrollIntoView();
\r
660 // Adds the document body as a context menu target.
\r
661 if ( editor.contextMenu )
\r
662 editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
\r
664 setTimeout( function()
\r
666 editor.fire( 'contentDom' );
\r
670 editor.mode = 'wysiwyg';
\r
671 editor.fire( 'mode' );
\r
675 isLoadingData = false;
\r
677 if ( isPendingFocus )
\r
680 isPendingFocus = false;
\r
682 setTimeout( function()
\r
684 editor.fire( 'dataReady' );
\r
687 // IE, Opera and Safari may not support it and throw errors.
\r
688 try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
\r
689 try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
\r
692 * IE BUG: IE might have rendered the iframe with invisible contents.
\r
693 * (#3623). Push some inconsequential CSS style changes to force IE to
\r
696 * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
\r
697 * fix the problem. :(
\r
699 if ( CKEDITOR.env.ie )
\r
701 setTimeout( function()
\r
703 if ( editor.document )
\r
705 var $body = editor.document.$.body;
\r
706 $body.runtimeStyle.marginBottom = '0px';
\r
707 $body.runtimeStyle.marginBottom = '';
\r
715 editor.addMode( 'wysiwyg',
\r
717 load : function( holderElement, data, isSnapshot )
\r
719 mainElement = holderElement;
\r
721 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
722 holderElement.setStyle( 'position', 'relative' );
\r
724 // The editor data "may be dirty" after this
\r
726 editor.mayBeDirty = true;
\r
731 this.loadSnapshotData( data );
\r
733 this.loadData( data );
\r
736 loadData : function( data )
\r
738 isLoadingData = true;
\r
740 var config = editor.config,
\r
741 fullPage = config.fullPage,
\r
742 docType = config.docType;
\r
744 // Build the additional stuff to be included into <head>.
\r
746 '<style type="text/css" cke_temp="1">' +
\r
747 editor._.styles.join( '\n' ) +
\r
750 !fullPage && ( headExtra =
\r
751 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
754 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
\r
758 // Search and sweep out the doctype declaration.
\r
759 data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
\r
761 editor.docType = docType = match;
\r
766 // Get the HTML version of the data.
\r
767 if ( editor.dataProcessor )
\r
768 data = editor.dataProcessor.toHtml( data, fixForBody );
\r
772 // Check if the <body> tag is available.
\r
773 if ( !(/<body[\s|>]/).test( data ) )
\r
774 data = '<body>' + data;
\r
776 // Check if the <html> tag is available.
\r
777 if ( !(/<html[\s|>]/).test( data ) )
\r
778 data = '<html>' + data + '</html>';
\r
780 // Check if the <head> tag is available.
\r
781 if ( !(/<head[\s|>]/).test( data ) )
\r
782 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
\r
783 else if ( !(/<title[\s|>]/).test( data ) )
\r
784 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;
\r
786 // The base must be the first tag in the HEAD, e.g. to get relative
\r
787 // links on styles.
\r
788 baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
\r
790 // Inject the extra stuff into <head>.
\r
791 // Attention: do not change it before testing it well. (V2)
\r
792 // This is tricky... if the head ends with <meta ... content type>,
\r
793 // Firefox will break. But, it works if we place our extra stuff as
\r
794 // the last elements in the HEAD.
\r
795 data = data.replace( /<\/head\s*>/, headExtra + '$&' );
\r
797 // Add the DOCTYPE back to it.
\r
798 data = docType + data;
\r
804 '<html dir="' + config.contentsLangDirection + '"' +
\r
805 ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +
\r
807 '<title>' + frameLabel + '</title>' +
\r
811 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
\r
812 ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
\r
818 data += activationScript;
\r
821 // The iframe is recreated on each call of setData, so we need to clear DOM objects
\r
823 createIFrame( data );
\r
826 getData : function()
\r
828 var config = editor.config,
\r
829 fullPage = config.fullPage,
\r
830 docType = fullPage && editor.docType,
\r
831 doc = iframe.getFrameDocument();
\r
833 var data = fullPage
\r
834 ? doc.getDocumentElement().getOuterHtml()
\r
835 : doc.getBody().getHtml();
\r
837 if ( editor.dataProcessor )
\r
838 data = editor.dataProcessor.toDataFormat( data, fixForBody );
\r
840 // Strip the last blank paragraph within document.
\r
841 if ( config.ignoreEmptyParagraph )
\r
842 data = data.replace( emptyParagraphRegexp, '' );
\r
845 data = docType + '\n' + data;
\r
850 getSnapshotData : function()
\r
852 return iframe.getFrameDocument().getBody().getHtml();
\r
855 loadSnapshotData : function( data )
\r
857 iframe.getFrameDocument().getBody().setHtml( data );
\r
860 onDispose : function()
\r
862 if ( !editor.document )
\r
865 editor.document.getDocumentElement().clearCustomData();
\r
866 editor.document.getBody().clearCustomData();
\r
868 editor.window.clearCustomData();
\r
869 editor.document.clearCustomData();
\r
871 iframe.clearCustomData();
\r
874 * IE BUG: When destroying editor DOM with the selection remains inside
\r
875 * editing area would break IE7/8's selection system, we have to put the editing
\r
876 * iframe offline first. (#3812 and #5441)
\r
881 unload : function( holderElement )
\r
885 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
\r
887 editor.fire( 'contentDomUnload' );
\r
892 if ( isLoadingData )
\r
893 isPendingFocus = true;
\r
894 else if ( editor.window )
\r
896 editor.window.focus();
\r
898 editor.selectionChange();
\r
903 editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
\r
904 editor.on( 'insertElement', onInsertElement, null, null, 20 );
\r
905 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
\r
906 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
\r
910 // Setting voice label as window title, backup the original one
\r
911 // and restore it before running into use.
\r
912 editor.on( 'contentDom', function ()
\r
914 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
\r
915 title.setAttribute( '_cke_title', editor.document.$.title );
\r
916 editor.document.$.title = frameLabel;
\r
919 // IE8 stricts mode doesn't have 'contentEditable' in effect
\r
920 // on element unless it has layout. (#5562)
\r
921 if ( CKEDITOR.env.ie8Compat )
\r
923 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );
\r
925 var selectors = [];
\r
926 for ( var tag in CKEDITOR.dtd.$removeEmpty )
\r
927 selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );
\r
928 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );
\r
931 // Switch on design mode for a short while and close it after then.
\r
932 function blinkCursor( retry )
\r
934 CKEDITOR.tools.tryThese(
\r
937 editor.document.$.designMode = 'on';
\r
938 setTimeout( function ()
\r
940 editor.document.$.designMode = 'off';
\r
941 editor.document.getBody().focus();
\r
946 // The above call is known to fail when parent DOM
\r
947 // tree layout changes may break design mode. (#5782)
\r
948 // Refresh the 'contentEditable' is a cue to this.
\r
949 editor.document.$.designMode = 'off';
\r
950 var body = editor.document.getBody();
\r
951 body.setAttribute( 'contentEditable', false );
\r
952 body.setAttribute( 'contentEditable', true );
\r
953 // Try it again once..
\r
954 !retry && blinkCursor( 1 );
\r
958 // Create an invisible element to grab focus.
\r
959 if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )
\r
962 editor.on( 'uiReady', function()
\r
964 focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
\r
965 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
\r
966 '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );
\r
968 focusGrabber.on( 'focus', function()
\r
973 editor.on( 'destroy', function()
\r
975 CKEDITOR.tools.removeFunction( contentDomReadyHandler );
\r
976 focusGrabber.clearCustomData();
\r
980 // Disable form elements editing mode provided by some browers. (#5746)
\r
981 editor.on( 'insertElement', function ( evt )
\r
983 var element = evt.data;
\r
984 if ( element.type == CKEDITOR.NODE_ELEMENT
\r
985 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )
\r
987 if ( !element.isReadOnly() )
\r
989 element.setAttribute( 'contentEditable', false );
\r
990 // We should flag that the element was locked by our code so
\r
991 // it'll be editable by the editor functions (#6046).
\r
992 element.setCustomData( '_cke_notReadOnly', 1 );
\r
1000 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
\r
1001 if ( CKEDITOR.env.gecko )
\r
1005 var body = document.body;
\r
1008 window.addEventListener( 'load', arguments.callee, false );
\r
1011 var currentHandler = body.getAttribute( 'onpageshow' );
\r
1012 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +
\r
1013 'event.persisted && (function(){' +
\r
1014 'var allInstances = CKEDITOR.instances, editor, doc;' +
\r
1015 'for ( var i in allInstances )' +
\r
1017 ' editor = allInstances[ i ];' +
\r
1018 ' doc = editor.document;' +
\r
1021 ' doc.$.designMode = "off";' +
\r
1022 ' doc.$.designMode = "on";' +
\r
1033 * Disables the ability of resize objects (image and tables) in the editing
\r
1038 * config.disableObjectResizing = true;
\r
1040 CKEDITOR.config.disableObjectResizing = false;
\r
1043 * Disables the "table tools" offered natively by the browser (currently
\r
1044 * Firefox only) to make quick table editing operations, like adding or
\r
1045 * deleting rows and columns.
\r
1049 * config.disableNativeTableHandles = false;
\r
1051 CKEDITOR.config.disableNativeTableHandles = true;
\r
1054 * Disables the built-in spell checker while typing natively available in the
\r
1055 * browser (currently Firefox and Safari only).<br /><br />
\r
1057 * Even if word suggestions will not appear in the CKEditor context menu, this
\r
1058 * feature is useful to help quickly identifying misspelled words.<br /><br />
\r
1060 * This setting is currently compatible with Firefox only due to limitations in
\r
1065 * config.disableNativeSpellChecker = false;
\r
1067 CKEDITOR.config.disableNativeSpellChecker = true;
\r
1070 * Whether the editor must output an empty value ("") if it's contents is made
\r
1071 * by an empty paragraph only.
\r
1075 * config.ignoreEmptyParagraph = false;
\r
1077 CKEDITOR.config.ignoreEmptyParagraph = true;
\r
1080 * Fired when data is loaded and ready for retrieval in an editor instance.
\r
1081 * @name CKEDITOR.editor#dataReady
\r