Loading ...
Sorry, an error occurred while loading the content.

problem in using using single context menu with removing and ,adding new items

Expand Messages
  • kavithapronet
    Hii all,, I am using single CONTEXT menu for whole document and removing elements from old target and adding new elements of new target. This greatly increases
    Message 1 of 1 , Feb 2, 2007
    • 0 Attachment
      Hii all,,

      I am using single CONTEXT menu for whole document and removing
      elements from old target and adding new elements of new target.

      This greatly increases the performance speed of menu.

      The menu displays fine with items not having submenu.

      But if i have some items with submenu,,menu will through javascript
      error and doesnt get displayed.

      my code is
      I have declared menu as globally,,
      var oMenu = new YAHOO.widget.ContextMenu("cmenu", { hidedelay : 5,
      constraintoviewport : true, submenualignment : ["tr", "tl"] });

      and calling mouse over function upon mouse over a href

      function buttonMouseOver(evt, id) {
      var target = (evt.target) ? evt.target : evt.srcElement;
      if (target.tagName == "IMG") {
      target = target.parentNode;
      }
      if ( YAHOO.widget.MenuManager.getMenu("oMenu") !== undefined ){
      var oContextMenu = YAHOO.widget.MenuManager.getMenu("oMenu");
      removeAllItems(oContextMenu);
      }
      var oYuiMenu = document.getElementById(id);
      var oLIs = oYuiMenu.getElementsByTagName("ul")[0].childNodes;
      if (!oLIs || oLIs.length == 0) {
      return;
      }
      for (i = 0; i < oLIs.length; i++) {
      if ("yuimenuitem" == oLIs[i].className) {
      oItem = oLIs[i].getElementsByTagName("a")[0];
      if (oItem.href.charAt(oItem.href.length-1) == "#") {
      sub = oLIs[i].getElementsByTagName("div")[0];
      oMenu.addItem({ text : oItem.innerHTML, submenu :
      getSubMenu(oLIs[i]) });
      } else {
      oMenu.addItem({ text : oItem.innerHTML, url : oItem.href });
      }
      }
      }
      oMenu.render(document.body);
      oMenu.cfg.setProperty("context", [target, "tr", "tl"]);
      oMenu.cfg.setProperty("lazyload", true);
      oMenu.show();
      }


      function getSubMenu(oLI) {
      u = oLI.getElementsByTagName("div")[0];
      return { id : oYuiMenu.id }
      }

      upon each mouseover i am setting the target,,,

      Please help in this regard.

      Thank you
    Your message has been successfully submitted and would be delivered to recipients shortly.