import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / commandclasses / fckfitwindow.js
diff --git a/rt/share/html/NoAuth/RichText/FCKeditor/editor/_source/commandclasses/fckfitwindow.js b/rt/share/html/NoAuth/RichText/FCKeditor/editor/_source/commandclasses/fckfitwindow.js
new file mode 100644 (file)
index 0000000..c1b8f9a
--- /dev/null
@@ -0,0 +1,213 @@
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ *  - GNU General Public License Version 2 or later (the "GPL")\r
+ *    http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ *    http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ *    http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ * Stretch the editor to full window size and back.\r
+ */\r
+\r
+var FCKFitWindow = function()\r
+{\r
+       this.Name = 'FitWindow' ;\r
+}\r
+\r
+FCKFitWindow.prototype.Execute = function()\r
+{\r
+       var eEditorFrame                = window.frameElement ;\r
+       var eEditorFrameStyle   = eEditorFrame.style ;\r
+\r
+       var eMainWindow                 = parent ;\r
+       var eDocEl                              = eMainWindow.document.documentElement ;\r
+       var eBody                               = eMainWindow.document.body ;\r
+       var eBodyStyle                  = eBody.style ;\r
+       var eParent ;\r
+\r
+       // Save the current selection and scroll position.\r
+       var oRange, oEditorScrollPos ;\r
+       if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
+       {\r
+               oRange = new FCKDomRange( FCK.EditorWindow ) ;\r
+               oRange.MoveToSelection() ;\r
+               oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ;\r
+       }\r
+       else\r
+       {\r
+               var eTextarea = FCK.EditingArea.Textarea ;\r
+               oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ;\r
+               oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ;\r
+       }\r
+\r
+       // No original style properties known? Go fullscreen.\r
+       if ( !this.IsMaximized )\r
+       {\r
+               // Registering an event handler when the window gets resized.\r
+               if( FCKBrowserInfo.IsIE )\r
+                       eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ;\r
+               else\r
+                       eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ;\r
+\r
+               // Save the scrollbars position.\r
+               this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ;\r
+\r
+               // Save and reset the styles for the entire node tree. They could interfere in the result.\r
+               eParent = eEditorFrame ;\r
+               // The extra () is to avoid a warning with strict error checking. This is ok.\r
+               while( (eParent = eParent.parentNode) )\r
+               {\r
+                       if ( eParent.nodeType == 1 )\r
+                       {\r
+                               eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ;\r
+                               eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ;\r
+                       }\r
+               }\r
+\r
+               // Hide IE scrollbars (in strict mode).\r
+               if ( FCKBrowserInfo.IsIE )\r
+               {\r
+                       this.documentElementOverflow = eDocEl.style.overflow ;\r
+                       eDocEl.style.overflow   = 'hidden' ;\r
+                       eBodyStyle.overflow             = 'hidden' ;\r
+               }\r
+               else\r
+               {\r
+                       // Hide the scroolbars in Firefox.\r
+                       eBodyStyle.overflow = 'hidden' ;\r
+                       eBodyStyle.width = '0px' ;\r
+                       eBodyStyle.height = '0px' ;\r
+               }\r
+\r
+               // Save the IFRAME styles.\r
+               this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ;\r
+\r
+               // Resize.\r
+               var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ;\r
+\r
+               eEditorFrameStyle.position      = "absolute";\r
+               eEditorFrame.offsetLeft ;               // Kludge for Safari 3.1 browser bug, do not remove. See #2066.\r
+               eEditorFrameStyle.zIndex        = FCKConfig.FloatingPanelsZIndex - 1;\r
+               eEditorFrameStyle.left          = "0px";\r
+               eEditorFrameStyle.top           = "0px";\r
+               eEditorFrameStyle.width         = oViewPaneSize.Width + "px";\r
+               eEditorFrameStyle.height        = oViewPaneSize.Height + "px";\r
+\r
+               // Giving the frame some (huge) borders on his right and bottom\r
+               // side to hide the background that would otherwise show when the\r
+               // editor is in fullsize mode and the window is increased in size\r
+               // not for IE, because IE immediately adapts the editor on resize,\r
+               // without showing any of the background oddly in firefox, the\r
+               // editor seems not to fill the whole frame, so just setting the\r
+               // background of it to white to cover the page laying behind it anyway.\r
+               if ( !FCKBrowserInfo.IsIE )\r
+               {\r
+                       eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ;\r
+                       eEditorFrameStyle.backgroundColor               = "white";\r
+               }\r
+\r
+               // Scroll to top left.\r
+               eMainWindow.scrollTo(0, 0);\r
+\r
+               // Is the editor still not on the top left? Let's find out and fix that as well. (Bug #174)\r
+               var editorPos = FCKTools.GetWindowPosition( eMainWindow, eEditorFrame ) ;\r
+               if ( editorPos.x != 0 )\r
+                       eEditorFrameStyle.left = ( -1 * editorPos.x ) + "px" ;\r
+               if ( editorPos.y != 0 )\r
+                       eEditorFrameStyle.top = ( -1 * editorPos.y ) + "px" ;\r
+\r
+               this.IsMaximized = true ;\r
+       }\r
+       else    // Resize to original size.\r
+       {\r
+               // Remove the event handler of window resizing.\r
+               if( FCKBrowserInfo.IsIE )\r
+                       eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ;\r
+               else\r
+                       eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ;\r
+\r
+               // Restore the CSS position for the entire node tree.\r
+               eParent = eEditorFrame ;\r
+               // The extra () is to avoid a warning with strict error checking. This is ok.\r
+               while( (eParent = eParent.parentNode) )\r
+               {\r
+                       if ( eParent._fckSavedStyles )\r
+                       {\r
+                               FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ;\r
+                               eParent._fckSavedStyles = null ;\r
+                       }\r
+               }\r
+\r
+               // Restore IE scrollbars\r
+               if ( FCKBrowserInfo.IsIE )\r
+                       eDocEl.style.overflow = this.documentElementOverflow ;\r
+\r
+               // Restore original size\r
+               FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ;\r
+\r
+               // Restore the window scroll position.\r
+               eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ;\r
+\r
+               this.IsMaximized = false ;\r
+       }\r
+\r
+       FCKToolbarItems.GetItem('FitWindow').RefreshState() ;\r
+\r
+       // It seams that Firefox restarts the editing area when making this changes.\r
+       // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special\r
+       //configuration, like DisableFFTableHandles and DisableObjectResizing get\r
+       //lost, so we must reset it. Also, the cursor position and selection are\r
+       //also lost, even if you comment the following line (MakeEditable).\r
+       // if ( FCKBrowserInfo.IsGecko10 )      // Initially I thought it was a FF 1.0 only problem.\r
+       if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
+               FCK.EditingArea.MakeEditable() ;\r
+\r
+       FCK.Focus() ;\r
+\r
+       // Restore the selection and scroll position of inside the document.\r
+       if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
+       {\r
+               oRange.Select() ;\r
+               FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ;\r
+       }\r
+       else\r
+       {\r
+               if ( !FCKBrowserInfo.IsIE )\r
+               {\r
+                       eTextarea.selectionStart = oRange[0] ;\r
+                       eTextarea.selectionEnd = oRange[1] ;\r
+               }\r
+               eTextarea.scrollLeft = oEditorScrollPos[0] ;\r
+               eTextarea.scrollTop = oEditorScrollPos[1] ;\r
+       }\r
+}\r
+\r
+FCKFitWindow.prototype.GetState = function()\r
+{\r
+       if ( FCKConfig.ToolbarLocation != 'In' )\r
+               return FCK_TRISTATE_DISABLED ;\r
+       else\r
+               return ( this.IsMaximized ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF );\r
+}\r
+\r
+function FCKFitWindow_Resize()\r
+{\r
+       var oViewPaneSize = FCKTools.GetViewPaneSize( parent ) ;\r
+\r
+       var eEditorFrameStyle = window.frameElement.style ;\r
+\r
+       eEditorFrameStyle.width         = oViewPaneSize.Width + 'px' ;\r
+       eEditorFrameStyle.height        = oViewPaneSize.Height + 'px' ;\r
+}\r