JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index ab06245..0a35305 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -10,12 +10,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \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[^>]*>|&nbsp;|&#160;)\s*(:?<\/\1>)?\s*$/gi;\r
+       var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center|li)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi;\r
+\r
+       var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
+\r
+       function checkReadOnly( selection )\r
+       {\r
+               if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )\r
+                       return selection.getSelectedElement().isReadOnly();\r
+               else\r
+                       return selection.getCommonAncestor().isReadOnly();\r
+       }\r
 \r
        function onInsertHtml( evt )\r
        {\r
@@ -23,8 +32,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        this.focus();\r
 \r
-                       var selection = this.getSelection(),\r
-                               data = evt.data;\r
+                       var selection = this.getSelection();\r
+                       if ( checkReadOnly( selection ) )\r
+                               return;\r
+\r
+                       var data = evt.data;\r
+                       this.fire( 'saveSnapshot' );\r
 \r
                        if ( this.dataProcessor )\r
                                data = this.dataProcessor.toHtml( data );\r
@@ -37,8 +50,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        selection.unlock();\r
 \r
                                var $sel = selection.getNative();\r
+\r
+                               // Delete control selections to avoid IE bugs on pasteHTML.\r
                                if ( $sel.type == 'Control' )\r
                                        $sel.clear();\r
+                               else if  ( selection.getType() == CKEDITOR.SELECTION_TEXT )\r
+                               {\r
+                                       // Due to IE bugs on handling contenteditable=false blocks\r
+                                       // (#6005), we need to make some checks and eventually\r
+                                       // delete the selection first.\r
+\r
+                                       var range = selection.getRanges()[0],\r
+                                               endContainer = range && range.endContainer;\r
+\r
+                                       if ( endContainer &&\r
+                                                endContainer.type == CKEDITOR.NODE_ELEMENT &&\r
+                                                endContainer.getAttribute( 'contenteditable' ) == 'false' &&\r
+                                                range.checkBoundaryOfElement( endContainer, CKEDITOR.END ) )\r
+                                       {\r
+                                               range.setEndAfter( range.endContainer );\r
+                                               range.deleteContents();\r
+                                       }\r
+                               }\r
+\r
                                $sel.createRange().pasteHTML( data );\r
 \r
                                if ( selIsLocked )\r
@@ -46,6 +80,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
                        else\r
                                this.document.$.execCommand( 'inserthtml', false, data );\r
+\r
+                       // Webkit does not scroll to the cursor position after pasting (#5558)\r
+                       if ( CKEDITOR.env.webkit )\r
+                       {\r
+                               this.document.$.execCommand( 'inserthtml', false, '<span id="cke_paste_marker" cke_temp="1"></span>' );\r
+                               var marker = this.document.getById( 'cke_paste_marker' );\r
+                               marker.scrollIntoView();\r
+                               marker.remove();\r
+                       }\r
+\r
+                       CKEDITOR.tools.setTimeout( function()\r
+                               {\r
+                                       this.fire( 'saveSnapshot' );\r
+                               }, 0, this );\r
                }\r
        }\r
 \r
@@ -54,15 +102,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                if ( this.mode == 'wysiwyg' )\r
                {\r
                        this.focus();\r
+\r
+                       var selection = this.getSelection();\r
+                       if ( checkReadOnly( selection ) )\r
+                               return;\r
+\r
                        this.fire( 'saveSnapshot' );\r
 \r
-                       var element = evt.data,\r
+                       var ranges = selection.getRanges(),\r
+                               element = evt.data,\r
                                elementName = element.getName(),\r
                                isBlock = CKEDITOR.dtd.$block[ elementName ];\r
 \r
-                       var selection = this.getSelection(),\r
-                               ranges = selection.getRanges();\r
-\r
                        var selIsLocked = selection.isLocked;\r
 \r
                        if ( selIsLocked )\r
@@ -84,13 +135,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                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
@@ -113,9 +167,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );\r
 \r
