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