JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2.1
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index c256646..dc8329d 100644 (file)
@@ -161,6 +161,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                           && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );\r
        }\r
 \r
+       function restoreSelection( selection )\r
+       {\r
+               if ( selection.isLocked )\r
+               {\r
+                       selection.unlock();\r
+                       setTimeout( function() { selection.lock(); }, 0 );\r
+               }\r
+       }\r
+\r
        /**\r
         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
         *  non-exitable-block by padding extra br.(#3189)\r
@@ -183,6 +192,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                         && !path.block )\r
                {\r
                        restoreDirty( editor );\r
+                       CKEDITOR.env.ie && restoreSelection( selection );\r
+\r
                        var fixedBlock = range.fixBlock( true,\r
                                        editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
 \r
@@ -200,7 +211,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                var previousElement = fixedBlock.getPrevious( isNotWhitespace ),\r
                                        nextElement = fixedBlock.getNext( isNotWhitespace );\r
 \r
-\r
                                if ( previousElement && previousElement.getName\r
                                         && !( previousElement.getName() in nonExitableElementNames )\r
                                         && range.moveToElementEditStart( previousElement )\r
@@ -221,14 +231,31 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                // 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 lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
-               if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )\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
                        restoreDirty( editor );\r
-                       if ( !CKEDITOR.env.ie )\r
-                               body.appendBogus();\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
-                               body.append( editor.document.createText( '\xa0' ) );\r
+                               paddingBlock = body;\r
+\r
+                       if ( !CKEDITOR.env.ie )\r
+                               paddingBlock.appendBogus();\r
                }\r
        }\r
 \r
@@ -277,19 +304,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        // call document.open().\r
                                                        ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) +\r
 \r
-                                                       // With FF, it's better to load the data on\r
-                                                       // iframe.load. (#3894,#4058)\r
-                                                       // But in FF, we still need the open()-close() call\r
-                                                       // to avoid HTTPS warnings.\r
-                                                       ( CKEDITOR.env.gecko ? '' : ( 'parent.CKEDITOR.tools.callFunction(' + setDataFn + ',document);' ) ) +\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
-                                                       ' src="javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())"' +\r
-                                                       ' tabIndex="' + editor.tabIndex + '"' +\r
+                                                       ' title="' + frameLabel + '"' +\r
+                                                       // With FF, 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
                                                        ' allowTransparency="true"' +\r
                                                        '></iframe>' );\r
 \r
@@ -425,6 +451,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                && ( '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
@@ -651,6 +678,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                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
                                                                createIFrame( data );\r
                                                        },\r
 \r
@@ -688,8 +718,24 @@ 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
                                                        unload : function( holderElement )\r
                                                        {\r
+                                                               this.onDispose();\r
+\r
                                                                editor.window = editor.document = iframe = mainElement = isPendingFocus = null;\r
 \r
                                                                editor.fire( 'contentDomUnload' );\r
@@ -702,25 +748,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                else if ( editor.window )\r
                                                                {\r
                                                                        editor.window.focus();\r
-\r
-                                                                       // Force the selection to happen, in this way\r
-                                                                       // we guarantee the focus will be there. (#4848)\r
-                                                                       if ( CKEDITOR.env.ie )\r
-                                                                       {\r
-                                                                               try\r
-                                                                               {\r
-                                                                                       var sel = editor.getSelection();\r
-                                                                                       sel = sel && sel.getNative();\r
-                                                                                       var range = sel && sel.type && sel.createRange();\r
-                                                                                       if ( range )\r
-                                                                                       {\r
-                                                                                                       sel.empty();\r
-                                                                                                       range.select();\r
-                                                                                       }\r
-                                                                               }\r
-                                                                               catch (e) {}\r
-                                                                       }\r
-\r
                                                                        editor.selectionChange();\r
                                                                }\r
                                                        }\r
@@ -758,6 +785,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        editor.focus();\r
                                                } );\r
                                } );\r
+                               editor.on( 'destroy', function()\r
+                               {\r
+                                       ieFocusGrabber.clearCustomData();\r
+                               } );\r
                        }\r
                }\r
        });\r