[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/_source/internals/ -> fcktoolbarset.js (source)

   1  /*
   2   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4   * 
   5   * == BEGIN LICENSE ==
   6   * 
   7   * Licensed under the terms of any of the following licenses at your
   8   * choice:
   9   * 
  10   *  - GNU General Public License Version 2 or later (the "GPL")
  11   *    http://www.gnu.org/licenses/gpl.html
  12   * 
  13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14   *    http://www.gnu.org/licenses/lgpl.html
  15   * 
  16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  17   *    http://www.mozilla.org/MPL/MPL-1.1.html
  18   * 
  19   * == END LICENSE ==
  20   * 
  21   * File Name: fcktoolbarset.js
  22   *     Defines the FCKToolbarSet object that is used to load and draw the 
  23   *     toolbar.
  24   * 
  25   * File Authors:
  26   *         Frederico Caldeira Knabben (www.fckeditor.net)
  27   */
  28  
  29  function FCKToolbarSet_Create( overhideLocation )
  30  {
  31      var oToolbarSet ;
  32      
  33      var sLocation = overhideLocation || FCKConfig.ToolbarLocation ;
  34      switch ( sLocation )
  35      {
  36          case 'In' :
  37                  document.getElementById( 'xToolbarRow' ).style.display = '' ;
  38                  oToolbarSet = new FCKToolbarSet( document ) ;
  39              break ;
  40              
  41  //        case 'OutTop' :
  42              // Not supported.
  43              
  44          default :
  45              FCK.Events.AttachEvent( 'OnBlur', FCK_OnBlur ) ;
  46              FCK.Events.AttachEvent( 'OnFocus', FCK_OnFocus ) ;
  47  
  48              var eToolbarTarget ;
  49              
  50              // Out:[TargetWindow]([TargetId])
  51              var oOutMatch = sLocation.match( /^Out:(.+)\((\w+)\)$/ ) ;
  52              if ( oOutMatch )
  53              {
  54                  eToolbarTarget = eval( 'parent.' + oOutMatch[1] ).document.getElementById( oOutMatch[2] ) ;
  55              }
  56              else
  57              {
  58                  // Out:[TargetId]
  59                  oOutMatch = sLocation.match( /^Out:(\w+)$/ ) ;
  60                  if ( oOutMatch )
  61                      eToolbarTarget = parent.document.getElementById( oOutMatch[1] ) ;
  62              }
  63              
  64              if ( !eToolbarTarget )
  65              {
  66                  alert( 'Invalid value for "ToolbarLocation"' ) ;
  67                  return this._Init( 'In' ) ;
  68              }
  69              
  70              // If it is a shared toolbar, it may be already available in the target element.
  71              oToolbarSet = eToolbarTarget.__FCKToolbarSet ;
  72              if ( oToolbarSet )
  73                  break ;
  74  
  75              // Create the IFRAME that will hold the toolbar inside the target element.
  76              var eToolbarIFrame = FCKTools.GetElementDocument( eToolbarTarget ).createElement( 'iframe' ) ;
  77              eToolbarIFrame.frameBorder = 0 ;
  78              eToolbarIFrame.width = '100%' ;
  79              eToolbarIFrame.height = '10' ;
  80              eToolbarTarget.appendChild( eToolbarIFrame ) ;
  81              eToolbarIFrame.unselectable = 'on' ;
  82              
  83              // Write the basic HTML for the toolbar (copy from the editor main page).
  84              var eTargetDocument = eToolbarIFrame.contentWindow.document ;
  85              eTargetDocument.open() ;
  86              eTargetDocument.write( '<html><head><script type="text/javascript"> window.onload = window.onresize = function() { window.frameElement.height = document.body.scrollHeight ; } </script></head><body style="overflow: hidden">' + document.getElementById( 'xToolbarSpace' ).innerHTML + '</body></html>' ) ;
  87              eTargetDocument.close() ;
  88              
  89              eTargetDocument.oncontextmenu = FCKTools.CancelEvent ;
  90  
  91              // Load external resources (must be done here, otherwise Firefox will not
  92              // have the document DOM ready to be used right away.
  93              FCKTools.AppendStyleSheet( eTargetDocument, FCKConfig.SkinPath + 'fck_editor.css' ) ;
  94              
  95              oToolbarSet = eToolbarTarget.__FCKToolbarSet = new FCKToolbarSet( eTargetDocument ) ;
  96              oToolbarSet._IFrame = eToolbarIFrame ;
  97  
  98              if ( FCK.IECleanup )
  99                  FCK.IECleanup.AddItem( eToolbarTarget, FCKToolbarSet_Target_Cleanup ) ;
 100      }
 101      
 102      oToolbarSet.CurrentInstance = FCK ;
 103  
 104      FCK.AttachToOnSelectionChange( oToolbarSet.RefreshItemsState ) ;
 105  
 106      return oToolbarSet ;
 107  }
 108  
 109  function FCK_OnBlur( editorInstance )
 110  {
 111      var eToolbarSet = editorInstance.ToolbarSet ;
 112      
 113      if ( eToolbarSet.CurrentInstance == editorInstance )
 114          eToolbarSet.Disable() ;
 115  }
 116  
 117  function FCK_OnFocus( editorInstance )
 118  {
 119      var oToolbarset = editorInstance.ToolbarSet ;
 120      var oInstance = editorInstance || FCK ;
 121      
 122      // Unregister the toolbar window from the current instance.
 123      oToolbarset.CurrentInstance.FocusManager.RemoveWindow( oToolbarset._IFrame.contentWindow ) ;
 124      
 125      // Set the new current instance.
 126      oToolbarset.CurrentInstance = oInstance ;
 127      
 128      // Register the toolbar window in the current instance.
 129      oInstance.FocusManager.AddWindow( oToolbarset._IFrame.contentWindow, true ) ;
 130  
 131      oToolbarset.Enable() ;
 132  }
 133  
 134  function FCKToolbarSet_Cleanup()
 135  {
 136      this._TargetElement = null ;
 137      this._IFrame = null ;
 138  }
 139  
 140  function FCKToolbarSet_Target_Cleanup()
 141  {
 142      this.__FCKToolbarSet = null ;
 143  }
 144  
 145  var FCKToolbarSet = function( targetDocument )
 146  {
 147      this._Document = targetDocument ; 
 148  
 149      // Get the element that will hold the elements structure.
 150      this._TargetElement    = targetDocument.getElementById( 'xToolbar' ) ;
 151      
 152      // Setup the expand and collapse handlers.
 153      var eExpandHandle    = targetDocument.getElementById( 'xExpandHandle' ) ;
 154      var eCollapseHandle    = targetDocument.getElementById( 'xCollapseHandle' ) ;
 155  
 156      eExpandHandle.title        = FCKLang.ToolbarExpand ;
 157      eExpandHandle.onclick    = FCKToolbarSet_Expand_OnClick ;
 158      
 159      eCollapseHandle.title    = FCKLang.ToolbarCollapse ;
 160      eCollapseHandle.onclick    = FCKToolbarSet_Collapse_OnClick ;
 161  
 162      // Set the toolbar state at startup.
 163      if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded )
 164          this.Expand() ;
 165      else
 166          this.Collapse() ;
 167  
 168      // Enable/disable the collapse handler
 169      eCollapseHandle.style.display = FCKConfig.ToolbarCanCollapse ? '' : 'none' ;
 170  
 171      if ( FCKConfig.ToolbarCanCollapse )
 172          eCollapseHandle.style.display = '' ;
 173      else
 174          targetDocument.getElementById( 'xTBLeftBorder' ).style.display = '' ;
 175          
 176      // Set the default properties.
 177      this.Toolbars = new Array() ;
 178      this.IsLoaded = false ;
 179  
 180      if ( FCK.IECleanup )
 181          FCK.IECleanup.AddItem( this, FCKToolbarSet_Cleanup ) ;
 182  }
 183  
 184  function FCKToolbarSet_Expand_OnClick()
 185  {
 186      FCK.ToolbarSet.Expand() ;
 187  }
 188  
 189  function FCKToolbarSet_Collapse_OnClick()
 190  {
 191      FCK.ToolbarSet.Collapse() ;
 192  }
 193  
 194  FCKToolbarSet.prototype.Expand = function()
 195  {
 196      this._ChangeVisibility( false ) ;
 197  }
 198  
 199  FCKToolbarSet.prototype.Collapse = function()
 200  {
 201      this._ChangeVisibility( true ) ;
 202  }
 203  
 204  FCKToolbarSet.prototype._ChangeVisibility = function( collapse )
 205  {
 206      this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ;
 207      this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ;
 208      
 209      if ( FCKBrowserInfo.IsGecko )
 210      {
 211          // I had to use "setTimeout" because Gecko was not responding in a right
 212          // way when calling window.onresize() directly.
 213          FCKTools.RunFunction( window.onresize ) ;
 214      }
 215  }
 216  
 217  FCKToolbarSet.prototype.Load = function( toolbarSetName )
 218  {
 219      this.Name = toolbarSetName ;
 220  
 221      this.Items = new Array() ;
 222      
 223      // Reset the array of toolbat items that are active only on WYSIWYG mode.
 224      this.ItemsWysiwygOnly = new Array() ;
 225  
 226      // Reset the array of toolbar items that are sensitive to the cursor position.
 227      this.ItemsContextSensitive = new Array() ;
 228      
 229      // Cleanup the target element.
 230      this._TargetElement.innerHTML = '' ;
 231      
 232      var ToolbarSet = FCKConfig.ToolbarSets[toolbarSetName] ;
 233      
 234      if ( !ToolbarSet )
 235      {
 236          alert( FCKLang.UnknownToolbarSet.replace( /%1/g, toolbarSetName ) ) ;
 237          return ;
 238      }
 239      
 240      this.Toolbars = new Array() ;
 241      
 242      for ( var x = 0 ; x < ToolbarSet.length ; x++ ) 
 243      {
 244          var oToolbarItems = ToolbarSet[x] ;
 245          
 246          var oToolbar ;
 247          
 248          if ( typeof( oToolbarItems ) == 'string' )
 249          {
 250              if ( oToolbarItems == '/' )
 251                  oToolbar = new FCKToolbarBreak() ;
 252          }
 253          else
 254          {
 255              oToolbar = new FCKToolbar() ;
 256              
 257              for ( var j = 0 ; j < oToolbarItems.length ; j++ ) 
 258              {
 259                  var sItem = oToolbarItems[j] ;
 260                  
 261                  if ( sItem == '-')
 262                      oToolbar.AddSeparator() ;
 263                  else
 264                  {
 265                      var oItem = FCKToolbarItems.GetItem( sItem ) ;
 266                      if ( oItem )
 267                      {
 268                          oToolbar.AddItem( oItem ) ;
 269  
 270                          this.Items.push( oItem ) ;
 271  
 272                          if ( !oItem.SourceView )
 273                              this.ItemsWysiwygOnly.push( oItem ) ;
 274                          
 275                          if ( oItem.ContextSensitive )
 276                              this.ItemsContextSensitive.push( oItem ) ;
 277                      }
 278                  }
 279              }
 280              
 281              // oToolbar.AddTerminator() ;
 282          }
 283          
 284          oToolbar.Create( this._TargetElement ) ;
 285  
 286          this.Toolbars[ this.Toolbars.length ] = oToolbar ;
 287      }
 288      
 289      FCKTools.DisableSelection( this._Document.getElementById( 'xCollapseHandle' ).parentNode ) ;
 290  
 291      if ( FCK.Status != FCK_STATUS_COMPLETE )
 292          FCK.Events.AttachEvent( 'OnStatusChange', this.RefreshModeState ) ;
 293      else
 294          this.RefreshModeState() ;
 295  
 296      this.IsLoaded = true ;
 297      this.IsEnabled = true ;
 298  
 299      FCKTools.RunFunction( this.OnLoad ) ;
 300  }
 301  
 302  FCKToolbarSet.prototype.Enable = function()
 303  {
 304      if ( this.IsEnabled )
 305          return ;
 306  
 307      this.IsEnabled = true ;
 308  
 309      var aItems = this.Items ;
 310      for ( var i = 0 ; i < aItems.length ; i++ )
 311          aItems[i].RefreshState() ;
 312  }
 313  
 314  FCKToolbarSet.prototype.Disable = function()
 315  {
 316      if ( !this.IsEnabled )
 317          return ;
 318  
 319      this.IsEnabled = false ;
 320  
 321      var aItems = this.Items ;
 322      for ( var i = 0 ; i < aItems.length ; i++ )
 323          aItems[i].Disable() ;
 324  }
 325  
 326  FCKToolbarSet.prototype.RefreshModeState = function( editorInstance )
 327  {
 328      if ( FCK.Status != FCK_STATUS_COMPLETE )
 329          return ;
 330  
 331      var oToolbarSet = editorInstance ? editorInstance.ToolbarSet : this ;
 332      var aItems = oToolbarSet.ItemsWysiwygOnly ;
 333      
 334      if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 335      {
 336          // Enable all buttons that are available on WYSIWYG mode only.
 337          for ( var i = 0 ; i < aItems.length ; i++ )
 338              aItems[i].Enable() ;
 339  
 340          // Refresh the buttons state.
 341          oToolbarSet.RefreshItemsState( editorInstance ) ;
 342      }
 343      else
 344      {
 345          // Refresh the buttons state.
 346          oToolbarSet.RefreshItemsState( editorInstance ) ;
 347  
 348          // Disable all buttons that are available on WYSIWYG mode only.
 349          for ( var j = 0 ; j < aItems.length ; j++ )
 350              aItems[j].Disable() ;
 351      }    
 352  }
 353  
 354  FCKToolbarSet.prototype.RefreshItemsState = function( editorInstance )
 355  {
 356      
 357      var aItems = ( editorInstance ? editorInstance.ToolbarSet : this ).ItemsContextSensitive ;
 358      
 359      for ( var i = 0 ; i < aItems.length ; i++ )
 360          aItems[i].RefreshState() ;
 361  }


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7