-                       var next = lastElement.getNextSourceNode( true );\r
-                       if ( next && next.type == CKEDITOR.NODE_ELEMENT )\r
-                               range.moveToElementEditStart( next );\r
+                       // If we're inserting a block element immediatelly followed by\r
+                       // another block element, the selection must move there. (#3100,#5436)\r
+                       if ( isBlock )\r
+                       {\r
+                               var next = lastElement.getNext( notWhitespaceEval ),\r
+                                       nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();\r
+\r
+                               // Check if it's a block element that accepts text.\r
+                               if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )\r
+                                       range.moveToElementEditStart( next );\r
+                       }\r
 \r
                        selection.selectRanges( [ range ] );\r
 \r
@@ -135,10 +197,68 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        // 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( /^(?:&nbsp;|\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
+       // Gecko need a key event to 'wake up' the editing\r
+       // ability when document is empty.(#3864, #5781)\r
+       function activateEditing( editor )\r
+       {\r
+               var win = editor.window,\r
+                       doc = editor.document,\r
+                       body = editor.document.getBody(),\r
+                       bodyChildsNum = body.getChildren().count();\r
+\r
+               if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )\r
+               {\r
+                       restoreDirty( editor );\r
+\r
+                       // Simulating keyboard character input by dispatching a keydown of white-space text.\r
+                       var keyEventSimulate = doc.$.createEvent( "KeyEvents" );\r
+                       keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,\r
+                               false, false, false, 0, 32 );\r
+                       doc.$.dispatchEvent( keyEventSimulate );\r
+\r
+                       // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
+                       bodyChildsNum && body.getFirst().remove();\r
+                       doc.getBody().appendBogus();\r
+                       var nativeRange = new CKEDITOR.dom.range( doc );\r
+                       nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START );\r
+                       nativeRange.select();\r
+               }\r
+       }\r
+\r
        /**\r
         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
         *  non-exitable-block by padding extra br.(#3189)\r
@@ -153,6 +273,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        body = editor.document.getBody(),\r
                        enterMode = editor.config.enterMode;\r
 \r
+               CKEDITOR.env.gecko && activateEditing( editor );\r
+\r
                // When enterMode set to block, we'll establing new paragraph only if we're\r
                // selecting inline contents right under body. (#3657)\r
                if ( enterMode != CKEDITOR.ENTER_BR\r
@@ -160,62 +282,80 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                         && 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 element = fixedBlock.getNext( isNotWhitespace );\r
+                               if ( element &&\r
+                                        element.type == CKEDITOR.NODE_ELEMENT &&\r
+                                        !nonExitableElementNames[ element.getName() ] )\r
+                               {\r
+                                       range.moveToElementEditStart( element );\r
+                                       fixedBlock.remove();\r
+                               }\r
+                               else\r
+                               {\r
+                                       element = fixedBlock.getPrevious( isNotWhitespace );\r
+                                       if ( element &&\r
+                                                element.type == CKEDITOR.NODE_ELEMENT &&\r
+                                                !nonExitableElementNames[ element.getName() ] )\r
+                                       {\r
+                                               range.moveToElementEditEnd( element );\r
+                                               fixedBlock.remove();\r
+                                       }\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
@@ -228,126 +368,92 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        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
+                                               // #5689 Running inside of Firefox chrome the load event doesn't bubble like in a normal page\r
+                                               if (document.location.protocol == 'chrome:')\r
+                                                       CKEDITOR.event.useCapture = true;\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
+                                               // #5689 Reset adjustment back to default\r
+                                               if (document.location.protocol == 'chrome:')\r
+                                                       CKEDITOR.event.useCapture = false;\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
@@ -356,8 +462,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                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
@@ -372,16 +476,35 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        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
-                                               // IE, Opera and Safari may not support it and throw\r
-                                               // errors.\r
-                                               try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}\r
-                                               try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}\r
+                                               CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );\r
 \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
@@ -393,6 +516,34 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        } );\r
                                                }\r
 \r
+                                               if ( CKEDITOR.env.gecko )\r
+                                               {\r
+                                                       domDocument.on( 'mouseup', function( ev )\r
+                                                       {\r
+                                                               if ( ev.data.$.button == 2 )\r
+                                                               {\r
+                                                                       var target = ev.data.getTarget();\r
+\r
+                                                                       // Prevent right click from selecting an empty block even\r
+                                                                       // when selection is anchored inside it. (#5845)\r
+                                                                       if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) )\r
+                                                                       {\r
+                                                                               var range = new CKEDITOR.dom.range( domDocument );\r
+                                                                               range.moveToElementEditStart( target );\r
+                                                                               range.select( true );\r
+                                                                       }\r
+                                                               }\r
+                                                       } );\r
+                                               }\r
+\r
+                                               // Prevent the browser opening links in read-only blocks. (#6032)\r
+                                               domDocument.on( 'click', function( ev )\r
+                                                       {\r
+                                                               ev = ev.data;\r
+                                                               if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )\r
+                                                                       ev.preventDefault();\r
+                                                       });\r
+\r
                                                // Webkit: avoid from editing form control elements content.\r
                                                if ( CKEDITOR.env.webkit )\r
                                                {\r
@@ -411,41 +562,41 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        } );\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
-                                                               }\r
+                                                               if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
+                                                                       blinkCursor();\r
+                                                               else if ( CKEDITOR.env.opera )\r
+                                                                       doc.getBody().focus();\r
 \r
                                                                editor.focusManager.focus();\r
                                                        });\r
@@ -454,29 +605,61 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                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
@@ -501,6 +684,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        editor.fire( 'dataReady' );\r
                                                                }, 0 );\r
 \r
+                                                               // IE, Opera and Safari may not support it and throw errors.\r
+                                                               try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {}\r
+                                                               try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}\r
+\r
                                                                /*\r
                                                                 * IE BUG: IE might have rendered the iframe with invisible contents.\r
                                                                 * (#3623). Push some inconsequential CSS style changes to force IE to\r
@@ -523,7 +710,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                }\r
                                                        },\r
                                                        0 );\r
-                                       };\r
+                                       }\r
 \r
                                        editor.addMode( 'wysiwyg',\r
                                                {\r
@@ -550,54 +737,113 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\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
@@ -611,8 +857,31 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                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
+                                                               * IE BUG: When destroying editor DOM with the selection remains inside\r
+                                                               * editing area would break IE7/8's selection system, we have to put the editing\r
+                                                               * iframe offline first. (#3812 and #5441)\r
+                                                               */\r
+                                                               iframe.remove();\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
@@ -622,9 +891,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                if ( isLoadingData )\r
                                                                        isPendingFocus = true;\r
-                                                               else if ( editor.window )\r
+                                                               // Temporary solution caused by #6025, supposed be unified by #6154.\r
+                                                               else if ( CKEDITOR.env.opera && editor.document )\r
+                                                               {\r
+                                                                       editor.document.getBody().focus();\r
+\r
+                                                                       editor.selectionChange();\r
+                                                               }\r
+                                                               else if ( !CKEDITOR.env.opera && editor.window )\r
                                                                {\r
                                                                        editor.window.focus();\r
+\r
                                                                        editor.selectionChange();\r
                                                                }\r
                                                        }\r
@@ -635,8 +912,128 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        // 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
+                                       if ( !element.isReadOnly() )\r
+                                       {\r
+                                               element.setAttribute( 'contentEditable', false );\r
+                                               // We should flag that the element was locked by our code so\r
+                                               // it'll be editable by the editor functions (#6046).\r
+                                               element.setCustomData( '_cke_notReadOnly', 1 );\r
+                                       }\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
@@ -685,3 +1082,9 @@ CKEDITOR.config.disableNativeSpellChecker = true;
  * 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