[1349] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * == BEGIN LICENSE == |
---|
| 6 | * |
---|
| 7 | * Licensed under the terms of any of the following licenses at your |
---|
| 8 | * choice: |
---|
| 9 | * |
---|
| 10 | * - GNU General Public License Version 2 or later (the "GPL") |
---|
| 11 | * http://www.gnu.org/licenses/gpl.html |
---|
| 12 | * |
---|
| 13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
| 14 | * http://www.gnu.org/licenses/lgpl.html |
---|
| 15 | * |
---|
| 16 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
| 17 | * http://www.mozilla.org/MPL/MPL-1.1.html |
---|
| 18 | * |
---|
| 19 | * == END LICENSE == |
---|
| 20 | * |
---|
| 21 | * Stretch the editor to full window size and back. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | var FCKFitWindow = function() |
---|
| 25 | { |
---|
| 26 | this.Name = 'FitWindow' ; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | FCKFitWindow.prototype.Execute = function() |
---|
| 30 | { |
---|
| 31 | var eEditorFrame = window.frameElement ; |
---|
| 32 | var eEditorFrameStyle = eEditorFrame.style ; |
---|
| 33 | |
---|
| 34 | var eMainWindow = parent ; |
---|
| 35 | var eDocEl = eMainWindow.document.documentElement ; |
---|
| 36 | var eBody = eMainWindow.document.body ; |
---|
| 37 | var eBodyStyle = eBody.style ; |
---|
| 38 | var eParent ; |
---|
| 39 | |
---|
| 40 | // No original style properties known? Go fullscreen. |
---|
| 41 | if ( !this.IsMaximized ) |
---|
| 42 | { |
---|
| 43 | // Registering an event handler when the window gets resized. |
---|
| 44 | if( FCKBrowserInfo.IsIE ) |
---|
| 45 | eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ; |
---|
| 46 | else |
---|
| 47 | eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ; |
---|
| 48 | |
---|
| 49 | // Save the scrollbars position. |
---|
| 50 | this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ; |
---|
| 51 | |
---|
| 52 | // Save and reset the styles for the entire node tree. They could interfere in the result. |
---|
| 53 | eParent = eEditorFrame ; |
---|
| 54 | // The extra () is to avoid a warning with strict error checking. This is ok. |
---|
| 55 | while( (eParent = eParent.parentNode) ) |
---|
| 56 | { |
---|
| 57 | if ( eParent.nodeType == 1 ) |
---|
| 58 | eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | // Hide IE scrollbars (in strict mode). |
---|
| 62 | if ( FCKBrowserInfo.IsIE ) |
---|
| 63 | { |
---|
| 64 | this.documentElementOverflow = eDocEl.style.overflow ; |
---|
| 65 | eDocEl.style.overflow = 'hidden' ; |
---|
| 66 | eBodyStyle.overflow = 'hidden' ; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | { |
---|
| 70 | // Hide the scroolbars in Firefox. |
---|
| 71 | eBodyStyle.overflow = 'hidden' ; |
---|
| 72 | eBodyStyle.width = '0px' ; |
---|
| 73 | eBodyStyle.height = '0px' ; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Save the IFRAME styles. |
---|
| 77 | this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ; |
---|
| 78 | |
---|
| 79 | // Resize. |
---|
| 80 | var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ; |
---|
| 81 | |
---|
| 82 | eEditorFrameStyle.position = "absolute"; |
---|
| 83 | eEditorFrameStyle.zIndex = FCKConfig.FloatingPanelsZIndex - 1; |
---|
| 84 | eEditorFrameStyle.left = "0px"; |
---|
| 85 | eEditorFrameStyle.top = "0px"; |
---|
| 86 | eEditorFrameStyle.width = oViewPaneSize.Width + "px"; |
---|
| 87 | eEditorFrameStyle.height = oViewPaneSize.Height + "px"; |
---|
| 88 | |
---|
| 89 | // Giving the frame some (huge) borders on his right and bottom |
---|
| 90 | // side to hide the background that would otherwise show when the |
---|
| 91 | // editor is in fullsize mode and the window is increased in size |
---|
| 92 | // not for IE, because IE immediately adapts the editor on resize, |
---|
| 93 | // without showing any of the background oddly in firefox, the |
---|
| 94 | // editor seems not to fill the whole frame, so just setting the |
---|
| 95 | // background of it to white to cover the page laying behind it anyway. |
---|
| 96 | if ( !FCKBrowserInfo.IsIE ) |
---|
| 97 | { |
---|
| 98 | eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ; |
---|
| 99 | eEditorFrameStyle.backgroundColor = "white"; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // Scroll to top left. |
---|
| 103 | eMainWindow.scrollTo(0, 0); |
---|
| 104 | |
---|
| 105 | this.IsMaximized = true ; |
---|
| 106 | } |
---|
| 107 | else // Resize to original size. |
---|
| 108 | { |
---|
| 109 | // Remove the event handler of window resizing. |
---|
| 110 | if( FCKBrowserInfo.IsIE ) |
---|
| 111 | eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ; |
---|
| 112 | else |
---|
| 113 | eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ; |
---|
| 114 | |
---|
| 115 | // Restore the CSS position for the entire node tree. |
---|
| 116 | eParent = eEditorFrame ; |
---|
| 117 | // The extra () is to avoid a warning with strict error checking. This is ok. |
---|
| 118 | while( (eParent = eParent.parentNode) ) |
---|
| 119 | { |
---|
| 120 | if ( eParent._fckSavedStyles ) |
---|
| 121 | { |
---|
| 122 | FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ; |
---|
| 123 | eParent._fckSavedStyles = null ; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | // Restore IE scrollbars |
---|
| 128 | if ( FCKBrowserInfo.IsIE ) |
---|
| 129 | eDocEl.style.overflow = this.documentElementOverflow ; |
---|
| 130 | |
---|
| 131 | // Restore original size |
---|
| 132 | FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ; |
---|
| 133 | |
---|
| 134 | // Restore the window scroll position. |
---|
| 135 | eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ; |
---|
| 136 | |
---|
| 137 | this.IsMaximized = false ; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | FCKToolbarItems.GetItem('FitWindow').RefreshState() ; |
---|
| 141 | |
---|
| 142 | // It seams that Firefox restarts the editing area when making this changes. |
---|
| 143 | // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special |
---|
| 144 | //configuration, like DisableFFTableHandles and DisableObjectResizing get |
---|
| 145 | //lost, so we must reset it. Also, the cursor position and selection are |
---|
| 146 | //also lost, even if you comment the following line (MakeEditable). |
---|
| 147 | // if ( FCKBrowserInfo.IsGecko10 ) // Initially I thought it was a FF 1.0 only problem. |
---|
| 148 | FCK.EditingArea.MakeEditable() ; |
---|
| 149 | |
---|
| 150 | FCK.Focus() ; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | FCKFitWindow.prototype.GetState = function() |
---|
| 154 | { |
---|
| 155 | if ( FCKConfig.ToolbarLocation != 'In' ) |
---|
| 156 | return FCK_TRISTATE_DISABLED ; |
---|
| 157 | else |
---|
| 158 | return ( this.IsMaximized ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | function FCKFitWindow_Resize() |
---|
| 162 | { |
---|
| 163 | var oViewPaneSize = FCKTools.GetViewPaneSize( parent ) ; |
---|
| 164 | |
---|
| 165 | var eEditorFrameStyle = window.frameElement.style ; |
---|
| 166 | |
---|
| 167 | eEditorFrameStyle.width = oViewPaneSize.Width + 'px' ; |
---|
| 168 | eEditorFrameStyle.height = oViewPaneSize.Height + 'px' ; |
---|
| 169 | } |
---|