[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/jscripts/ -> popup_menu.js (source)

   1  var PopupMenu = Class.create();
   2  
   3  PopupMenu.prototype = {
   4  
   5      initialize: function(id, options)
   6      {
   7          document.currentMenu = "";
   8  
   9          if(!$(id))
  10          {
  11              return false;
  12          }
  13          this.id = id;
  14          var element = $(id);
  15          
  16          var popupMenu = element.id+"_popup";
  17          if(!$(popupMenu))
  18          {
  19              return false;
  20          }
  21          
  22          this.menu = $(popupMenu);
  23          this.menu.style.display = "none";
  24          element.onclick = this.openMenu.bindAsEventListener(this);
  25      },
  26      
  27      openMenu: function(e)
  28      {
  29          Event.stop(e);
  30          if(document.currentMenu && document.currentMenu == this.id)
  31          {
  32              this.closeMenu();
  33              return false;
  34          }
  35          else if(document.currentMenu != "")
  36          {
  37              this.closeMenu();
  38          }
  39          
  40          offsetTop = offsetLeft = 0;
  41          var element = $(this.id);
  42          do
  43          {
  44              offsetTop += element.offsetTop || 0;
  45              offsetLeft += element.offsetLeft || 0;
  46              element = element.offsetParent;
  47              if(element)
  48              {
  49                  if(Element.getStyle(element, 'position') == 'relative' || Element.getStyle(element, 'position') == 'absolute') break;
  50              }
  51          } while(element);
  52          offsetTopReal = offsetTop;
  53          offsetLeftReal = offsetLeft;
  54          if(element) // will be true if we broke off the last loop
  55          {
  56              // calculate the true top/left position relative to page borders (this is used for checking whether the popup menu will be displayed within the page)
  57              do
  58              {
  59                  offsetTopReal += element.offsetTop || 0;
  60                  offsetLeftReal += element.offsetLeft || 0;
  61              } while(element = element.offsetParent);
  62          }
  63          element = $(this.id);
  64          element.blur();
  65          this.menu.style.position = "absolute";
  66          this.menu.style.zIndex = 100;
  67          this.menu.style.top = (offsetTop+element.offsetHeight-1)+"px";
  68          // Bad browser detection - yes, only choice - yes.
  69          if(MyBB.browser == "opera" || MyBB.browser == "safari")
  70          {
  71              this.menu.style.top = (parseInt(this.menu.style.top)-2)+"px";
  72          }
  73          this.menu.style.left = offsetLeft+"px";
  74          this.menu.style.visibility = 'hidden';
  75          this.menu.style.display = 'block';
  76          if(this.menu.style.width)
  77          {
  78              menuWidth = parseInt(this.menu.style.width);
  79          }
  80          else
  81          {
  82              menuWidth = this.menu.offsetWidth;
  83          }
  84          pageSize = DomLib.getPageSize();
  85          if(offsetLeftReal+menuWidth >= pageSize[0])
  86          {
  87              this.menu.style.left = (offsetLeft-menuWidth+element.offsetWidth)+"px";
  88          }
  89          this.menu.style.display = 'block';    
  90          this.menu.style.visibility = 'visible';
  91  
  92          document.currentMenu = element.id;
  93          Event.observe(document, 'click', this.closeMenu.bindAsEventListener(this));
  94      },
  95      
  96      closeMenu: function()
  97      {
  98          if(!document.currentMenu)
  99          {
 100              return;
 101          }
 102          var menu = document.currentMenu;
 103          menu = $(menu+"_popup");
 104          menu.style.display = "none";
 105          document.currentMenu = "";
 106          document.onclick = function() { };
 107      }
 108  };


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1