JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / maximize / plugin.js
index 4c40544..fa2f791 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,8 +10,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                if ( !formElement || formElement.type != CKEDITOR.NODE_ELEMENT || formElement.getName() != 'form' )\r
                        return [];\r
 \r
-               var hijackRecord = [];\r
-               var hijackNames = [ 'style', 'className' ];\r
+               var hijackRecord = [],\r
+                       hijackNames = [ 'style', 'className' ];\r
                for ( var i = 0 ; i < hijackNames.length ; i++ )\r
                {\r
                        var name = hijackNames[i];\r
@@ -78,13 +78,50 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                restoreFormStyles( data );\r
        }\r
 \r
-       function getResizeHandler( mainWindow, editor )\r
+       function refreshCursor( editor )\r
        {\r
-               return function()\r
+               // Refresh all editor instances on the page (#5724).\r
+               var all = CKEDITOR.instances;\r
+               for ( var i in all )\r
                {\r
-                       var viewPaneSize = mainWindow.getViewPaneSize();\r
-                       editor.resize( viewPaneSize.width, viewPaneSize.height, null, true );\r
-               };\r
+                       var one = all[ i ];\r
+                       if ( one.mode == 'wysiwyg' )\r
+                       {\r
+                               var body = one.document.getBody();\r
+                               // Refresh 'contentEditable' otherwise\r
+                               // DOM lifting breaks design mode. (#5560)\r
+                               body.setAttribute( 'contentEditable', false );\r
+                               body.setAttribute( 'contentEditable', true );\r
+                       }\r
+               }\r
+\r
+               if ( editor.focusManager.hasFocus )\r
+               {\r
+                       editor.toolbox.focus();\r
+                       editor.focus();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Adding an iframe shim to this element, OR removing the existing one if already applied.\r
+        * Note: This will only affect IE version below 7.\r
+        */\r
+        function createIframeShim( element )\r
+       {\r
+               if ( !CKEDITOR.env.ie || CKEDITOR.env.version > 6 )\r
+                       return null;\r
+\r
+               var shim = CKEDITOR.dom.element.createFromHtml( '<iframe frameborder="0" tabindex="-1"' +\r
+                                       ' src="javascript:' +\r
+                                          'void((function(){' +\r
+                                                  'document.open();' +\r
+                                                  ( CKEDITOR.env.isCustomDomain() ? 'document.domain=\'' + this.getDocument().$.domain + '\';' : '' ) +\r
+                                                  'document.close();' +\r
+                                          '})())"' +\r
+                                       ' style="display:block;position:absolute;z-index:-1;' +\r
+                                       'progid:DXImageTransform.Microsoft.Alpha(opacity=0);' +\r
+                                       '"></iframe>' );\r
+               return element.append( shim, true );\r
        }\r
 \r
        CKEDITOR.plugins.add( 'maximize',\r
@@ -92,18 +129,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                init : function( editor )\r
                {\r
                        var lang = editor.lang;\r
-                       var mainDocument = CKEDITOR.document;\r
-                       var mainWindow = mainDocument.getWindow();\r
+                       var mainDocument = CKEDITOR.document,\r
+                               mainWindow = mainDocument.getWindow();\r
 \r
                        // Saved selection and scroll position for the editing area.\r
-                       var savedSelection;\r
-                       var savedScroll;\r
+                       var savedSelection,\r
+                               savedScroll;\r
 \r
                        // Saved scroll position for the outer window.\r
                        var outerScroll;\r
 \r
+                       var shim;\r
+\r
                        // Saved resize handler function.\r
-                       var resizeHandler = getResizeHandler( mainWindow, editor );\r
+                       function resizeHandler()\r
+                       {\r
+                               var viewPaneSize = mainWindow.getViewPaneSize();\r
+                               shim && shim.setStyles( { width : viewPaneSize.width + 'px', height : viewPaneSize.height + 'px' } );\r
+                               editor.resize( viewPaneSize.width, viewPaneSize.height, null, true );\r
+                       }\r
 \r
                        // Retain state after mode switches.\r
                        var savedState = CKEDITOR.TRISTATE_OFF;\r
@@ -114,7 +158,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        editorFocus : false,\r
                                        exec : function()\r
                                        {\r
-                                               var container = editor.container.getChild( [ 0, 0 ] );\r
+                                               var container = editor.container.getChild( 1 );\r
                                                var contents = editor.getThemeSpace( 'contents' );\r
 \r
                                                // Save current selection and scroll position in editing area.\r
@@ -150,26 +194,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        container.setCustomData( 'maximize_saved_styles', saveStyles( container, true ) );\r
 \r
                                                        // Hide scroll bars.\r
-                                                       if ( CKEDITOR.env.ie )\r
-                                                       {\r
-                                                               mainDocument.$.documentElement.style.overflow =\r
-                                                                       mainDocument.getBody().$.style.overflow = 'hidden';\r
-                                                       }\r
-                                                       else\r
-                                                       {\r
-                                                               mainDocument.getBody().setStyles(\r
-                                                                       {\r
-                                                                               overflow : 'hidden',\r
-                                                                               width : '0px',\r
-                                                                               height : '0px'\r
-                                                                       } );\r
-                                                       }\r
+                                                       var viewPaneSize = mainWindow.getViewPaneSize();\r
+                                                       var styles =\r
+                                                               {\r
+                                                                       overflow : 'hidden',\r
+                                                                       width : 0,\r
+                                                                       height : 0\r
+                                                               };\r
+\r
+                                                       mainDocument.getDocumentElement().setStyles( styles );\r
+                                                       !CKEDITOR.env.gecko && mainDocument.getDocumentElement().setStyle( 'position', 'fixed' );\r
+                                                       mainDocument.getBody().setStyles( styles );\r
 \r
-                                                       // Scroll to the top left.\r
-                                                       mainWindow.$.scrollTo( 0, 0 );\r
+                                                       // Scroll to the top left (IE needs some time for it - #4923).\r
+                                                       CKEDITOR.env.ie ?\r
+                                                               setTimeout( function() { mainWindow.$.scrollTo( 0, 0 ); }, 0 ) :\r
+                                                               mainWindow.$.scrollTo( 0, 0 );\r
 \r
                                                        // Resize and move to top left.\r
-                                                       var viewPaneSize = mainWindow.getViewPaneSize();\r
                                                        container.setStyle( 'position', 'absolute' );\r
                                                        container.$.offsetLeft;                 // SAFARI BUG: See #2066.\r
                                                        container.setStyles(\r
@@ -178,7 +220,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        left : '0px',\r
                                                                        top : '0px'\r
                                                                } );\r
-                                                       editor.resize( viewPaneSize.width, viewPaneSize.height, null, true );\r
+\r
+                                                       shim =  createIframeShim( container );          // IE6 select element penetration when maximized. (#4459)\r
+\r
+                                                       // Add cke_maximized class before resize handle since that will change things sizes (#5580)\r
+                                                       container.addClass( 'cke_maximized' );\r
+\r
+                                                       resizeHandler();\r
 \r
                                                        // Still not top left? Fix it. (Bug #174)\r
                                                        var offset = container.getDocumentPosition();\r
@@ -188,8 +236,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        top : ( -1 * offset.y ) + 'px'\r
                                                                } );\r
 \r
-                                                       // Add cke_maximized class.\r
-                                                       container.addClass( 'cke_maximized' );\r
+                                                       // Fixing positioning editor chrome in Firefox break design mode. (#5149)\r
+                                                       CKEDITOR.env.gecko && refreshCursor( editor );\r
+\r
                                                }\r
                                                else if ( this.state == CKEDITOR.TRISTATE_ON )  // Restore from fullscreen if the state is on.\r
                                                {\r
@@ -212,11 +261,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        }\r
 \r
                                                        // Restore the window scroll position.\r
