}\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
CKEDITOR.env.ie && restoreSelection( selection );\r
\r
first && isNbsp( first ) && first.remove();\r
}\r
\r
- // If the fixed block is blank and already followed by a exitable\r
- // block, we should revert the fix. (#3684)\r
- if ( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )\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
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
- && range.moveToElementEditStart( nextElement ) )\r
+ && !( nextElement.getName() in nonExitableElementNames )\r
+ && isBlankParagraph( nextElement )\r
+ && range.moveToElementEditStart( nextElement ) )\r
{\r
fixedBlock.remove();\r
}\r
\r
if ( walker.previous() )\r
{\r
+ editor.fire( 'updateSnapshot' );\r
restoreDirty( editor );\r
CKEDITOR.env.ie && restoreSelection( selection );\r
\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
if ( iframe )\r
iframe.remove();\r
\r
- frameLoaded = 0;\r
-\r
- var setDataFn = !CKEDITOR.env.gecko && CKEDITOR.tools.addFunction( function( doc )\r
- {\r
- CKEDITOR.tools.removeFunction( setDataFn );\r
- doc.write( data );\r
- });\r
\r
var srcScript =\r
'document.open();' +\r
// call document.open().\r
( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
\r
- ( ( 'parent.CKEDITOR.tools.callFunction(' + setDataFn + ',document);' ) ) +\r
-\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 FF, the 'src' attribute should be left empty to\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.gecko ? '' : 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' ) + '"' +\r
- ' tabIndex="' + editor.tabIndex + '"' +\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
- CKEDITOR.env.gecko && iframe.on( 'load', function( ev )\r
+ iframe.on( 'load', function( ev )\r
{\r
+ frameLoaded = 1;\r
ev.removeListener();\r
\r
var doc = iframe.getFrameDocument().$;\r
\r
- doc.open();\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
// 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" cke_temp="1">' +\r
( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
- 'parent.CKEDITOR._["contentDomReady' + editor.name + '"]( window );' +\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 = 1;\r
+ frameLoaded = 0;\r
\r
editor.fire( 'ariaWidget', iframe );\r
\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
// 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
+ && domDocument.$.compatMode == 'CSS1Compat'\r
+ || CKEDITOR.env.gecko\r
+ || CKEDITOR.env.opera )\r
{\r
var htmlElement = domDocument.getDocumentElement();\r
htmlElement.on( 'mousedown', function( evt )\r
// have to use here a temporary element to 'redirect'\r
// the focus.\r
if ( evt.data.getTarget().equals( htmlElement ) )\r
- ieFocusGrabber.focus();\r
+ {\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
+ blinkCursor();\r
+ focusGrabber.focus();\r
+ }\r
} );\r
}\r
\r
- var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?\r
- domWindow : domDocument;\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
+ var doc = editor.document;\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
- var first = body;\r
- while ( first.firstChild )\r
- first = first.firstChild;\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
- if ( !first.nextSibling\r
- && ( 'BR' == first.tagName )\r
- && first.hasAttribute( '_moz_editor_bogus_node' ) )\r
- {\r
- restoreDirty( editor );\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
+ doc.getDocumentElement().focus();\r
+ range && range.select();\r
}\r
\r
editor.focusManager.focus();\r
\r
if ( CKEDITOR.env.ie )\r
{\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
},\r
0 );\r
- };\r
+ }\r
\r
editor.addMode( 'wysiwyg',\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
{\r
data =\r
config.docType +\r
- '<html dir="' + config.contentsLangDirection + '">' +\r
- '<title>' + frameLabel + '</title>' +\r
+ '<html dir="' + config.contentsLangDirection + '"' +\r
+ ' lang="' + ( config.contentsLanguage || editor.langCode ) + '">' +\r
'<head>' +\r
+ '<title>' + frameLabel + '</title>' +\r
baseTag +\r
headExtra +\r
'</head>' +\r
\r
data += activationScript;\r
\r
- CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;\r
\r
// The iframe is recreated on each call of setData, so we need to clear DOM objects\r
this.onDispose();\r
else if ( editor.window )\r
{\r
editor.window.focus();\r
+\r
editor.selectionChange();\r
}\r
}\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.ie )\r
+ if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )\r
{\r
- var ieFocusGrabber;\r
+ var focusGrabber;\r
editor.on( 'uiReady', function()\r
{\r
- ieFocusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\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
- ieFocusGrabber.on( 'focus', function()\r
+ focusGrabber.on( 'focus', function()\r
{\r
editor.focus();\r
} );\r
} );\r
editor.on( 'destroy', function()\r
{\r
- ieFocusGrabber.clearCustomData();\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
window.addEventListener( 'load', arguments.callee, false );\r
else\r
{\r
- body.setAttribute( 'onpageshow', body.getAttribute( 'onpageshow' )\r
- + ';event.persisted && CKEDITOR.tools.callFunction(' +\r
- CKEDITOR.tools.addFunction( function()\r
- {\r
- var allInstances = CKEDITOR.instances,\r
- editor,\r
- 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
+ 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