/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
\r
(function()\r
{\r
- /**\r
- * List of elements in which has no way to move editing focus outside.\r
- */\r
+ // List of elements in which has no way to move editing focus outside.\r
var nonExitableElementNames = { table:1,pre:1 };\r
+\r
// Matching an empty paragraph at the end of document.\r
- var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| | )\s*(:?<\/\1>)?\s*$/gi;\r
+ var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>| |\u00A0| )?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi;\r
\r
function onInsertHtml( evt )\r
{\r
if ( this.mode == 'wysiwyg' )\r
{\r
this.focus();\r
+ this.fire( 'saveSnapshot' );\r
\r
var selection = this.getSelection(),\r
data = evt.data;\r
}\r
else\r
this.document.$.execCommand( 'inserthtml', false, data );\r
+\r
+ CKEDITOR.tools.setTimeout( function()\r
+ {\r
+ this.fire( 'saveSnapshot' );\r
+ }, 0, this );\r
}\r
}\r
\r
var current, dtd;\r
if ( isBlock )\r
{\r
- while( ( current = range.getCommonAncestor( false, true ) )\r
+ while ( ( current = range.getCommonAncestor( false, true ) )\r
&& ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
&& !( dtd && dtd [ elementName ] ) )\r
{\r
+ // Split up inline elements.\r
+ if ( current.getName() in CKEDITOR.dtd.span )\r
+ range.splitElement( current );\r
// If we're in an empty block which indicate a new paragraph,\r
// simply replace it with the inserting block.(#3664)\r
- if ( range.checkStartOfBlock()\r
+ else if ( range.checkStartOfBlock()\r
&& range.checkEndOfBlock() )\r
{\r
range.setStartBefore( current );\r
// DOM modification here should not bother dirty flag.(#4385)\r
function restoreDirty( editor )\r
{\r
- if( !editor.checkDirty() )\r
+ if ( !editor.checkDirty() )\r
setTimeout( function(){ editor.resetDirty(); } );\r
}\r
\r
+ var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),\r
+ isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );\r
+\r
+ function isNotEmpty( node )\r
+ {\r
+ return isNotWhitespace( node ) && isNotBookmark( node );\r
+ }\r
+\r
+ function isNbsp( node )\r
+ {\r
+ return node.type == CKEDITOR.NODE_TEXT\r
+ && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );\r
+ }\r
+\r
+ function restoreSelection( selection )\r
+ {\r
+ if ( selection.isLocked )\r
+ {\r
+ selection.unlock();\r
+ setTimeout( function() { selection.lock(); }, 0 );\r
+ }\r
+ }\r
+\r
+ function isBlankParagraph( block )\r
+ {\r
+ return block.getOuterHtml().match( emptyParagraphRegexp );\r
+ }\r
+\r
+ isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );\r
+\r
/**\r
* Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
* non-exitable-block by padding extra br.(#3189)\r
&& blockLimit.getName() == 'body'\r
&& !path.block )\r
{\r
+ editor.fire( 'updateSnapshot' );\r
restoreDirty( editor );\r
- var bms = selection.createBookmarks(),\r
- fixedBlock = range.fixBlock( true,\r
+ CKEDITOR.env.ie && restoreSelection( selection );\r
+\r
+ var fixedBlock = range.fixBlock( true,\r
editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );\r
\r
- // For IE, we'll be removing any bogus br ( introduce by fixing body )\r
- // right now to prevent it introducing visual line break.\r
+ // For IE, we should remove any filler node which was introduced before.\r
if ( CKEDITOR.env.ie )\r
{\r
- var brNodeList = fixedBlock.getElementsByTag( 'br' ), brNode;\r
- for ( var i = 0 ; i < brNodeList.count() ; i++ )\r
- {\r
- if( ( brNode = brNodeList.getItem( i ) ) && brNode.hasAttribute( '_cke_bogus' ) )\r
- brNode.remove();\r
- }\r
+ var first = fixedBlock.getFirst( isNotEmpty );\r
+ first && isNbsp( first ) && first.remove();\r
}\r
\r
- selection.selectBookmarks( bms );\r
-\r
- // If the fixed block is blank and is already followed by a exitable\r
- // block, we should drop it and move to the exist block(#3684).\r
- var children = fixedBlock.getChildren(),\r
- count = children.count(),\r
- firstChild,\r
- whitespaceGuard = CKEDITOR.dom.walker.whitespaces( true ),\r
- previousElement = fixedBlock.getPrevious( whitespaceGuard ),\r
- nextElement = fixedBlock.getNext( whitespaceGuard ),\r
- enterBlock;\r
- if ( previousElement && previousElement.getName\r
- && !( previousElement.getName() in nonExitableElementNames ) )\r
- enterBlock = previousElement;\r
- else if ( nextElement && nextElement.getName\r
- && !( nextElement.getName() in nonExitableElementNames ) )\r
- enterBlock = nextElement;\r
-\r
- // Not all blocks are editable, e.g. <hr />, further checking it.(#3994)\r
- if( ( !count\r
- || ( firstChild = children.getItem( 0 ) ) && firstChild.is && firstChild.is( 'br' ) )\r
- && enterBlock\r
- && range.moveToElementEditStart( enterBlock ) )\r
+ // If the fixed block is actually blank and is already followed by an exitable blank\r
+ // block, we should revert the fix and move into the existed one. (#3684)\r
+ if ( isBlankParagraph( fixedBlock ) )\r
{\r
- fixedBlock.remove();\r
- range.select();\r
+ var previousElement = fixedBlock.getPrevious( isNotWhitespace ),\r
+ nextElement = fixedBlock.getNext( isNotWhitespace );\r
+\r
+ if ( previousElement && previousElement.getName\r
+ && !( previousElement.getName() in nonExitableElementNames )\r
+ && isBlankParagraph( previousElement )\r
+ && range.moveToElementEditStart( previousElement )\r
+ || nextElement && nextElement.getName\r
+ && !( nextElement.getName() in nonExitableElementNames )\r
+ && isBlankParagraph( nextElement )\r
+ && range.moveToElementEditStart( nextElement ) )\r
+ {\r
+ fixedBlock.remove();\r
+ }\r
}\r
+\r
+ range.select();\r
+ // Notify non-IE that selection has changed.\r
+ if ( !CKEDITOR.env.ie )\r
+ editor.selectionChange();\r
}\r
\r
- // Inserting the padding-br before body if it's preceded by an\r
- // unexitable block.\r
- var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
- if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )\r
+ // All browsers are incapable to moving cursor out of certain non-exitable\r
+ // blocks (e.g. table, list, pre) at the end of document, make this happen by\r
+ // place a bogus node there, which would be later removed by dataprocessor.\r
+ var walkerRange = new CKEDITOR.dom.range( editor.document ),\r
+ walker = new CKEDITOR.dom.walker( walkerRange );\r
+ walkerRange.selectNodeContents( body );\r
+ walker.evaluator = function( node )\r
{\r
+ return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );\r
+ };\r
+ walker.guard = function( node, isMoveout )\r
+ {\r
+ return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );\r
+ };\r
+\r
+ if ( walker.previous() )\r
+ {\r
+ editor.fire( 'updateSnapshot' );\r
restoreDirty( editor );\r
- var paddingBlock = editor.document.createElement(\r
- ( CKEDITOR.env.ie && enterMode != CKEDITOR.ENTER_BR ) ?\r
- '<br _cke_bogus="true" />' : 'br' );\r
- body.append( paddingBlock );\r
+ CKEDITOR.env.ie && restoreSelection( selection );\r
+\r
+ var paddingBlock;\r
+ if ( enterMode != CKEDITOR.ENTER_BR )\r
+ paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );\r
+ else\r
+ paddingBlock = body;\r
+\r
+ if ( !CKEDITOR.env.ie )\r
+ paddingBlock.appendBogus();\r
}\r
}\r
\r
var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )\r
? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;\r
\r
+ var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );\r
+\r
+ var contentDomReadyHandler;\r
editor.on( 'editingBlockReady', function()\r
{\r
var mainElement,\r
- fieldset,\r
iframe,\r
isLoadingData,\r
isPendingFocus,\r
frameLoaded,\r
fireMode;\r
\r
+\r
// Support for custom document.domain in IE.\r
var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
\r
// Creates the iframe that holds the editable document.\r
- var createIFrame = function()\r
+ var createIFrame = function( data )\r
{\r
if ( iframe )\r
iframe.remove();\r
- if ( fieldset )\r
- fieldset.remove();\r
\r
- frameLoaded = 0;\r
- // The document domain must be set within the src\r
- // attribute;\r
- // Defer the script execution until iframe\r
- // has been added to main window, this is needed for some\r
- // browsers which will begin to load the frame content\r
- // prior to it's presentation in DOM.(#3894)\r
- var src = 'void( '\r
- + ( CKEDITOR.env.gecko ? 'setTimeout' : '' ) + '( function(){' +\r
- 'document.open();' +\r
- ( CKEDITOR.env.ie && isCustomDomain ? 'document.domain="' + document.domain + '";' : '' ) +\r
- 'document.write( window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] );' +\r
- 'document.close();' +\r
- 'window.parent[ "_cke_htmlToLoad_' + editor.name + '" ] = null;' +\r
- '}'\r
- + ( CKEDITOR.env.gecko ? ', 0 )' : ')()' )\r
- + ' )';\r
-\r
- // Loading via src attribute does not work in Opera.\r
- if ( CKEDITOR.env.opera )\r
- src = 'void(0);';\r
\r
- iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
- ' style="width:100%;height:100%"' +\r
- ' frameBorder="0"' +\r
- ' tabIndex="-1"' +\r
- ' allowTransparency="true"' +\r
- ' src="javascript:' + encodeURIComponent( src ) + '"' +\r
- '></iframe>' );\r
+ var srcScript =\r
+ 'document.open();' +\r
\r
- var accTitle = editor.lang.editorTitle.replace( '%1', editor.name );\r
+ // The document domain must be set any time we\r
+ // call document.open().\r
+ ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
\r
- if ( CKEDITOR.env.gecko )\r
- {\r
- // Double checking the iframe will be loaded properly(#4058).\r
- iframe.on( 'load', function( ev )\r
+ 'document.close();';\r
+\r
+ iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
+ ' style="width:100%;height:100%"' +\r
+ ' frameBorder="0"' +\r
+ ' title="' + frameLabel + '"' +\r
+ // With IE, the custom domain has to be taken care at first,\r
+ // for other browers, the 'src' attribute should be left empty to\r
+ // trigger iframe's 'load' event.\r
+ ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +\r
+ ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +\r
+ ' allowTransparency="true"' +\r
+ '></iframe>' );\r
+\r
+ // With FF, it's better to load the data on iframe.load. (#3894,#4058)\r
+ iframe.on( 'load', function( ev )\r
{\r
+ frameLoaded = 1;\r
ev.removeListener();\r
- contentDomReady( iframe.$.contentWindow );\r
- } );\r
\r
- // Accessibility attributes for Firefox.\r
- mainElement.setAttributes(\r
- {\r
- role : 'region',\r
- title : accTitle\r
- } );\r
- iframe.setAttributes(\r
- {\r
- role : 'region',\r
- title : ' '\r
- } );\r
- }\r
- else if ( CKEDITOR.env.webkit )\r
- {\r
- iframe.setAttribute( 'title', accTitle ); // Safari 4\r
- iframe.setAttribute( 'name', accTitle ); // Safari 3\r
- }\r
- else if ( CKEDITOR.env.ie )\r
- {\r
- // Accessibility label for IE.\r
- fieldset = CKEDITOR.dom.element.createFromHtml(\r
- '<fieldset style="height:100%' +\r
- ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? ';position:relative' : '' ) +\r
- '">' +\r
- '<legend style="display:block;width:0;height:0;overflow:hidden;' +\r
- ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? 'position:absolute' : '' ) +\r
- '">' +\r
- CKEDITOR.tools.htmlEncode( accTitle ) +\r
- '</legend>' +\r
- '</fieldset>'\r
- , CKEDITOR.document );\r
- iframe.appendTo( fieldset );\r
- fieldset.appendTo( mainElement );\r
- }\r
+ var doc = iframe.getFrameDocument().$;\r
\r
- if ( !CKEDITOR.env.ie )\r
- mainElement.append( iframe );\r
+ // Don't leave any history log in IE. (#5657)\r
+ doc.open( "text/html","replace" );\r
+ doc.write( data );\r
+ doc.close();\r
+ });\r
+\r
+ mainElement.append( iframe );\r
};\r
\r
- // The script that is appended to the data being loaded. It\r
- // enables editing, and makes some\r
+ // The script that launches the bootstrap logic on 'domReady', so the document\r
+ // is fully editable even before the editing iframe is fully loaded (#4455).\r
+ contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady );\r
var activationScript =\r
- '<script id="cke_actscrpt" type="text/javascript">' +\r
- 'window.onload = function()' +\r
- '{' +\r
- // Call the temporary function for the editing\r
- // boostrap.\r
- 'window.parent.CKEDITOR._["contentDomReady' + editor.name + '"]( window );' +\r
- '}' +\r
+ '<script id="cke_actscrpt" type="text/javascript" cke_temp="1">' +\r
+ ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
+ 'window.parent.CKEDITOR.tools.callFunction( ' + contentDomReadyHandler + ', window );' +\r
'</script>';\r
\r
// Editing area bootstrap code.\r
- var contentDomReady = function( domWindow )\r
+ function contentDomReady( domWindow )\r
{\r
- if ( frameLoaded )\r
+ if ( !frameLoaded )\r
return;\r
+ frameLoaded = 0;\r
\r
- frameLoaded = 1;\r
+ editor.fire( 'ariaWidget', iframe );\r
\r
var domDocument = domWindow.document,\r
body = domDocument.body;\r
var script = domDocument.getElementById( "cke_actscrpt" );\r
script.parentNode.removeChild( script );\r
\r
- delete CKEDITOR._[ 'contentDomReady' + editor.name ];\r
-\r
body.spellcheck = !editor.config.disableNativeSpellChecker;\r
\r
if ( CKEDITOR.env.ie )\r
body.removeAttribute( 'disabled' );\r
}\r
else\r
- domDocument.designMode = 'on';\r
+ {\r
+ // Avoid opening design mode in a frame window thread,\r
+ // which will cause host page scrolling.(#4397)\r
+ setTimeout( function()\r
+ {\r
+ // Prefer 'contentEditable' instead of 'designMode'. (#3593)\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900\r
+ || CKEDITOR.env.opera )\r
+ domDocument.$.body.contentEditable = true;\r
+ else if ( CKEDITOR.env.webkit )\r
+ domDocument.$.body.parentNode.contentEditable = true;\r
+ else\r
+ domDocument.$.designMode = 'on';\r
+ }, 0 );\r
+ }\r
+\r
+ // Gecko need a key event to 'wake up' the editing\r
+ // ability when document is empty.(#3864)\r
+ if ( CKEDITOR.env.gecko && !body.childNodes.length )\r
+ {\r
+ setTimeout( function()\r
+ {\r
+ restoreDirty( editor );\r
+\r
+ // Simulating keyboard character input by dispatching a keydown of white-space text.\r
+ var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );\r
+ keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,\r
+ false, false, false, 0, 32 );\r
+ domDocument.$.dispatchEvent( keyEventSimulate );\r
+\r
+ // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
+ domDocument.createElement( 'br', { attributes: { '_moz_editor_bogus_node' : 'TRUE', '_moz_dirty' : "" } } )\r
+ .replace( domDocument.getBody().getFirst() );\r
+ var nativeRange = new CKEDITOR.dom.range( domDocument );\r
+ nativeRange.setStartAt( new CKEDITOR.dom.element( body ) , CKEDITOR.POSITION_AFTER_START );\r
+ nativeRange.select();\r
+ }, 0 );\r
+ }\r
\r
// IE, Opera and Safari may not support it and throw\r
// errors.\r
domWindow = editor.window = new CKEDITOR.dom.window( domWindow );\r
domDocument = editor.document = new CKEDITOR.dom.document( domDocument );\r
\r
+ domDocument.on( 'dblclick', function( evt )\r
+ {\r
+ var element = evt.data.getTarget(),\r
+ data = { element : element, dialog : '' };\r
+ editor.fire( 'doubleclick', data );\r
+ data.dialog && editor.openDialog( data.dialog );\r
+ });\r
+\r
// Gecko/Webkit need some help when selecting control type elements. (#3448)\r
if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )\r
{\r
} );\r
}\r
\r
- var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?\r
- domWindow : domDocument;\r
+ // IE standard compliant in editing frame doesn't focus the editor when\r
+ // clicking outside actual content, manually apply the focus. (#1659)\r
+ if ( CKEDITOR.env.ie\r
+ && domDocument.$.compatMode == 'CSS1Compat'\r
+ || CKEDITOR.env.gecko\r
+ || CKEDITOR.env.opera )\r
+ {\r
+ var htmlElement = domDocument.getDocumentElement();\r
+ htmlElement.on( 'mousedown', function( evt )\r
+ {\r
+ // Setting focus directly on editor doesn't work, we\r
+ // have to use here a temporary element to 'redirect'\r
+ // the focus.\r
+ if ( evt.data.getTarget().equals( htmlElement ) )\r
+ {\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
+ blinkCursor();\r
+ focusGrabber.focus();\r
+ }\r
+ } );\r
+ }\r
\r
- focusTarget.on( 'blur', function()\r
+ domWindow.on( 'blur', function()\r
{\r
editor.focusManager.blur();\r
});\r
\r
- focusTarget.on( 'focus', function()\r
+ domWindow.on( 'focus', function()\r
{\r
- // Gecko need a key event to 'wake up' the editing\r
- // ability when document is empty.(#3864)\r
- if ( CKEDITOR.env.gecko )\r
- {\r
- var first = body;\r
- while( first.firstChild )\r
- first = first.firstChild;\r
+ var doc = editor.document;\r
\r
- if( !first.nextSibling\r
- && ( 'BR' == first.tagName )\r
- && first.hasAttribute( '_moz_editor_bogus_node' ) )\r
- {\r
- var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );\r
- keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,\r
- false, false, false, 0, 32 );\r
- domDocument.$.dispatchEvent( keyEventSimulate );\r
- var bogusText = domDocument.getBody().getFirst() ;\r
- // Compensate the line maintaining <br> if enterMode is not block.\r
- if ( editor.config.enterMode == CKEDITOR.ENTER_BR )\r
- domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )\r
- .replace( bogusText );\r
- else\r
- bogusText.remove();\r
- }\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
+ blinkCursor();\r
+ else if ( CKEDITOR.env.opera )\r
+ doc.getBody().focus();\r
+ else if ( CKEDITOR.env.webkit )\r
+ {\r
+ // Selection will get lost after move focus\r
+ // to document element, save it first.\r
+ var sel = editor.getSelection(),\r
+ type = sel.getType(),\r
+ range = ( type != CKEDITOR.SELECTION_NONE ) && sel.getRanges()[ 0 ];\r
+\r
+ doc.getDocumentElement().focus();\r
+ range && range.select();\r
}\r
\r
editor.focusManager.focus();\r
if ( keystrokeHandler )\r
keystrokeHandler.attach( domDocument );\r
\r
- // Cancel default action for backspace in IE on control types. (#4047)\r
if ( CKEDITOR.env.ie )\r
{\r
- editor.on( 'key', function( event )\r
+ domDocument.getDocumentElement().addClass( domDocument.$.compatMode );\r
+ // Override keystrokes which should have deletion behavior\r
+ // on control types in IE . (#4047)\r
+ domDocument.on( 'keydown', function( evt )\r
{\r
- // Backspace.\r
- var control = event.data.keyCode == 8\r
- && editor.getSelection().getSelectedElement();\r
- if ( control )\r
+ var keyCode = evt.data.getKeystroke();\r
+\r
+ // Backspace OR Delete.\r
+ if ( keyCode in { 8 : 1, 46 : 1 } )\r
{\r
- // Make undo snapshot.\r
- editor.fire( 'saveSnapshot' );\r
- // Remove manually.\r
- control.remove();\r
- editor.fire( 'saveSnapshot' );\r
- event.cancel();\r
+ var sel = editor.getSelection(),\r
+ control = sel.getSelectedElement();\r
+\r
+ if ( control )\r
+ {\r
+ // Make undo snapshot.\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will\r
+ // break up the selection, safely manage it here. (#4795)\r
+ var bookmark = sel.getRanges()[ 0 ].createBookmark();\r
+ // Remove the control manually.\r
+ control.remove();\r
+ sel.selectBookmarks( [ bookmark ] );\r
+\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ evt.data.preventDefault();\r
+ }\r
}\r
} );\r
+\r
+ // PageUp/PageDown scrolling is broken in document\r
+ // with standard doctype, manually fix it. (#4736)\r
+ if ( domDocument.$.compatMode == 'CSS1Compat' )\r
+ {\r
+ var pageUpDownKeys = { 33 : 1, 34 : 1 };\r
+ domDocument.on( 'keydown', function( evt )\r
+ {\r
+ if ( evt.data.getKeystroke() in pageUpDownKeys )\r
+ {\r
+ setTimeout( function ()\r
+ {\r
+ editor.getSelection().scrollIntoView();\r
+ }, 0 );\r
+ }\r
+ } );\r
+ }\r
}\r
\r
// Adds the document body as a context menu target.\r
if ( editor.contextMenu )\r
- editor.contextMenu.addTarget( domDocument );\r
+ editor.contextMenu.addTarget( domDocument, editor.config.browserContextMenuOnCtrl !== false );\r
\r
setTimeout( function()\r
{\r
}\r
},\r
0 );\r
- };\r
+ }\r
\r
editor.addMode( 'wysiwyg',\r
{\r
{\r
isLoadingData = true;\r
\r
+ var config = editor.config,\r
+ fullPage = config.fullPage,\r
+ docType = config.docType;\r
+\r
+ // Build the additional stuff to be included into <head>.\r
+ var headExtra =\r
+ '<style type="text/css" cke_temp="1">' +\r
+ editor._.styles.join( '\n' ) +\r
+ '</style>';\r
+\r
+ !fullPage && ( headExtra =\r
+ CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +\r
+ headExtra );\r
+\r
+ var baseTag = config.baseHref ? '<base href="' + config.baseHref + '" cke_temp="1" />' : '';\r
+\r
+ if ( fullPage )\r
+ {\r
+ // Search and sweep out the doctype declaration.\r
+ data = data.replace( /<!DOCTYPE[^>]*>/i, function( match )\r
+ {\r
+ editor.docType = docType = match;\r
+ return '';\r
+ });\r
+ }\r
+\r
// Get the HTML version of the data.\r
if ( editor.dataProcessor )\r
- {\r
data = editor.dataProcessor.toHtml( data, fixForBody );\r
- }\r
\r
- data =\r
- editor.config.docType +\r
- '<html dir="' + editor.config.contentsLangDirection + '">' +\r
- '<head>' +\r
- '<link type="text/css" rel="stylesheet" href="' +\r
- [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +\r
- '">' +\r
- '<style type="text/css" _fcktemp="true">' +\r
- editor._.styles.join( '\n' ) +\r
- '</style>'+\r
- '</head>' +\r
- '<body>' +\r
- data +\r
- '</body>' +\r
- '</html>' +\r
- activationScript;\r
-\r
- window[ '_cke_htmlToLoad_' + editor.name ] = data;\r
- CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;\r
- createIFrame();\r
-\r
- // Opera must use the old method for loading contents.\r
- if ( CKEDITOR.env.opera )\r
+ if ( fullPage )\r
{\r
- var doc = iframe.$.contentWindow.document;\r
- doc.open();\r
- doc.write( data );\r
- doc.close();\r
+ // Check if the <body> tag is available.\r
+ if ( !(/<body[\s|>]/).test( data ) )\r
+ data = '<body>' + data;\r
+\r
+ // Check if the <html> tag is available.\r
+ if ( !(/<html[\s|>]/).test( data ) )\r
+ data = '<html>' + data + '</html>';\r
+\r
+ // Check if the <head> tag is available.\r
+ if ( !(/<head[\s|>]/).test( data ) )\r
+ data = data.replace( /<html[^>]*>/, '$&<head><title></title></head>' ) ;\r
+ else if ( !(/<title[\s|>]/).test( data ) )\r
+ data = data.replace( /<head[^>]*>/, '$&<title></title>' ) ;\r
+\r
+ // The base must be the first tag in the HEAD, e.g. to get relative\r
+ // links on styles.\r
+ baseTag && ( data = data.replace( /<head>/, '$&' + baseTag ) );\r
+\r
+ // Inject the extra stuff into <head>.\r
+ // Attention: do not change it before testing it well. (V2)\r
+ // This is tricky... if the head ends with <meta ... content type>,\r
+ // Firefox will break. But, it works if we place our extra stuff as\r
+ // the last elements in the HEAD.\r
+ data = data.replace( /<\/head\s*>/, headExtra + '$&' );\r
+\r
+ // Add the DOCTYPE back to it.\r
+ data = docType + data;\r
}\r
+ else\r
+ {\r
+ data =\r
+ config.docType +\r
+ '<html dir="' + config.contentsLangDirection + '"' +\r
+ ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +\r
+ '<head>' +\r
+ '<title>' + frameLabel + '</title>' +\r
+ baseTag +\r
+ headExtra +\r
+ '</head>' +\r
+ '<body' + ( config.bodyId ? ' id="' + config.bodyId + '"' : '' ) +\r
+ ( config.bodyClass ? ' class="' + config.bodyClass + '"' : '' ) +\r
+ '>' +\r
+ data +\r
+ '</html>';\r
+ }\r
+\r
+ data += activationScript;\r
+\r
+\r
+ // The iframe is recreated on each call of setData, so we need to clear DOM objects\r
+ this.onDispose();\r
+ createIFrame( data );\r
},\r
\r
getData : function()\r
{\r
- var data = iframe.getFrameDocument().getBody().getHtml();\r
+ var config = editor.config,\r
+ fullPage = config.fullPage,\r
+ docType = fullPage && editor.docType,\r
+ doc = iframe.getFrameDocument();\r
+\r
+ var data = fullPage\r
+ ? doc.getDocumentElement().getOuterHtml()\r
+ : doc.getBody().getHtml();\r
\r
if ( editor.dataProcessor )\r
data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
\r
// Strip the last blank paragraph within document.\r
- if ( editor.config.ignoreEmptyParagraph )\r
+ if ( config.ignoreEmptyParagraph )\r
data = data.replace( emptyParagraphRegexp, '' );\r
\r
+ if ( docType )\r
+ data = docType + '\n' + data;\r
+\r
return data;\r
},\r
\r
iframe.getFrameDocument().getBody().setHtml( data );\r
},\r
\r
+ onDispose : function()\r
+ {\r
+ if ( !editor.document )\r
+ return;\r
+\r
+ editor.document.getDocumentElement().clearCustomData();\r
+ editor.document.getBody().clearCustomData();\r
+\r
+ editor.window.clearCustomData();\r
+ editor.document.clearCustomData();\r
+\r
+ iframe.clearCustomData();\r
+ },\r
+\r
unload : function( holderElement )\r
{\r
+ this.onDispose();\r
+\r
editor.window = editor.document = iframe = mainElement = isPendingFocus = null;\r
\r
editor.fire( 'contentDomUnload' );\r
else if ( editor.window )\r
{\r
editor.window.focus();\r
+\r
editor.selectionChange();\r
}\r
}\r
// Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)\r
editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );\r
});\r
+\r
+ var titleBackup;\r
+ // Setting voice label as window title, backup the original one\r
+ // and restore it before running into use.\r
+ editor.on( 'contentDom', function ()\r
+ {\r
+ var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );\r
+ title.setAttribute( '_cke_title', editor.document.$.title );\r
+ editor.document.$.title = frameLabel;\r
+ });\r
+\r
+ // IE8 stricts mode doesn't have 'contentEditable' in effect\r
+ // on element unless it has layout. (#5562)\r
+ if ( CKEDITOR.env.ie8Compat )\r
+ {\r
+ editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );\r
+\r
+ var selectors = [];\r
+ for ( var tag in CKEDITOR.dtd.$removeEmpty )\r
+ selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );\r
+ editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );\r
+ }\r
+\r
+ // Switch on design mode for a short while and close it after then.\r
+ function blinkCursor( retry )\r
+ {\r
+ CKEDITOR.tools.tryThese(\r
+ function()\r
+ {\r
+ editor.document.$.designMode = 'on';\r
+ setTimeout( function ()\r
+ {\r
+ editor.document.$.designMode = 'off';\r
+ editor.document.getBody().focus();\r
+ }, 50 );\r
+ },\r
+ function()\r
+ {\r
+ // The above call is known to fail when parent DOM\r
+ // tree layout changes may break design mode. (#5782)\r
+ // Refresh the 'contentEditable' is a cue to this.\r
+ editor.document.$.designMode = 'off';\r
+ var body = editor.document.getBody();\r
+ body.setAttribute( 'contentEditable', false );\r
+ body.setAttribute( 'contentEditable', true );\r
+ // Try it again once..\r
+ !retry && blinkCursor( 1 );\r
+ });\r
+ }\r
+\r
+ // Create an invisible element to grab focus.\r
+ if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )\r
+ {\r
+ var focusGrabber;\r
+ editor.on( 'uiReady', function()\r
+ {\r
+ focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
+ // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)\r
+ '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );\r
+\r
+ focusGrabber.on( 'focus', function()\r
+ {\r
+ editor.focus();\r
+ } );\r
+ } );\r
+ editor.on( 'destroy', function()\r
+ {\r
+ CKEDITOR.tools.removeFunction( contentDomReadyHandler );\r
+ focusGrabber.clearCustomData();\r
+ } );\r
+ }\r
+\r
+ // Disable form elements editing mode provided by some browers. (#5746)\r
+ editor.on( 'insertElement', function ( evt )\r
+ {\r
+ var element = evt.data;\r
+ if ( element.type = CKEDITOR.NODE_ELEMENT\r
+ && ( element.is( 'input' ) || element.is( 'textarea' ) ) )\r
+ {\r
+ element.setAttribute( 'contentEditable', false );\r
+ }\r
+ });\r
+\r
}\r
});\r
+\r
+ // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)\r
+ if ( CKEDITOR.env.gecko )\r
+ {\r
+ ( function ()\r
+ {\r
+ var body = document.body;\r
+\r
+ if ( !body )\r
+ window.addEventListener( 'load', arguments.callee, false );\r
+ else\r
+ {\r
+ var currentHandler = body.getAttribute( 'onpageshow' );\r
+ body.setAttribute( 'onpageshow', ( currentHandler ? currentHandler + ';' : '') +\r
+ 'event.persisted && (function(){' +\r
+ 'var allInstances = CKEDITOR.instances, editor, doc;' +\r
+ 'for ( var i in allInstances )' +\r
+ '{' +\r
+ ' editor = allInstances[ i ];' +\r
+ ' doc = editor.document;' +\r
+ ' if ( doc )' +\r
+ ' {' +\r
+ ' doc.$.designMode = "off";' +\r
+ ' doc.$.designMode = "on";' +\r
+ ' }' +\r
+ '}' +\r
+ '})();' );\r
+ }\r
+ } )();\r
+\r
+ }\r
})();\r
\r
/**\r
* config.ignoreEmptyParagraph = false;\r
*/\r
CKEDITOR.config.ignoreEmptyParagraph = true;\r
+\r
+/**\r
+ * Fired when data is loaded and ready for retrieval in an editor instance.\r
+ * @name CKEDITOR.editor#dataReady\r
+ * @event\r
+ */\r