当前位置:首页 > 开发教程 > js/jQuery教程 >

js 下拉级联菜单(2)

时间:2013-04-25 11:00 来源:网络整理 作者:采集侠 收藏

// removeIframeLayer for Menu Bar // removes an IFRAME underneath a menu to reveal any form controls and ActiveX Spry.Widget.MenuBar.prototype.removeIframeLayer = function(menu) { var layers = menu.p

// removeIframeLayer for Menu Bar
// removes an IFRAME underneath a menu to reveal any form controls and ActiveX
Spry.Widget.MenuBar.prototype.removeIframeLayer =  function(menu)
{
 var layers = menu.parentNode.getElementsByTagName('iframe');
 while(layers.length > 0)
 {
  layers[0].parentNode.removeChild(layers[0]);
 }
};

// clearMenus for Menu Bar
// root is the top level unordered list (<ul> tag)
Spry.Widget.MenuBar.prototype.clearMenus = function(root)
{
 var menus = root.getElementsByTagName('ul');
 for(var i=0; i<menus.length; i++)
 {
  this.hideSubmenu(menus[i]);
 }
 this.removeClassName(this.element, "MenuBarActive");
};

// bubbledTextEvent for Menu Bar
// identify bubbled up text events in Safari so we can ignore them
Spry.Widget.MenuBar.prototype.bubbledTextEvent = function()
{
 return (navigator.vendor == 'Apple Computer, Inc.' && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)));
};

// showSubmenu for Menu Bar
// set the proper CSS class on this menu to show it
Spry.Widget.MenuBar.prototype.showSubmenu = function(menu)
{
 if(this.currMenu)
 {
  this.clearMenus(this.currMenu);
  this.currMenu = null;
 }
 
 if(menu)
 {
  this.addClassName(menu, "MenuBarSubmenuVisible");
  if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
  {
   if(!this.hasClassName(this.element, "MenuBarHorizontal") || menu.parentNode.parentNode != this.element)
   {
    menu.style.top = menu.parentNode.offsetTop + 'px';
   }
  }
  if(typeof document.uniqueID != "undefined")
  {
   this.createIframeLayer(menu);
  }
 }
 this.addClassName(this.element, "MenuBarActive");
};

// hideSubmenu for Menu Bar
// remove the proper CSS class on this menu to hide it
Spry.Widget.MenuBar.prototype.hideSubmenu = function(menu)
{
 if(menu)
 {
  this.removeClassName(menu, "MenuBarSubmenuVisible");
  if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
  {
   menu.style.top = '';
   menu.style.left = '';
  }
  this.removeIframeLayer(menu);
 }
};

// initialize for Menu Bar
// create event listeners for the Menu Bar widget so we can properly
// show and hide submenus
Spry.Widget.MenuBar.prototype.initialize = function(listitem, element, isie)
{
 var opentime, closetime;
 var link = listitem.getElementsByTagName('a')[0];
 var submenus = listitem.getElementsByTagName('ul');
 var menu = (submenus.length > 0 submenus[0] : null);

 var hasSubMenu = false;
 if(menu)
 {
  this.addClassName(link, "MenuBarItemSubmenu");
  hasSubMenu = true;
 }

 if(!isie)
 {
  // define a simple function that comes standard in IE to determine
  // if a node is within another node
  listitem.contains = function(testNode)
  {
   // this refers to the list item
   if(testNode == null)
   {
    return false;
   }
   if(testNode == this)
   {
    return true;
   }
   else
   {
    return this.contains(testNode.parentNode);
   }
  };
 }
 
 // need to save this for scope further down
 var self = this;


js/jQuery教程阅读排行

最新文章