topical media & game development

talk show tell print

professional-web-01-v2-menuBar.js / js



  function initMenuBar() {
    
    // MenuBar handling copied from samples
    // in the Yahoo UI library
  
    // "click" event handler for each item in the root MenuBar instance
  
    function onMenuBarItemClick(p_sType, p_aArguments) {
              
      this.parent.hasFocus = true;
      var oActiveItem = this.parent.activeItem;
        
      // Hide any other submenus that might be visible
              
      if(oActiveItem && oActiveItem != this) {
         this.parent.clearActiveItem();
      }
              
      // Select and focus the current MenuItem instance
              
      this.cfg.setProperty("selected", true);
      this.focus();
              
      // Show the submenu for this instance
              
      var oSubmenu = this.cfg.getProperty("submenu");
  
      if(oSubmenu) {
        if(oSubmenu.cfg.getProperty("visible")) {
          oSubmenu.hide();
        } else {
          oSubmenu.show();                    
        }
      }
  
    }
  
    // "mouseover" event handler for each item in the root MenuBar instance
  
    function onMenuBarItemMouseOver(p_sType, p_aArguments) {
              
      var oActiveItem = this.parent.activeItem;
              
      // Hide any other submenus that might be visible
              
      if(oActiveItem && oActiveItem != this) {
        this.parent.clearActiveItem();
      }
   
      // Select and focus the current MenuItem instance
   
      this.cfg.setProperty("selected", true);
      this.focus();
  
      if(this.parent.hasFocus) {                  
        // Show the submenu for this instance
        var oSubmenu = this.cfg.getProperty("submenu");
        if(oSubmenu) {
          if(oSubmenu.cfg.getProperty("visible")) {
            oSubmenu.hide();    
          } else {
            oSubmenu.show();                    
          }
        }
      }
  
    }
  
    var oMenuBar = new YAHOO.widget.MenuBar(
      "menubar", 
      { fixedcenter: false }
    );
    oMenuBar.render();
  
    YAHOO.buzzWatch.menuBar = oMenuBar;
    YAHOO.buzzWatch.menuGo = oMenuBar.getItem(1);
    
    /*
        Add a "click" and "mouseover" event handler to each item 
        in the root MenuBar instnace
    */
  
    var i = oMenuBar.getItemGroups()[0].length - 1,
      oMenuBarItem;
  
    do {
  
      oMenuBarItem = oMenuBar.getItem(i);
                      
      if(oMenuBarItem) {
  
        oMenuBarItem.clickEvent.subscribe(
          onMenuBarItemClick,
          oMenuBarItem,
          true
        );
  
        oMenuBarItem.mouseOverEvent.subscribe(
          onMenuBarItemMouseOver,
          oMenuBarItem,
          true
        );
      }
                  
    } while(i--);
  
    // "click" event handler for the document
     
    function onDocumentClick(p_oEvent) {
                  
      YAHOO.buzzWatch.OverlayManager.hideAll();
     
      oMenuBar.hasFocus = false;
                      
      if(oMenuBar.activeItem) {
  
        oMenuBar.clearActiveItem();
        oMenuBar.activeItem.blur();
                      
      }
  
    }
  
    // Add a "click" handler for the document
  
    YAHOO.util.Event.addListener(
      document, 
      "click", 
      onDocumentClick
    );
  
    YAHOO.buzzWatch.OverlayManager = 
      new YAHOO.widget.OverlayManager();
  
    YAHOO.buzzWatch.OverlayManager.register(
      document.getElementById("menubar.file"));
        
    YAHOO.buzzWatch.OverlayManager.register(
      document.getElementById("menubar.go"));
        
    YAHOO.buzzWatch.OverlayManager.register(
      document.getElementById("menubar.view"));
   
    oMenuBar.show();
      
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.