JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / maximize / plugin.js
index 2b7ffe3..a3a260a 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
@@ -111,16 +111,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( 0 );\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 +165,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
@@ -211,7 +214,9 @@ 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
@@ -223,14 +228,25 @@ 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
+                                                               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