[ Index ]
 

Code source de FCKeditor 2.4

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

title

Body

[fermer]

/editor/_source/classes/ -> fckmenuitem.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: fckmenuitem.js
  22   *     Defines and renders a menu items in a menu block.
  23   * 
  24   * File Authors:
  25   *         Frederico Caldeira Knabben (www.fckeditor.net)
  26   */
  27  
  28  
  29  var FCKMenuItem = function( parentMenuBlock, name, label, iconPathOrStripInfoArray, isDisabled )
  30  {
  31      this.Name        = name ;
  32      this.Label        = label || name ;
  33      this.IsDisabled    = isDisabled ;
  34      
  35      this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
  36      
  37      this.SubMenu            = new FCKMenuBlockPanel() ;
  38      this.SubMenu.Parent        = parentMenuBlock ;
  39      this.SubMenu.OnClick    = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnClick, this ) ;
  40  
  41      if ( FCK.IECleanup )
  42          FCK.IECleanup.AddItem( this, FCKMenuItem_Cleanup ) ;
  43  }
  44  
  45  
  46  FCKMenuItem.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
  47  {
  48      this.HasSubMenu = true ;
  49      return this.SubMenu.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ;
  50  }
  51  
  52  FCKMenuItem.prototype.AddSeparator = function()
  53  {
  54      this.SubMenu.AddSeparator() ;
  55  }
  56  
  57  FCKMenuItem.prototype.Create = function( parentTable )
  58  {
  59      var bHasSubMenu = this.HasSubMenu ;
  60      
  61      var oDoc = FCKTools.GetElementDocument( parentTable ) ;
  62  
  63      // Add a row in the table to hold the menu item.
  64      var r = this.MainElement = parentTable.insertRow(-1) ;
  65      r.className = this.IsDisabled ? 'MN_Item_Disabled' : 'MN_Item' ;
  66  
  67      // Set the row behavior.
  68      if ( !this.IsDisabled )
  69      {
  70          FCKTools.AddEventListenerEx( r, 'mouseover', FCKMenuItem_OnMouseOver, [ this ] ) ;
  71          FCKTools.AddEventListenerEx( r, 'click', FCKMenuItem_OnClick, [ this ] ) ;
  72  
  73          if ( !bHasSubMenu )
  74              FCKTools.AddEventListenerEx( r, 'mouseout', FCKMenuItem_OnMouseOut, [ this ] ) ;
  75      }
  76      
  77      // Create the icon cell.
  78      var eCell = r.insertCell(-1) ;
  79      eCell.className = 'MN_Icon' ;
  80      eCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
  81  
  82      // Create the label cell.
  83      eCell = r.insertCell(-1) ;
  84      eCell.className = 'MN_Label' ;
  85      eCell.noWrap = true ;
  86      eCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
  87      
  88      // Create the arrow cell and setup the sub menu panel (if needed).
  89      eCell = r.insertCell(-1) ;
  90      if ( bHasSubMenu )
  91      {
  92          eCell.className = 'MN_Arrow' ;
  93  
  94          // The arrow is a fixed size image.
  95          var eArrowImg = eCell.appendChild( oDoc.createElement( 'IMG' ) ) ;
  96          eArrowImg.src = FCK_IMAGES_PATH + 'arrow_' + FCKLang.Dir + '.gif' ;
  97          eArrowImg.width     = 4 ;
  98          eArrowImg.height = 7 ;
  99          
 100          this.SubMenu.Create() ;
 101          this.SubMenu.Panel.OnHide = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnHide, this ) ;
 102      }
 103  }
 104  
 105  FCKMenuItem.prototype.Activate = function()
 106  {
 107      this.MainElement.className = 'MN_Item_Over' ;
 108  
 109      if ( this.HasSubMenu )
 110      {
 111          // Show the child menu block. The ( +2, -2 ) correction is done because
 112          // of the padding in the skin. It is not a good solution because one
 113          // could change the skin and so the final result would not be accurate.
 114          // For now it is ok because we are controlling the skin.
 115          this.SubMenu.Show( this.MainElement.offsetWidth + 2, -2, this.MainElement ) ;
 116      }
 117  
 118      FCKTools.RunFunction( this.OnActivate, this ) ;
 119  }
 120  
 121  FCKMenuItem.prototype.Deactivate = function()
 122  {
 123      this.MainElement.className = 'MN_Item' ;
 124  
 125      if ( this.HasSubMenu )
 126          this.SubMenu.Hide() ;
 127  }
 128  
 129  /* Events */
 130  
 131  function FCKMenuItem_SubMenu_OnClick( clickedItem, listeningItem )
 132  {
 133      FCKTools.RunFunction( listeningItem.OnClick, listeningItem, [ clickedItem ] ) ;
 134  }
 135  
 136  function FCKMenuItem_SubMenu_OnHide( menuItem )
 137  {
 138      menuItem.Deactivate() ;
 139  }
 140  
 141  function FCKMenuItem_OnClick( ev, menuItem )
 142  {
 143      if ( menuItem.HasSubMenu )
 144          menuItem.Activate() ;
 145      else
 146      {
 147          menuItem.Deactivate() ;
 148          FCKTools.RunFunction( menuItem.OnClick, menuItem, [ menuItem ] ) ;
 149      }
 150  }
 151  
 152  function FCKMenuItem_OnMouseOver( ev, menuItem )
 153  {
 154      menuItem.Activate() ;
 155  }
 156  
 157  function FCKMenuItem_OnMouseOut( ev, menuItem )
 158  {
 159      menuItem.Deactivate() ;
 160  }
 161  
 162  function FCKMenuItem_Cleanup()
 163  {
 164      this.MainElement = null ;
 165  }


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