home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 April / Chip_2003-04_cd1.bin / bonus / energyweb / inc / menu.js < prev    next >
Text File  |  2002-02-04  |  4KB  |  111 lines

  1. var isMinNS4=(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4)?1:0;
  2. var isMinIE4=(document.all)?1:0;
  3. var isMinIE5=(isMinIE4&&navigator.appVersion.indexOf("5.")>=0)?1:0;
  4.  
  5.  
  6. var pop_up_menus=0;
  7. var pop_up_menus_instances = new Array();
  8.  
  9.  function getLayer(name){if(isMinNS4)return findLayer(name,document);if(isMinIE4)return eval('document.all.'+name);return null;}
  10.  function MoveLayerTo(layer,x,y) { if(isMinNS4) { layer.moveTo(x,y); } if(isMinIE4) { layer.style.left=x;layer.style.top=y; } }
  11.  function HideLayer(layer){if(isMinNS4)layer.visibility="hide";if(isMinIE4)layer.style.visibility="hidden";}
  12.  function ShowLayer(layer) { if(isMinNS4)layer.visibility="show"; if(isMinIE4)layer.style.visibility="visible"; }
  13.  function getPageWidth(){if(isMinNS4)return document.width;if(isMinIE4)return document.body.scrollWidth;return-1;}
  14.  function getWidth(layer){if(isMinNS4){if(layer.document.width)return layer.document.width;else return layer.clip.right-layer.clip.left;}if(isMinIE4){if(layer.style.pixelWidth)return layer.style.pixelWidth;else return layer.clientWidth;}return-1;}
  15.  function getHeight(layer){if(isMinNS4){if(layer.document.height)return layer.document.height;else return layer.clip.bottom-layer.clip.top;}if(isMinIE4){if(layer.style.pixelHeight)return layer.style.pixelHeight;else return layer.clientHeight;}return-1;}
  16.  function getLeft(layer){if(isMinNS4)return layer.left;if(isMinIE4)return layer.style.pixelLeft;return-1;}
  17.  function getTop(layer){if(isMinNS4)return layer.top;if(isMinIE4)return layer.style.pixelTop;return-1;}
  18.  function getRight(layer){if(isMinNS4)return layer.left+getWidth(layer);if(isMinIE4)return layer.style.pixelLeft+getWidth(layer);return-1;}
  19.  function getBottom(layer){if(isMinNS4)return layer.top+getHeight(layer);if(isMinIE4)return layer.style.pixelTop+getHeight(layer);return-1;}
  20.  
  21.  
  22. function PopUpMenu()
  23. {
  24.     this.width      = 100;
  25.     this.posx       = 0;
  26.     this.posy       = 0;
  27.     this.items      = new Array();
  28.     this.item_count = 0;
  29.     this.created    = false;
  30.     this.index      = pop_up_menus++;
  31.     this.style      = "";
  32.     this.backcolor  = "#FFFFFF";
  33.     this.textcolor  = "#000000";
  34.     this.open_func  = "";
  35.     this.base_layer = null;
  36.  
  37.     this.AddItem = PM_AddItem;
  38.     this.Create  = PM_Create;
  39.     this.Open    = PM_Open;
  40.     this.ReOpen  = PM_ReOpen;
  41.     this.Close   = PM_Close;
  42.  
  43.     pop_up_menus_instances[pop_up_menus-1] = this;
  44.     return this;
  45. }
  46.  
  47. function PM_AddItem(item_text,item_href,href_type)
  48. {
  49.     this.item_count++;
  50.     this.items[this.item_count-1]= new Array(item_text,item_href,href_type);
  51. }
  52.  
  53. function PM_Create()
  54. {
  55.     if (this.style!="") class_str = "class='"+this.style+"'";  else class_str="";
  56.  
  57.     str  = "<div id='_menu_"+this.index+"' style='position:absolute; width:"+this.width+"'><table "+class_str+" bgcolor='"+this.backcolor+"' cellpadding=2 cellspacing=0 width='100%' height='100%'><tr><td>";
  58.     for (i=0;i<this.item_count;i++)
  59.     {
  60.          str  = str + "<a href='"+this.items[i][1]+"' style='color:"+this.textcolor+"'>"+this.items[i][0]+"</a><br>";
  61.     }
  62.     str  = str + "</td></tr></table></div>";
  63.  
  64.     if(isMinNS4) 
  65.       {
  66.           this.base_layer = new Layer(this.width);
  67.       }
  68.         
  69.       if(isMinIE4)
  70.       {
  71.           document.body.insertAdjacentHTML("beforeEnd",str);
  72.           this.base_layer = getLayer("_menu_"+this.index);
  73.        }
  74.  
  75.     HideLayer(this.base_layer);
  76.     this.base_layer.onmouseout=PM_MenuOff;
  77.     this.base_layer.index = this.index;
  78. }
  79.  
  80. function PM_Open(x,y)
  81. {
  82.    this.posx = x;
  83.    this.posy = y;
  84.    MoveLayerTo(this.base_layer, this.posx,this.posy);
  85.    ShowLayer(this.base_layer);
  86. }
  87.  
  88. function PM_ReOpen()
  89. {
  90.    MoveLayerTo(this.base_layer,this.posx,this.posy);
  91.    ShowLayer(this.base_layer);
  92. }
  93.  
  94. function PM_Close()
  95. {
  96.    HideLayer(this.base_layer);
  97. }
  98.  
  99. function PM_MenuOff(e)
  100. {
  101.   var menu = pop_up_menus_instances[this.index];
  102.  
  103.     if(isMinIE4)
  104.     {
  105.         mouseX=window.event.clientX+document.body.scrollLeft;
  106.         mouseY=window.event.clientY+document.body.scrollTop;
  107.   }
  108.     if(!(mouseX>getLeft(this) && mouseX<getRight(this) && mouseY>getTop(this) && mouseY<getBottom(this)))
  109.       HideLayer(this);
  110. }
  111.