fckpanel.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:8k
源码类别:

OA系统

开发平台:

C#

  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: fckpanel.js
  14.  *  Component that creates floating panels. It is used by many 
  15.  *  other components, like the toolbar items, context menu, etc...
  16.  * 
  17.  * File Authors:
  18.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  19.  */
  20. var FCKPanel = function( parentWindow )
  21. {
  22. this.IsRTL = ( FCKLang.Dir == 'rtl' ) ;
  23. this.IsContextMenu = false ;
  24. this._LockCounter = 0 ;
  25. this._Window = parentWindow || window ;
  26. var oDocument ;
  27. if ( FCKBrowserInfo.IsIE )
  28. {
  29. // Create the Popup that will hold the panel.
  30. this._Popup = this._Window.createPopup() ;
  31. oDocument = this.Document = this._Popup.document ;
  32. }
  33. else
  34. {
  35. var oIFrame = this._IFrame = this._Window.document.createElement('iframe') ; 
  36. oIFrame.src = 'javascript:void(0)' ;
  37. oIFrame.allowTransparency = true ;
  38. oIFrame.frameBorder = '0' ;
  39. oIFrame.scrolling = 'no' ;
  40. oIFrame.style.position = 'absolute';
  41. oIFrame.style.zIndex = FCKConfig.FloatingPanelsZIndex ;
  42. oIFrame.width = oIFrame.height = 0 ;
  43. if ( this._Window == window.parent && window.frameElement )
  44. window.frameElement.parentNode.insertBefore( oIFrame, window.frameElement ) ;
  45. else
  46. this._Window.document.body.appendChild( oIFrame ) ;
  47. var oIFrameWindow = oIFrame.contentWindow ; 
  48. oDocument = this.Document = oIFrameWindow.document ;
  49. // Initialize the IFRAME document body.
  50. oDocument.open() ;
  51. oDocument.write( '<html><head></head><body style="margin:0px;padding:0px;"></body></html>' ) ;
  52. oDocument.close() ;
  53. FCKTools.AddEventListenerEx( oIFrameWindow, 'focus', FCKPanel_Window_OnFocus, this ) ;
  54. FCKTools.AddEventListenerEx( oIFrameWindow, 'blur', FCKPanel_Window_OnBlur, this ) ;
  55. }
  56. oDocument.dir = FCKLang.Dir ;
  57. oDocument.oncontextmenu = FCKTools.CancelEvent ;
  58. // Create the main DIV that is used as the panel base.
  59. this.MainNode = oDocument.body.appendChild( oDocument.createElement('DIV') ) ;
  60. // The "float" property must be set so Firefox calculates the size correcly.
  61. this.MainNode.style.cssFloat = this.IsRTL ? 'right' : 'left' ;
  62. if ( FCK.IECleanup )
  63. FCK.IECleanup.AddItem( this, FCKPanel_Cleanup ) ;
  64. }
  65. FCKPanel.prototype.AppendStyleSheet = function( styleSheet )
  66. {
  67. FCKTools.AppendStyleSheet( this.Document, styleSheet ) ;
  68. }
  69. FCKPanel.prototype.Preload = function( x, y, relElement )
  70. {
  71. // The offsetWidth and offsetHeight properties are not available if the 
  72. // element is not visible. So we must "show" the popup with no size to
  73. // be able to use that values in the second call (IE only).
  74. if ( this._Popup )
  75. this._Popup.show( x, y, 0, 0, relElement ) ;
  76. }
  77. FCKPanel.prototype.Show = function( x, y, relElement, width, height )
  78. {
  79. if ( this._Popup )
  80. {
  81. // The offsetWidth and offsetHeight properties are not available if the 
  82. // element is not visible. So we must "show" the popup with no size to
  83. // be able to use that values in the second call.
  84. this._Popup.show( x, y, 0, 0, relElement ) ;
  85. // The following lines must be place after the above "show", otherwise it 
  86. // doesn't has the desired effect.
  87. this.MainNode.style.width = width ? width + 'px' : '' ;
  88. this.MainNode.style.height = height ? height + 'px' : '' ;
  89. var iMainWidth = this.MainNode.offsetWidth ;
  90. if ( this.IsRTL )
  91. {
  92. if ( this.IsContextMenu )
  93. x  = x - iMainWidth + 1 ;
  94. else if ( relElement )
  95. x  = ( x * -1 ) + relElement.offsetWidth - iMainWidth ;
  96. }
  97. // Second call: Show the Popup at the specified location, with the correct size.
  98. this._Popup.show( x, y, iMainWidth, this.MainNode.offsetHeight, relElement ) ;
  99. if ( this.OnHide )
  100. {
  101. if ( this._Timer )
  102. CheckPopupOnHide.call( this, true ) ;
  103. this._Timer = FCKTools.SetInterval( CheckPopupOnHide, 100, this ) ;
  104. }
  105. }
  106. else
  107. {
  108. // Do not fire OnBlur while the panel is opened.
  109. if ( typeof( FCKFocusManager ) != 'undefined' )
  110. FCKFocusManager.Lock() ;
  111. if ( this.ParentPanel )
  112. this.ParentPanel.Lock() ;
  113. this.MainNode.style.width = width ? width + 'px' : '' ;
  114. this.MainNode.style.height = height ? height + 'px' : '' ;
  115. var iMainWidth = this.MainNode.offsetWidth ;
  116. if ( !width ) this._IFrame.width = 1 ;
  117. if ( !height ) this._IFrame.height = 1 ;
  118. // This is weird... but with Firefox, we must get the offsetWidth before
  119. // setting the _IFrame size (which returns "0"), and then after that,
  120. // to return the correct width. Remove the first step and it will not
  121. // work when the editor is in RTL.
  122. iMainWidth = this.MainNode.offsetWidth ;
  123. var oPos = FCKTools.GetElementPosition( ( relElement.nodeType == 9 ? relElement.body : relElement), this._Window ) ;
  124. if ( this.IsRTL && !this.IsContextMenu )
  125. x = ( x * -1 ) ;
  126. x += oPos.X ;
  127. y += oPos.Y ;
  128. if ( this.IsRTL )
  129. {
  130. if ( this.IsContextMenu )
  131. x  = x - iMainWidth + 1 ;
  132. else if ( relElement )
  133. x  = x + relElement.offsetWidth - iMainWidth ;
  134. }
  135. else
  136. {
  137. var oViewPaneSize = FCKTools.GetViewPaneSize( this._Window ) ;
  138. var oScrollPosition = FCKTools.GetScrollPosition( this._Window ) ;
  139. var iViewPaneHeight = oViewPaneSize.Height + oScrollPosition.Y ;
  140. var iViewPaneWidth = oViewPaneSize.Width + oScrollPosition.X ;
  141. if ( ( x + iMainWidth ) > iViewPaneWidth )
  142. x -= x + iMainWidth - iViewPaneWidth ;
  143. if ( ( y + this.MainNode.offsetHeight ) > iViewPaneHeight )
  144. y -= y + this.MainNode.offsetHeight - iViewPaneHeight ;
  145. }
  146. if ( x < 0 )
  147.  x = 0 ;
  148. // Set the context menu DIV in the specified location.
  149. this._IFrame.style.left = x + 'px' ;
  150. this._IFrame.style.top = y + 'px' ;
  151. var iWidth = iMainWidth ;
  152. var iHeight = this.MainNode.offsetHeight ;
  153. this._IFrame.width = iWidth ;
  154. this._IFrame.height = iHeight ;
  155. // Move the focus to the IFRAME so we catch the "onblur".
  156. this._IFrame.contentWindow.focus() ;
  157. }
  158. this._IsOpened = true ;
  159. FCKTools.RunFunction( this.OnShow, this ) ;
  160. }
  161. FCKPanel.prototype.Hide = function( ignoreOnHide )
  162. {
  163. if ( this._Popup )
  164. this._Popup.hide() ;
  165. else
  166. {
  167. if ( !this._IsOpened )
  168. return ;
  169. // Enable the editor to fire the "OnBlur".
  170. if ( typeof( FCKFocusManager ) != 'undefined' )
  171. FCKFocusManager.Unlock() ;
  172. // It is better to set the sizes to 0, otherwise Firefox would have 
  173. // rendering problems.
  174. this._IFrame.width = this._IFrame.height = 0 ;
  175. this._IsOpened = false ;
  176. if ( this.ParentPanel )
  177. this.ParentPanel.Unlock() ;
  178. if ( !ignoreOnHide )
  179. FCKTools.RunFunction( this.OnHide, this ) ;
  180. }
  181. }
  182. FCKPanel.prototype.CheckIsOpened = function()
  183. {
  184. if ( this._Popup )
  185. return this._Popup.isOpen ;
  186. else
  187. return this._IsOpened ;
  188. }
  189. FCKPanel.prototype.CreateChildPanel = function()
  190. {
  191. var oWindow = this._Popup ? FCKTools.GetParentWindow( this.Document ) : this._Window ;
  192. var oChildPanel = new FCKPanel( oWindow, true ) ;
  193. oChildPanel.ParentPanel = this ;
  194. return oChildPanel ;
  195. }
  196. FCKPanel.prototype.Lock = function()
  197. {
  198. this._LockCounter++ ;
  199. }
  200. FCKPanel.prototype.Unlock = function()
  201. {
  202. if ( --this._LockCounter == 0 && !this.HasFocus )
  203. this.Hide() ;
  204. }
  205. /* Events */
  206. function FCKPanel_Window_OnFocus( e, panel )
  207. {
  208. panel.HasFocus = true ;
  209. }
  210. function FCKPanel_Window_OnBlur( e, panel )
  211. {
  212. panel.HasFocus = false ;
  213. if ( panel._LockCounter == 0 )
  214. FCKTools.RunFunction( panel.Hide, panel ) ;
  215. }
  216. function CheckPopupOnHide( forceHide )
  217. {
  218. if ( forceHide || !this._Popup.isOpen )
  219. {
  220. window.clearInterval( this._Timer ) ;
  221. this._Timer = null ;
  222. FCKTools.RunFunction( this.OnHide, this ) ;
  223. }
  224. }
  225. function FCKPanel_Cleanup()
  226. {
  227. this._Popup = null ;
  228. this._Window = null ;
  229. this.Document = null ;
  230. this.MainNode = null ;
  231. }