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 function onInsertHtml( evt )
\r
21 if ( this.mode == 'wysiwyg' )
\r
24 this.fire( 'saveSnapshot' );
\r
26 var selection = this.getSelection(),
\r
29 if ( this.dataProcessor )
\r
30 data = this.dataProcessor.toHtml( data );
\r
32 if ( CKEDITOR.env.ie )
\r
34 var selIsLocked = selection.isLocked;
\r
39 var $sel = selection.getNative();
\r
40 if ( $sel.type == 'Control' )
\r
42 $sel.createRange().pasteHTML( data );
\r
45 this.getSelection().lock();
\r
48 this.document.$.execCommand( 'inserthtml', false, data );
\r
50 CKEDITOR.tools.setTimeout( function()
\r
52 this.fire( 'saveSnapshot' );
\r
57 function onInsertElement( evt )
\r
59 if ( this.mode == 'wysiwyg' )
\r
62 this.fire( 'saveSnapshot' );
\r
64 var element = evt.data,
\r
65 elementName = element.getName(),
\r
66 isBlock = CKEDITOR.dtd.$block[ elementName ];
\r
68 var selection = this.getSelection(),
\r
69 ranges = selection.getRanges();
\r
71 var selIsLocked = selection.isLocked;
\r
76 var range, clone, lastElement, bookmark;
\r
78 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
\r
80 range = ranges[ i ];
\r
82 // Remove the original contents.
\r
83 range.deleteContents();
\r
85 clone = !i && element || element.clone( true );
\r
87 // If we're inserting a block at dtd-violated position, split
\r
88 // the parent blocks until we reach blockLimit.
\r
92 while ( ( current = range.getCommonAncestor( false, true ) )
\r
93 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
\r
94 && !( dtd && dtd [ elementName ] ) )
\r
96 // Split up inline elements.
\r
97 if ( current.getName() in CKEDITOR.dtd.span )
\r
98 range.splitElement( current );
\r
99 // If we're in an empty block which indicate a new paragraph,
\r
100 // simply replace it with the inserting block.(#3664)
\r
101 else if ( range.checkStartOfBlock()
\r
102 && range.checkEndOfBlock() )
\r
104 range.setStartBefore( current );
\r
105 range.collapse( true );
\r
109 range.splitBlock();
\r
113 // Insert the new node.
\r
114 range.insertNode( clone );
\r
116 // Save the last element reference so we can make the
\r
117 // selection later.
\r
118 if ( !lastElement )
\r
119 lastElement = clone;
\r
122 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
\r
124 var next = lastElement.getNextSourceNode( true );
\r
125 if ( next && next.type == CKEDITOR.NODE_ELEMENT )
\r
126 range.moveToElementEditStart( next );
\r
128 selection.selectRanges( [ range ] );
\r
131 this.getSelection().lock();
\r
133 // Save snaps after the whole execution completed.
\r
134 // This's a workaround for make DOM modification's happened after
\r
135 // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
\r
137 CKEDITOR.tools.setTimeout( function(){
\r
138 this.fire( 'saveSnapshot' );
\r
143 // DOM modification here should not bother dirty flag.(#4385)
\r
144 function restoreDirty( editor )
\r
146 if ( !editor.checkDirty() )
\r
147 setTimeout( function(){ editor.resetDirty(); } );
\r
150 var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
\r
151 isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
\r
153 function isNotEmpty( node )
\r
155 return isNotWhitespace( node ) && isNotBookmark( node );
\r
158 function isNbsp( node )
\r
160 return node.type == CKEDITOR.NODE_TEXT
\r
161 && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
\r
164 function restoreSelection( selection )
\r
166 if ( selection.isLocked )
\r
168 selection.unlock();
\r
169 setTimeout( function() { selection.lock(); }, 0 );
\r
173 function isBlankParagraph( block )
\r
175 return block.getOuterHtml().match( emptyParagraphRegexp );
\r
178 isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
\r
181 * Auto-fixing block-less content by wrapping paragraph (#3190), prevent
\r
182 * non-exitable-block by padding extra br.(#3189)
\r
184 function onSelectionChangeFixBody( evt )
\r
186 var editor = evt.editor,
\r
187 path = evt.data.path,
\r
188 blockLimit = path.blockLimit,
\r
189 selection = evt.data.selection,
\r
190 range = selection.getRanges()[0],
\r
191 body = editor.document.getBody(),
\r
192 enterMode = editor.config.enterMode;
\r
194 // When enterMode set to block, we'll establing new paragraph only if we're
\r
195 // selecting inline contents right under body. (#3657)
\r
196 if ( enterMode != CKEDITOR.ENTER_BR
\r
198 && blockLimit.getName() == 'body'
\r
201 editor.fire( 'updateSnapshot' );
\r
202 restoreDirty( editor );
\r
203 CKEDITOR.env.ie && restoreSelection( selection );
\r
205 var fixedBlock = range.fixBlock( true,
\r
206 editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
\r
208 // For IE, we should remove any filler node which was introduced before.
\r
209 if ( CKEDITOR.env.ie )
\r
211 var first = fixedBlock.getFirst( isNotEmpty );
\r
212 first && isNbsp( first ) && first.remove();
\r
215 // If the fixed block is actually blank and is already followed by an exitable blank
\r
216 // block, we should revert the fix and move into the existed one. (#3684)
\r
217 if ( isBlankParagraph( fixedBlock ) )
\r
219 var previousElement = fixedBlock.getPrevious( isNotWhitespace ),
\r
220 nextElement = fixedBlock.getNext( isNotWhitespace );
\r
222 if ( previousElement && previousElement.getName
\r
223 && !( previousElement.getName() in nonExitableElementNames )
\r
224 && isBlankParagraph( previousElement )
\r
225 && range.moveToElementEditStart( previousElement )
\r
226 || nextElement && nextElement.getName
\r
227 && !( nextElement.getName() in nonExitableElementNames )
\r
228 && isBlankParagraph( nextElement )
\r
229 && range.moveToElementEditStart( nextElement ) )
\r
231 fixedBlock.remove();
\r
236 // Notify non-IE that selection has changed.
\r
237 if ( !CKEDITOR.env.ie )
\r
238 editor.selectionChange();
\r
241 // All browsers are incapable to moving cursor out of certain non-exitable
\r
242 // blocks (e.g. table, list, pre) at the end of document, make this happen by
\r
243 // place a bogus node there, which would be later removed by dataprocessor.
\r
244 var walkerRange = new CKEDITOR.dom.range( editor.document ),
\r
245 walker = new CKEDITOR.dom.walker( walkerRange );
\r
246 walkerRange.selectNodeContents( body );
\r
247 walker.evaluator = function( node )
\r
249 return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
\r
251 walker.guard = function( node, isMoveout )
\r
253 return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
\r
256 if ( walker.previous() )
\r
258 editor.fire( 'updateSnapshot' );
\r
259 restoreDirty( editor );
\r
260 CKEDITOR.env.ie && restoreSelection( selection );
\r
263 if ( enterMode != CKEDITOR.ENTER_BR )
\r
264 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
\r
266 paddingBlock = body;
\r
268 if ( !CKEDITOR.env.ie )
\r
269 paddingBlock.appendBogus();
\r
273 CKEDITOR.plugins.add( 'wysiwygarea',
\r
275 requires : [ 'editingblock' ],
\r
277 init : function( editor )
\r
279 var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
\r
280 ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
\r
282 var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );
\r
284 var contentDomReadyHandler;
\r
285 editor.on( 'editingBlockReady', function()
\r
295 // Support for custom document.domain in IE.
\r
296 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
298 // Creates the iframe that holds the editable document.
\r
299 var createIFrame = function( data )
\r
306 'document.open();' +
\r
308 // The document domain must be set any time we
\r
309 // call document.open().
\r
310 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
312 'document.close();';
\r
314 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
315 ' style="width:100%;height:100%"' +
\r
316 ' frameBorder="0"' +
\r
317 ' title="' + frameLabel + '"' +
\r
318 // With IE, the custom domain has to be taken care at first,
\r
319 // for other browers, the 'src' attribute should be left empty to
\r
320 // trigger iframe's 'load' event.
\r
321 ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +
\r
322 ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +
\r
323 ' allowTransparency="true"' +
\r
326 // With FF, it's better to load the data on iframe.load. (#3894,#4058)
\r
327 iframe.on( 'load', function( ev )
\r
330 ev.removeListener();
\r
332 var doc = iframe.getFrameDocument().$;
\r
334 // Don't leave any history log in IE. (#5657)
\r
335 doc.open( "text/html","replace" );
\r
340 mainElement.append( iframe );
\r
343 // The script that launches the bootstrap logic on 'domReady', so the document
\r
344 // is fully editable even before the editing iframe is fully loaded (#4455).
\r
345 contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );
\r
346 var activationScript =
\r
347 '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +
\r
348 ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +
\r
349 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +
\r
352 // Editing area bootstrap code.
\r
353 function contentDomReady( domWindow )
\r
355 if ( !frameLoaded )
\r
359 editor.fire( 'ariaWidget', iframe );
\r
361 var domDocument = domWindow.document,
\r
362 body = domDocument.body;
\r
364 // Remove this script from the DOM.
\r
365 var script = domDocument.getElementById( "cke_actscrpt" );
\r
366 script.parentNode.removeChild( script );
\r
368 body.spellcheck = !editor.config.disableNativeSpellChecker;
\r
370 if ( CKEDITOR.env.ie )
\r
372 // Don't display the focus border.
\r
373 body.hideFocus = true;
\r
375 // Disable and re-enable the body to avoid IE from
\r
376 // taking the editing focus at startup. (#141 / #523)
\r
377 body.disabled = true;
\r
378 body.contentEditable = true;
\r
379 body.removeAttribute( 'disabled' );
\r
383 // Avoid opening design mode in a frame window thread,
\r
384 // which will cause host page scrolling.(#4397)
\r
385 setTimeout( function()
\r
387 // Prefer 'contentEditable' instead of 'designMode'. (#3593)
\r
388 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
\r
389 || CKEDITOR.env.opera )
\r
390 domDocument.$.body.contentEditable = true;
\r
391 else if ( CKEDITOR.env.webkit )
\r
392 domDocument.$.body.parentNode.contentEditable = true;
\r
394 domDocument.$.designMode = 'on';
\r
398 // Gecko need a key event to 'wake up' the editing
\r
399 // ability when document is empty.(#3864)
\r
400 if ( CKEDITOR.env.gecko && !body.childNodes.length )
\r
402 setTimeout( function()
\r
404 restoreDirty( editor );
\r
406 // Simulating keyboard character input by dispatching a keydown of white-space text.
\r
407 var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );
\r
408 keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,
\r
409 false, false, false, 0, 32 );
\r
410 domDocument.$.dispatchEvent( keyEventSimulate );
\r
412 // Restore the original document status by placing the cursor before a bogus br created (#5021).
\r
413 domDocument.createElement( 'br', { attributes: { '_moz_editor_bogus_node' : 'TRUE', '_moz_dirty' : "" } } )
\r
414 .replace( domDocument.getBody().getFirst() );
\r
415 var nativeRange = new CKEDITOR.dom.range( domDocument );
\r
416 nativeRange.setStartAt( new CKEDITOR.dom.element( body ) , CKEDITOR.POSITION_AFTER_START );
\r
417 nativeRange.select();
\r
421 // IE, Opera and Safari may not support it and throw
\r
423 try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}
\r
424 try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
\r
426 domWindow = editor.window = new CKEDITOR.dom.window( domWindow );
\r
427 domDocument = editor.document = new CKEDITOR.dom.document( domDocument );
\r
429 domDocument.on( 'dblclick', function( evt )
\r
431 var element = evt.data.getTarget(),
\r
432 data = { element : element, dialog : '' };
\r
433 editor.fire( 'doubleclick', data );
\r
434 data.dialog && editor.openDialog( data.dialog );
\r
437 // Gecko/Webkit need some help when selecting control type elements. (#3448)
\r
438 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )
\r
440 domDocument.on( 'mousedown', function( ev )
\r
442 var control = ev.data.getTarget();
\r
443 if ( control.is( 'img', 'hr', 'input', 'textarea', 'select' ) )
\r
444 editor.getSelection().selectElement( control );
\r
448 // Webkit: avoid from editing form control elements content.
\r
449 if ( CKEDITOR.env.webkit )
\r
451 // Prevent from tick checkbox/radiobox/select
\r
452 domDocument.on( 'click', function( ev )
\r
454 if ( ev.data.getTarget().is( 'input', 'select' ) )
\r
455 ev.data.preventDefault();
\r
458 // Prevent from editig textfield/textarea value.
\r
459 domDocument.on( 'mouseup', function( ev )
\r
461 if ( ev.data.getTarget().is( 'input', 'textarea' ) )
\r
462 ev.data.preventDefault();
\r
466 // IE standard compliant in editing frame doesn't focus the editor when
\r
467 // clicking outside actual content, manually apply the focus. (#1659)
\r
468 if ( CKEDITOR.env.ie
\r
469 && domDocument.$.compatMode == 'CSS1Compat'
\r
470 || CKEDITOR.env.gecko
\r
471 || CKEDITOR.env.opera )
\r
473 var htmlElement = domDocument.getDocumentElement();
\r
474 htmlElement.on( 'mousedown', function( evt )
\r
476 // Setting focus directly on editor doesn't work, we
\r
477 // have to use here a temporary element to 'redirect'
\r
479 if ( evt.data.getTarget().equals( htmlElement ) )
\r
481 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
483 focusGrabber.focus();
\r
488 domWindow.on( 'blur', function()
\r
490 editor.focusManager.blur();
\r
493 domWindow.on( 'focus', function()
\r
495 var doc = editor.document;
\r
497 if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )
\r
499 else if ( CKEDITOR.env.opera )
\r
500 doc.getBody().focus();
\r
501 else if ( CKEDITOR.env.webkit )
\r
503 // Selection will get lost after move focus
\r
504 // to document element, save it first.
\r
505 var sel = editor.getSelection(),
\r
506 type = sel.getType(),
\r
507 range = ( type != CKEDITOR.SELECTION_NONE ) && sel.getRanges()[ 0 ];
\r
509 doc.getDocumentElement().focus();
\r
510 range && range.select();
\r
513 editor.focusManager.focus();
\r
516 var keystrokeHandler = editor.keystrokeHandler;
\r
517 if ( keystrokeHandler )
\r
518 keystrokeHandler.attach( domDocument );
\r
520 if ( CKEDITOR.env.ie )
\r
522 domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
\r
523 // Override keystrokes which should have deletion behavior
\r
524 // on control types in IE . (#4047)
\r
525 domDocument.on( 'keydown', function( evt )
\r
527 var keyCode = evt.data.getKeystroke();
\r
529 // Backspace OR Delete.
\r
530 if ( keyCode in { 8 : 1, 46 : 1 } )
\r
532 var sel = editor.getSelection(),
\r
533 control = sel.getSelectedElement();
\r
537 // Make undo snapshot.
\r
538 editor.fire( 'saveSnapshot' );
\r
540 // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will
\r
541 // break up the selection, safely manage it here. (#4795)
\r
542 var bookmark = sel.getRanges()[ 0 ].createBookmark();
\r
543 // Remove the control manually.
\r
545 sel.selectBookmarks( [ bookmark ] );
\r
547 editor.fire( 'saveSnapshot' );
\r
549 evt.data.preventDefault();
\r
554 // PageUp/PageDown scrolling is broken in document
\r
555 // with standard doctype, manually fix it. (#4736)
\r
556 if ( domDocument.$.compatMode == 'CSS1Compat' )
\r
558 var pageUpDownKeys = { 33 : 1, 34 : 1 };
\r
559 domDocument.on( 'keydown', function( evt )
\r
561 if ( evt.data.getKeystroke() in pageUpDownKeys )
\r
563 setTimeout( function ()
\r
565 editor.getSelection().scrollIntoView();
\r
572 // Adds the document body as a context menu target.
\r
573 if ( editor.contextMenu )
\r
574 editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );
\r
576 setTimeout( function()
\r
578 editor.fire( 'contentDom' );
\r
582 editor.mode = 'wysiwyg';
\r
583 editor.fire( 'mode' );
\r
587 isLoadingData = false;
\r
589 if ( isPendingFocus )
\r
592 isPendingFocus = false;
\r
594 setTimeout( function()
\r
596 editor.fire( 'dataReady' );
\r
600 * IE BUG: IE might have rendered the iframe with invisible contents.
\r
601 * (#3623). Push some inconsequential CSS style changes to force IE to
\r
604 * Also, for some unknown reasons, short timeouts (e.g. 100ms) do not
\r
605 * fix the problem. :(
\r
607 if ( CKEDITOR.env.ie )
\r
609 setTimeout( function()
\r
611 if ( editor.document )
\r
613 var $body = editor.document.$.body;
\r
614 $body.runtimeStyle.marginBottom = '0px';
\r
615 $body.runtimeStyle.marginBottom = '';
\r
623 editor.addMode( 'wysiwyg',
\r
625 load : function( holderElement, data, isSnapshot )
\r
627 mainElement = holderElement;
\r
629 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
630 holderElement.setStyle( 'position', 'relative' );
\r
632 // The editor data "may be dirty" after this
\r
634 editor.mayBeDirty = true;
\r
639 this.loadSnapshotData( data );
\r
641 this.loadData( data );
\r
644 loadData : function( data )
\r
646 isLoadingData = true;
\r
648 var config = editor.config,
\r
649 fullPage = config.fullPage,
\r
650 docType = config.docType;
\r
652 // Build the additional stuff to be included into <head>.
\r
654 '<style type="text/css" cke_temp="1">' +
\r
655 editor._.styles.join( '\n' ) +
\r
658 !fullPage && ( headExtra =
\r
659 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
662 var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';
\r
666 // Search and sweep out the doctype declaration.
\r
667 data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )
\r
669 editor.docType = docType = match;
\r
674 // Get the HTML version of the data.
\r
675 if ( editor.dataProcessor )
\r
676 data = editor.dataProcessor.toHtml( data, fixForBody );
\r
680 // Check if the <body> tag is available.
\r
681 if ( !(/<body[\s|>]/).test( data ) )
\r
682 data = '<body>' + data;
\r
684 // Check if the <html> tag is available.
\r
685 if ( !(/<html[\s|>]/).test( data ) )
\r
686 data = '<html>' + data + '</html>';
\r
688 // Check if the <head> tag is available.
\r
689 if ( !(/<head[\s|>]/).test( data ) )
\r
690 data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;
\r
691 else if ( !(/<title[\s|>]/).test( data ) )
\r
692 data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;
\r
694 // The base must be the first tag in the HEAD, e.g. to get relative
\r
695 // links on styles.
\r
696 baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );
\r
698 // Inject the extra stuff into <head>.
\r
699 // Attention: do not change it before testing it well. (V2)
\r
700 // This is tricky... if the head ends with <meta ... content type>,
\r
701 // Firefox will break. But, it works if we place our extra stuff as
\r
702 // the last elements in the HEAD.
\r
703 data = data.replace( /<\/head\s*>/, headExtra + '$&' );
\r
705 // Add the DOCTYPE back to it.
\r
706 data = docType + data;
\r
712 '<html dir="' + config.contentsLangDirection + '"' +
\r
713 ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +
\r
715 '<title>' + frameLabel + '</title>' +
\r
719 '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +
\r
720 ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +
\r
726 data += activationScript;
\r
729 // The iframe is recreated on each call of setData, so we need to clear DOM objects
\r
731 createIFrame( data );
\r
734 getData : function()
\r
736 var config = editor.config,
\r
737 fullPage = config.fullPage,
\r
738 docType = fullPage && editor.docType,
\r
739 doc = iframe.getFrameDocument();
\r
741 var data = fullPage
\r
742 ? doc.getDocumentElement().getOuterHtml()
\r
743 : doc.getBody().getHtml();
\r
745 if ( editor.dataProcessor )
\r
746 data = editor.dataProcessor.toDataFormat( data, fixForBody );
\r
748 // Strip the last blank paragraph within document.
\r
749 if ( config.ignoreEmptyParagraph )
\r
750 data = data.replace( emptyParagraphRegexp, '' );
\r
753 data = docType + '\n' + data;
\r
758 getSnapshotData : function()
\r
760 return iframe.getFrameDocument().getBody().getHtml();
\r
763 loadSnapshotData : function( data )
\r
765 iframe.getFrameDocument().getBody().setHtml( data );
\r
768 onDispose : function()
\r
770 if ( !editor.document )
\r
773 editor.document.getDocumentElement().clearCustomData();
\r
774 editor.document.getBody().clearCustomData();
\r
776 editor.window.clearCustomData();
\r
777 editor.document.clearCustomData();
\r
779 iframe.clearCustomData();
\r
782 unload : function( holderElement )
\r
786 editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
\r
788 editor.fire( 'contentDomUnload' );
\r
793 if ( isLoadingData )
\r
794 isPendingFocus = true;
\r
795 else if ( editor.window )
\r
797 editor.window.focus();
\r
799 editor.selectionChange();
\r
804 editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
\r
805 editor.on( 'insertElement', onInsertElement, null, null, 20 );
\r
806 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
\r
807 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
\r
811 // Setting voice label as window title, backup the original one
\r
812 // and restore it before running into use.
\r
813 editor.on( 'contentDom', function ()
\r
815 var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
\r
816 title.setAttribute( '_cke_title', editor.document.$.title );
\r
817 editor.document.$.title = frameLabel;
\r
820 // IE8 stricts mode doesn't have 'contentEditable' in effect
\r
821 // on element unless it has layout. (#5562)
\r
822 if ( CKEDITOR.env.ie8Compat )
\r
824 editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );
\r
826 var selectors = [];
\r
827 for ( var tag in CKEDITOR.dtd.$removeEmpty )
\r
828 selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );
\r
829 editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );
\r
832 // Switch on design mode for a short while and close it after then.
\r
833 function blinkCursor( retry )
\r
835 CKEDITOR.tools.tryThese(
\r
838 editor.document.$.designMode = 'on';
\r
839 setTimeout( function ()
\r
841 editor.document.$.designMode = 'off';
\r
842 editor.document.getBody().focus();
\r
847 // The above call is known to fail when parent DOM
\r
848 // tree layout changes may break design mode. (#5782)
\r
849 // Refresh the 'contentEditable' is a cue to this.
\r
850 editor.document.$.designMode = 'off';
\r
851 var body = editor.document.getBody();
\r
852 body.setAttribute( 'contentEditable', false );
\r
853 body.setAttribute( 'contentEditable', true );
\r
854 // Try it again once..
\r
855 !retry && blinkCursor( 1 );
\r
859 // Create an invisible element to grab focus.
\r
860 if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )
\r
863 editor.on( 'uiReady', function()
\r
865 focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(
\r
866 // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)
\r
867 '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );
\r
869 focusGrabber.on( 'focus', function()
\r
874 editor.on( 'destroy', function()
\r
876 CKEDITOR.tools.removeFunction( contentDomReadyHandler );
\r
877 focusGrabber.clearCustomData();
\r
881 // Disable form elements editing mode provided by some browers. (#5746)
\r
882 editor.on( 'insertElement', function ( evt )
\r
884 var element = evt.data;
\r
885 if ( element.type = CKEDITOR.NODE_ELEMENT
\r
886 && ( element.is( 'input' ) || element.is( 'textarea' ) ) )
\r
888 element.setAttribute( 'contentEditable', false );
\r
895 // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
\r
896 if ( CKEDITOR.env.gecko )
\r
900 var body = document.body;
\r
903 window.addEventListener( 'load', arguments.callee, false );
\r
906 var currentHandler = body.getAttribute( 'onpageshow' );
\r
907 body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +
\r
908 'event.persisted && (function(){' +
\r
909 'var allInstances = CKEDITOR.instances, editor, doc;' +
\r
910 'for ( var i in allInstances )' +
\r
912 ' editor = allInstances[ i ];' +
\r
913 ' doc = editor.document;' +
\r
916 ' doc.$.designMode = "off";' +
\r
917 ' doc.$.designMode = "on";' +
\r
928 * Disables the ability of resize objects (image and tables) in the editing
\r
933 * config.disableObjectResizing = true;
\r
935 CKEDITOR.config.disableObjectResizing = false;
\r
938 * Disables the "table tools" offered natively by the browser (currently
\r
939 * Firefox only) to make quick table editing operations, like adding or
\r
940 * deleting rows and columns.
\r
944 * config.disableNativeTableHandles = false;
\r
946 CKEDITOR.config.disableNativeTableHandles = true;
\r
949 * Disables the built-in spell checker while typing natively available in the
\r
950 * browser (currently Firefox and Safari only).<br /><br />
\r
952 * Even if word suggestions will not appear in the CKEditor context menu, this
\r
953 * feature is useful to help quickly identifying misspelled words.<br /><br />
\r
955 * This setting is currently compatible with Firefox only due to limitations in
\r
960 * config.disableNativeSpellChecker = false;
\r
962 CKEDITOR.config.disableNativeSpellChecker = true;
\r
965 * Whether the editor must output an empty value ("") if it's contents is made
\r
966 * by an empty paragraph only.
\r
970 * config.ignoreEmptyParagraph = false;
\r
972 CKEDITOR.config.ignoreEmptyParagraph = true;
\r
975 * Fired when data is loaded and ready for retrieval in an editor instance.
\r
976 * @name CKEDITOR.editor#dataReady
\r