[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/fckeditor/editor/_source/classes/ -> fckpanel.js (source)

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


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics