--- /dev/null
+/*\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
+ * Component that creates floating panels. It is used by many\r
+ * other components, like the toolbar items, context menu, etc...\r
+ */\r
+\r
+var FCKPanel = function( parentWindow )\r
+{\r
+ this.IsRTL = ( FCKLang.Dir == 'rtl' ) ;\r
+ this.IsContextMenu = false ;\r
+ this._LockCounter = 0 ;\r
+\r
+ this._Window = parentWindow || window ;\r
+\r
+ var oDocument ;\r
+\r
+ if ( FCKBrowserInfo.IsIE )\r
+ {\r
+ // Create the Popup that will hold the panel.\r
+ // The popup has to be created before playing with domain hacks, see #1666.\r
+ this._Popup = this._Window.createPopup() ;\r
+\r
+ // this._Window cannot be accessed while playing with domain hacks, but local variable is ok.\r
+ // See #1666.\r
+ var pDoc = this._Window.document ;\r
+\r
+ // This is a trick to IE6 (not IE7). The original domain must be set\r
+ // before creating the popup, so we are able to take a refence to the\r
+ // document inside of it, and the set the proper domain for it. (#123)\r
+ if ( FCK_IS_CUSTOM_DOMAIN && !FCKBrowserInfo.IsIE7 )\r
+ {\r
+ pDoc.domain = FCK_ORIGINAL_DOMAIN ;\r
+ document.domain = FCK_ORIGINAL_DOMAIN ;\r
+ }\r
+\r
+ oDocument = this.Document = this._Popup.document ;\r
+\r
+ // Set the proper domain inside the popup.\r
+ if ( FCK_IS_CUSTOM_DOMAIN )\r
+ {\r
+ oDocument.domain = FCK_RUNTIME_DOMAIN ;\r
+ pDoc.domain = FCK_RUNTIME_DOMAIN ;\r
+ document.domain = FCK_RUNTIME_DOMAIN ;\r
+ }\r
+\r
+ FCK.IECleanup.AddItem( this, FCKPanel_Cleanup ) ;\r
+ }\r
+ else\r
+ {\r
+ var oIFrame = this._IFrame = this._Window.document.createElement('iframe') ;\r
+ FCKTools.ResetStyles( oIFrame );\r
+ oIFrame.src = 'javascript:void(0)' ;\r
+ oIFrame.allowTransparency = true ;\r
+ oIFrame.frameBorder = '0' ;\r
+ oIFrame.scrolling = 'no' ;\r
+ oIFrame.style.width = oIFrame.style.height = '0px' ;\r
+ FCKDomTools.SetElementStyles( oIFrame,\r
+ {\r
+ position : 'absolute',\r
+ zIndex : FCKConfig.FloatingPanelsZIndex\r
+ } ) ;\r
+\r
+ this._Window.document.body.appendChild( oIFrame ) ;\r
+\r
+ var oIFrameWindow = oIFrame.contentWindow ;\r
+\r
+ oDocument = this.Document = oIFrameWindow.document ;\r
+\r
+ // Workaround for Safari 12256. Ticket #63\r
+ var sBase = '' ;\r
+ if ( FCKBrowserInfo.IsSafari )\r
+ sBase = '<base href="' + window.document.location + '">' ;\r
+\r
+ // Initialize the IFRAME document body.\r
+ oDocument.open() ;\r
+ oDocument.write( '<html><head>' + sBase + '<\/head><body style="margin:0px;padding:0px;"><\/body><\/html>' ) ;\r
+ oDocument.close() ;\r
+\r
+ if( FCKBrowserInfo.IsAIR )\r
+ FCKAdobeAIR.Panel_Contructor( oDocument, window.document.location ) ;\r
+\r
+ FCKTools.AddEventListenerEx( oIFrameWindow, 'focus', FCKPanel_Window_OnFocus, this ) ;\r
+ FCKTools.AddEventListenerEx( oIFrameWindow, 'blur', FCKPanel_Window_OnBlur, this ) ;\r
+ }\r
+\r
+ oDocument.dir = FCKLang.Dir ;\r
+\r
+ FCKTools.AddEventListener( oDocument, 'contextmenu', FCKTools.CancelEvent ) ;\r
+\r
+\r
+ // Create the main DIV that is used as the panel base.\r
+ this.MainNode = oDocument.body.appendChild( oDocument.createElement('DIV') ) ;\r
+\r
+ // The "float" property must be set so Firefox calculates the size correctly.\r
+ this.MainNode.style.cssFloat = this.IsRTL ? 'right' : 'left' ;\r
+}\r
+\r
+\r
+FCKPanel.prototype.AppendStyleSheet = function( styleSheet )\r
+{\r
+ FCKTools.AppendStyleSheet( this.Document, styleSheet ) ;\r
+}\r
+\r
+FCKPanel.prototype.Preload = function( x, y, relElement )\r
+{\r
+ // The offsetWidth and offsetHeight properties are not available if the\r
+ // element is not visible. So we must "show" the popup with no size to\r
+ // be able to use that values in the second call (IE only).\r
+ if ( this._Popup )\r
+ this._Popup.show( x, y, 0, 0, relElement ) ;\r
+}\r
+\r
+// Workaround for IE7 problem. See #1982\r
+// Submenus are restricted to the size of its parent, so we increase it as needed.\r
+// Returns true if the panel has been repositioned\r
+FCKPanel.prototype.ResizeForSubpanel = function( panel, width, height )\r
+{\r
+ if ( !FCKBrowserInfo.IsIE7 )\r
+ return false ;\r
+\r
+ if ( !this._Popup.isOpen )\r
+ {\r
+ this.Subpanel = null ;\r
+ return false ;\r
+ }\r
+\r
+ // If we are resetting the extra space\r
+ if ( width == 0 && height == 0 )\r
+ {\r
+ // Another subpanel is being shown, so we must not shrink back\r
+ if (this.Subpanel !== panel)\r
+ return false ;\r
+\r
+ // Reset values.\r
+ // We leave the IncreasedY untouched to avoid vertical movement of the\r
+ // menu if the submenu is higher than the main menu.\r
+ this.Subpanel = null ;\r
+ this.IncreasedX = 0 ;\r
+ }\r
+ else\r
+ {\r
+ this.Subpanel = panel ;\r
+ // If the panel has already been increased enough, get out\r
+ if ( ( this.IncreasedX >= width ) && ( this.IncreasedY >= height ) )\r
+ return false ;\r
+\r
+ this.IncreasedX = Math.max( this.IncreasedX, width ) ;\r
+ this.IncreasedY = Math.max( this.IncreasedY, height ) ;\r
+ }\r
+\r
+ var x = this.ShowRect.x ;\r
+ var w = this.IncreasedX ;\r
+ if ( this.IsRTL )\r
+ x = x - w ;\r
+\r
+ // Horizontally increase as needed (sum of widths).\r
+ // Vertically, use only the maximum of this menu or the submenu\r
+ var finalWidth = this.ShowRect.w + w ;\r
+ var finalHeight = Math.max( this.ShowRect.h, this.IncreasedY ) ;\r
+ if ( this.ParentPanel )\r
+ this.ParentPanel.ResizeForSubpanel( this, finalWidth, finalHeight ) ;\r
+ this._Popup.show( x, this.ShowRect.y, finalWidth, finalHeight, this.RelativeElement ) ;\r
+\r
+ return this.IsRTL ;\r
+}\r
+\r
+FCKPanel.prototype.Show = function( x, y, relElement, width, height )\r
+{\r
+ var iMainWidth ;\r
+ var eMainNode = this.MainNode ;\r
+\r
+ if ( this._Popup )\r
+ {\r
+ // The offsetWidth and offsetHeight properties are not available if the\r
+ // element is not visible. So we must "show" the popup with no size to\r
+ // be able to use that values in the second call.\r
+ this._Popup.show( x, y, 0, 0, relElement ) ;\r
+\r
+ // The following lines must be place after the above "show", otherwise it\r
+ // doesn't has the desired effect.\r
+ FCKDomTools.SetElementStyles( eMainNode,\r
+ {\r
+ width : width ? width + 'px' : '',\r
+ height : height ? height + 'px' : ''\r
+ } ) ;\r
+\r
+ iMainWidth = eMainNode.offsetWidth ;\r
+\r
+ if ( FCKBrowserInfo.IsIE7 )\r
+ {\r
+ if (this.ParentPanel && this.ParentPanel.ResizeForSubpanel(this, iMainWidth, eMainNode.offsetHeight) )\r
+ {\r
+ // As the parent has moved, allow the browser to update its internal data, so the new position is correct.\r
+ FCKTools.RunFunction( this.Show, this, [x, y, relElement] ) ;\r
+ return ;\r
+ }\r
+ }\r
+\r
+ if ( this.IsRTL )\r
+ {\r
+ if ( this.IsContextMenu )\r
+ x = x - iMainWidth + 1 ;\r
+ else if ( relElement )\r
+ x = ( x * -1 ) + relElement.offsetWidth - iMainWidth ;\r
+ }\r
+\r
+ if ( FCKBrowserInfo.IsIE7 )\r
+ {\r
+ // Store the values that will be used by the ResizeForSubpanel function\r
+ this.ShowRect = {x:x, y:y, w:iMainWidth, h:eMainNode.offsetHeight} ;\r
+ this.IncreasedX = 0 ;\r
+ this.IncreasedY = 0 ;\r
+ this.RelativeElement = relElement ;\r
+ }\r
+\r
+ // Second call: Show the Popup at the specified location, with the correct size.\r
+ this._Popup.show( x, y, iMainWidth, eMainNode.offsetHeight, relElement ) ;\r
+\r
+ if ( this.OnHide )\r
+ {\r
+ if ( this._Timer )\r
+ CheckPopupOnHide.call( this, true ) ;\r
+\r
+ this._Timer = FCKTools.SetInterval( CheckPopupOnHide, 100, this ) ;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // Do not fire OnBlur while the panel is opened.\r
+ if ( typeof( FCK.ToolbarSet.CurrentInstance.FocusManager ) != 'undefined' )\r
+ FCK.ToolbarSet.CurrentInstance.FocusManager.Lock() ;\r
+\r
+ if ( this.ParentPanel )\r
+ {\r
+ this.ParentPanel.Lock() ;\r
+\r
+ // Due to a bug on FF3, we must ensure that the parent panel will\r
+ // blur (#1584).\r
+ FCKPanel_Window_OnBlur( null, this.ParentPanel ) ;\r
+ }\r
+\r
+ // Toggle the iframe scrolling attribute to prevent the panel\r
+ // scrollbars from disappearing in FF Mac. (#191)\r
+ if ( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsMac )\r
+ {\r
+ this._IFrame.scrolling = '' ;\r
+ FCKTools.RunFunction( function(){ this._IFrame.scrolling = 'no'; }, this ) ;\r
+ }\r
+\r
+ // Be sure we'll not have more than one Panel opened at the same time.\r
+ // Do not unlock focus manager here because we're displaying another floating panel\r
+ // instead of returning the editor to a "no panel" state (Bug #1514).\r
+ if ( FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel &&\r
+ FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel != this )\r
+ FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel.Hide( false, true ) ;\r
+\r
+ FCKDomTools.SetElementStyles( eMainNode,\r
+ {\r
+ width : width ? width + 'px' : '',\r
+ height : height ? height + 'px' : ''\r
+ } ) ;\r
+\r
+ iMainWidth = eMainNode.offsetWidth ;\r
+\r
+ if ( !width ) this._IFrame.width = 1 ;\r
+ if ( !height ) this._IFrame.height = 1 ;\r
+\r
+ // This is weird... but with Firefox, we must get the offsetWidth before\r
+ // setting the _IFrame size (which returns "0"), and then after that,\r
+ // to return the correct width. Remove the first step and it will not\r
+ // work when the editor is in RTL.\r
+ //\r
+ // The "|| eMainNode.firstChild.offsetWidth" part has been added\r
+ // for Opera compatibility (see #570).\r
+ iMainWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;\r
+\r
+ // Base the popup coordinates upon the coordinates of relElement.\r
+ var oPos = FCKTools.GetDocumentPosition( this._Window,\r
+ relElement.nodeType == 9 ?\r
+ ( FCKTools.IsStrictMode( relElement ) ? relElement.documentElement : relElement.body ) :\r
+ relElement ) ;\r
+\r
+ // Minus the offsets provided by any positioned parent element of the panel iframe.\r
+ var positionedAncestor = FCKDomTools.GetPositionedAncestor( this._IFrame.parentNode ) ;\r
+ if ( positionedAncestor )\r
+ {\r
+ var nPos = FCKTools.GetDocumentPosition( FCKTools.GetElementWindow( positionedAncestor ), positionedAncestor ) ;\r
+ oPos.x -= nPos.x ;\r
+ oPos.y -= nPos.y ;\r
+ }\r
+\r
+ if ( this.IsRTL && !this.IsContextMenu )\r
+ x = ( x * -1 ) ;\r
+\r
+ x += oPos.x ;\r
+ y += oPos.y ;\r
+\r
+ if ( this.IsRTL )\r
+ {\r
+ if ( this.IsContextMenu )\r
+ x = x - iMainWidth + 1 ;\r
+ else if ( relElement )\r
+ x = x + relElement.offsetWidth - iMainWidth ;\r
+ }\r
+ else\r
+ {\r
+ var oViewPaneSize = FCKTools.GetViewPaneSize( this._Window ) ;\r
+ var oScrollPosition = FCKTools.GetScrollPosition( this._Window ) ;\r
+\r
+ var iViewPaneHeight = oViewPaneSize.Height + oScrollPosition.Y ;\r
+ var iViewPaneWidth = oViewPaneSize.Width + oScrollPosition.X ;\r
+\r
+ if ( ( x + iMainWidth ) > iViewPaneWidth )\r
+ x -= x + iMainWidth - iViewPaneWidth ;\r
+\r
+ if ( ( y + eMainNode.offsetHeight ) > iViewPaneHeight )\r
+ y -= y + eMainNode.offsetHeight - iViewPaneHeight ;\r
+ }\r
+\r
+ // Set the context menu DIV in the specified location.\r
+ FCKDomTools.SetElementStyles( this._IFrame,\r
+ {\r
+ left : x + 'px',\r
+ top : y + 'px'\r
+ } ) ;\r
+\r
+ // Move the focus to the IFRAME so we catch the "onblur".\r
+ this._IFrame.contentWindow.focus() ;\r
+ this._IsOpened = true ;\r
+\r
+ var me = this ;\r
+ this._resizeTimer = setTimeout( function()\r
+ {\r
+ var iWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;\r
+ var iHeight = eMainNode.offsetHeight ;\r
+ me._IFrame.style.width = iWidth + 'px' ;\r
+ me._IFrame.style.height = iHeight + 'px' ;\r
+\r
+ }, 0 ) ;\r
+\r
+ FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel = this ;\r
+ }\r
+\r
+ FCKTools.RunFunction( this.OnShow, this ) ;\r
+}\r
+\r
+FCKPanel.prototype.Hide = function( ignoreOnHide, ignoreFocusManagerUnlock )\r
+{\r
+ if ( this._Popup )\r
+ this._Popup.hide() ;\r
+ else\r
+ {\r
+ if ( !this._IsOpened || this._LockCounter > 0 )\r
+ return ;\r
+\r
+ // Enable the editor to fire the "OnBlur".\r
+ if ( typeof( FCKFocusManager ) != 'undefined' && !ignoreFocusManagerUnlock )\r
+ FCKFocusManager.Unlock() ;\r
+\r
+ // It is better to set the sizes to 0, otherwise Firefox would have\r
+ // rendering problems.\r
+ this._IFrame.style.width = this._IFrame.style.height = '0px' ;\r
+\r
+ this._IsOpened = false ;\r
+\r
+ if ( this._resizeTimer )\r
+ {\r
+ clearTimeout( this._resizeTimer ) ;\r
+ this._resizeTimer = null ;\r
+ }\r
+\r
+ if ( this.ParentPanel )\r
+ this.ParentPanel.Unlock() ;\r
+\r
+ if ( !ignoreOnHide )\r
+ FCKTools.RunFunction( this.OnHide, this ) ;\r
+ }\r
+}\r
+\r
+FCKPanel.prototype.CheckIsOpened = function()\r
+{\r
+ if ( this._Popup )\r
+ return this._Popup.isOpen ;\r
+ else\r
+ return this._IsOpened ;\r
+}\r
+\r
+FCKPanel.prototype.CreateChildPanel = function()\r
+{\r
+ var oWindow = this._Popup ? FCKTools.GetDocumentWindow( this.Document ) : this._Window ;\r
+\r
+ var oChildPanel = new FCKPanel( oWindow ) ;\r
+ oChildPanel.ParentPanel = this ;\r
+\r
+ return oChildPanel ;\r
+}\r
+\r
+FCKPanel.prototype.Lock = function()\r
+{\r
+ this._LockCounter++ ;\r
+}\r
+\r
+FCKPanel.prototype.Unlock = function()\r
+{\r
+ if ( --this._LockCounter == 0 && !this.HasFocus )\r
+ this.Hide() ;\r
+}\r
+\r
+/* Events */\r
+\r
+function FCKPanel_Window_OnFocus( e, panel )\r
+{\r
+ panel.HasFocus = true ;\r
+}\r
+\r
+function FCKPanel_Window_OnBlur( e, panel )\r
+{\r
+ panel.HasFocus = false ;\r
+\r
+ if ( panel._LockCounter == 0 )\r
+ FCKTools.RunFunction( panel.Hide, panel ) ;\r
+}\r
+\r
+function CheckPopupOnHide( forceHide )\r
+{\r
+ if ( forceHide || !this._Popup.isOpen )\r
+ {\r
+ window.clearInterval( this._Timer ) ;\r
+ this._Timer = null ;\r
+\r
+ if (this._Popup && this.ParentPanel && !forceHide)\r
+ this.ParentPanel.ResizeForSubpanel(this, 0, 0) ;\r
+\r
+ FCKTools.RunFunction( this.OnHide, this ) ;\r
+ }\r
+}\r
+\r
+function FCKPanel_Cleanup()\r
+{\r
+ this._Popup = null ;\r
+ this._Window = null ;\r
+ this.Document = null ;\r
+ this.MainNode = null ;\r
+ this.RelativeElement = null ;\r
+}\r