JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2.2
[ckeditor.git] / _source / plugins / maximize / plugin.js
index 2b7ffe3..a5a06fc 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
@@ -78,13 +78,35 @@ 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
+               if ( editor.focusManager.hasFocus )\r
                {\r
-                       var viewPaneSize = mainWindow.getViewPaneSize();\r
-                       editor.resize( viewPaneSize.width, viewPaneSize.height, null, true );\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
@@ -102,8 +124,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // 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
@@ -111,16 +140,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        editor.addCommand( 'maximize',\r
                                {\r
                                        modes : { wysiwyg : 1, source : 1 },\r
-\r
+                                       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
                                                if ( editor.mode == 'wysiwyg' )\r
                                                {\r
-                                                       savedSelection = editor.getSelection().getRanges();\r
+                                                       var selection = editor.getSelection();\r
+                                                       savedSelection = selection && selection.getRanges();\r
                                                        savedScroll = mainWindow.getScrollPosition();\r
                                                }\r
                                                else\r
@@ -164,8 +194,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        } );\r
                                                        }\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
@@ -177,7 +209,9 @@ 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
+                                                       resizeHandler();\r
 \r
                                                        // Still not top left? Fix it. (Bug #174)\r
                                                        var offset = container.getDocumentPosition();\r
@@ -187,6 +221,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        top : ( -1 * offset.y ) + 'px'\r
                                                                } );\r
 \r
+                                                       // Fixing positioning editor chrome in Firefox break design mode. (#5149)\r
+                                                       CKEDITOR.env.gecko && refreshCursor( editor );\r
+\r
                                                        // Add cke_maximized class.\r
                                                        container.addClass( 'cke_maximized' );\r
                                                }\r
@@ -211,11 +248,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
@@ -223,14 +268,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                this.toggleState();\r
 \r
+                                               // Toggle button label.\r
+                                               var button = this.uiItems[ 0 ];\r
+                                               var label = ( this.state == CKEDITOR.TRISTATE_OFF )\r
+                                                       ? lang.maximize : lang.minimize;\r
+                                               var buttonNode = editor.element.getDocument().getById( button._.id );\r
+                                               buttonNode.getChild( 1 ).setHtml( label );\r
+                                               buttonNode.setAttribute( 'title', label );\r
+                                               buttonNode.setAttribute( 'href', 'javascript:void("' + label + '");' );\r
+\r
                                                // Restore selection and scroll position in editing area.\r
                                                if ( editor.mode == 'wysiwyg' )\r
                                                {\r
-                                                       editor.getSelection().selectRanges( savedSelection );\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
+                                                       }\r
 \r
-                                                       var element = editor.getSelection().getStartElement();\r
-                                                       if ( element )\r
-                                                               element.scrollIntoView( true );\r
                                                        else\r
                                                                mainWindow.$.scrollTo( savedScroll.x, savedScroll.y );\r
                                                }\r