-                                                       mainWindow.$.scrollTo( outerScroll.x, outerScroll.y );\r
+                                                       CKEDITOR.env.ie ?\r
+                                                               setTimeout( function() { mainWindow.$.scrollTo( outerScroll.x, outerScroll.y ); }, 0 ) :\r
+                                                               mainWindow.$.scrollTo( outerScroll.x, outerScroll.y );\r
 \r
                                                        // Remove cke_maximized class.\r
                                                        container.removeClass( 'cke_maximized' );\r
 \r
+                                                       if ( shim )\r
+                                                       {\r
+                                                               shim.remove();\r
+                                                               shim = null;\r
+                                                       }\r
+\r
                                                        // Emit a resize event, because this time the size is modified in\r
                                                        // restoreStyles.\r
                                                        editor.fire( 'resize' );\r
@@ -238,6 +295,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                {\r
                                                        if ( savedSelection )\r
                                                        {\r
+                                                               // Fixing positioning editor chrome in Firefox break design mode. (#5149)\r
+                                                               CKEDITOR.env.gecko && refreshCursor( editor );\r
+\r
                                                                editor.getSelection().selectRanges(savedSelection);\r
                                                                var element = editor.getSelection().getStartElement();\r
                                                                element && element.scrollIntoView( true );\r
@@ -269,10 +329,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        command : 'maximize'\r
                                } );\r
 \r
-                       // Restore the command state after mode change.\r
+                       // Restore the command state after mode change, unless it has been changed to disabled (#6467)\r
                        editor.on( 'mode', function()\r
                                {\r
-                                       editor.getCommand( 'maximize' ).setState( savedState );\r
+                                       var command = editor.getCommand( 'maximize' );\r
+                                       command.setState( command.state == CKEDITOR.TRISTATE_DISABLED ? CKEDITOR.TRISTATE_DISABLED : savedState );\r
                                }, null, null, 100 );\r
                }\r
        } );\r