home *** CD-ROM | disk | FTP | other *** search
/ Il Mio Computer 2006 May / Mico05CD.bin / Utility / CryptoMX / menu.js < prev    next >
Encoding:
Text File  |  2006-01-05  |  7.2 KB  |  248 lines

  1. if (document.all)    {n=0;ie=1;ns6=0;fShow="visible";fHide="hidden";}
  2. if (document.getElementById&&!document.all)    {n=0;ie=0;ns6=1;fShow="visible";fHide="hidden";}
  3. if (document.layers) {n=1;ie=0;ns6=0;fShow="show";fHide="hide";}
  4.  
  5. opr6=ie&&navigator.userAgent.indexOf("Opera")!=-1
  6.  
  7. window.onerror=new Function("return true")
  8.  
  9. rightX = 0;
  10. function Menu()
  11. {
  12.     this.bgColor     = menucolor;
  13.     if (ie) this.menuFont = "bold 12px Arial"; 
  14.     if (n)  this.menuFont = "bold 12px Verdana";
  15.     this.fontColor   = "black";
  16.  
  17.     this.addItem    = addItem;
  18.     this.addSubItem = addSubItem;
  19.     this.showMenu   = showMenu;
  20.     this.mainPaneBorder = 0;
  21.     this.subMenuPaneBorder = 0;
  22.  
  23.     this.subMenuPaneWidth = submenuwidth;
  24.  
  25.     lastMenu = null;
  26.     
  27.     rightY = 0;
  28.     leftY = 0;
  29.     leftX = 0;
  30.  
  31.     HTMLstr = "";
  32.     HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
  33.     HTMLstr += "\n";
  34.     if (ie||ns6) HTMLstr += "<div id='MainTable' style='position:absolute;top:0;left:0;'>\n";
  35.     HTMLstr += "<table width='100%' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"'>\n";
  36.     HTMLstr += "<tr>";
  37.     if (n) HTMLstr += "<td> ";
  38.     HTMLstr += "<!-- MAIN MENU STARTS -->\n";
  39.     HTMLstr += "<!-- MAIN_MENU -->\n";
  40.     HTMLstr += "<!-- MAIN MENU ENDS -->\n";
  41.     if (n) HTMLstr += "</td>";
  42.     HTMLstr += "</tr>\n";
  43.     HTMLstr += "</table>\n";
  44.     HTMLstr += "\n";
  45.     HTMLstr += "<!-- SUB MENU STARTS -->\n";
  46.     HTMLstr += "<!-- SUB_MENU -->\n";
  47.     HTMLstr += "<!-- SUB MENU ENDS -->\n";
  48.     HTMLstr += "\n";
  49.     if (ie||ns6) HTMLstr+= "</div>\n";
  50.     HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
  51. }
  52.  
  53. function addItem(idItem, text, hint, location, altLocation)
  54. {
  55.     var Lookup = "<!-- ITEM "+idItem+" -->";
  56.     if (HTMLstr.indexOf(Lookup) != -1)
  57.     {
  58.         alert(idParent + " already exist");
  59.         return;
  60.     }
  61.     var MENUitem = "";
  62.     MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
  63.     if (n)
  64.     {
  65.         MENUitem += "<ilayer name="+idItem+">";
  66.         MENUitem += "<a href='.' class=clsMenuItemNS onmouseover=\"displaySubMenu('"+idItem+"')\" onclick=\"return false;\">";
  67.         MENUitem += "| ";
  68.         MENUitem += text;
  69.         MENUitem += "</a>";
  70.         MENUitem += "</ilayer>";
  71.     }
  72.     if (ie||ns6)
  73.     {
  74.         MENUitem += "<td>\n";
  75.         MENUitem += "<div id='"+idItem+"' style='position:relative; font: "+this.menuFont+";'>\n";
  76.         MENUitem += "<a ";
  77.         MENUitem += "class=clsMenuItemIE ";
  78.         if (hint != null)
  79.             MENUitem += "title='"+hint+"' ";
  80.         if (location != null)
  81.         {
  82.             MENUitem += "href='"+location+"' ";
  83.             MENUitem += "onmouseover=\"hideAll()\" ";
  84.         }
  85.         else
  86.         {
  87.             if (altLocation != null)
  88.                 MENUitem += "href='"+altLocation+"' ";
  89.             else
  90.                 MENUitem += "href='.' ";
  91.             MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
  92.             MENUitem += "onclick=\"return false;\" "
  93.         }
  94.         MENUitem += ">";
  95.         MENUitem += "| \n";
  96.         MENUitem += text;
  97.         MENUitem += "</a>\n";
  98.         MENUitem += "</div>\n";
  99.         MENUitem += "</td>\n";
  100.     }
  101.     MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
  102.     MENUitem += "<!-- MAIN_MENU -->\n";
  103.  
  104.     HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
  105. }
  106.  
  107. function addSubItem(idParent, text, hint, location, linktarget)
  108. {
  109.     var MENUitem = "";
  110.     Lookup = "<!-- ITEM "+idParent+" -->";
  111.     if (HTMLstr.indexOf(Lookup) == -1)
  112.     {
  113.         alert(idParent + " not found");
  114.         return;
  115.     }
  116.     Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
  117.     if (HTMLstr.indexOf(Lookup) == -1)
  118.     {
  119.         if (n)
  120.         {
  121.             MENUitem += "\n";
  122.             MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'>\n";
  123.             MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+">\n";
  124.             MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
  125.             MENUitem += "</table>\n";
  126.             MENUitem += "</layer>\n";
  127.             MENUitem += "\n";
  128.         }
  129.         if (ie||ns6)
  130.         {
  131.             MENUitem += "\n";
  132.             MENUitem += "<div id='"+idParent+"submenu' onmouseout=operahide() style='position:absolute; visibility: hidden; z-index:100; width: "+this.subMenuPaneWidth+"; font: "+this.menuFont+"; top: -300;'>\n";
  133.             MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+">\n";
  134.             MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
  135.             MENUitem += "</table>\n";
  136.             MENUitem += "</div>\n";
  137.             MENUitem += "\n";
  138.         }
  139.         MENUitem += "<!-- SUB_MENU -->\n";
  140.         HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
  141.     }
  142.  
  143.     Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
  144.     if (n)  MENUitem = "<tr><td><a class=clsMenuItemNS title='"+hint+"' href='"+location+"' target='"+linktarget+"'>"+text+"</a><br></td></tr>\n";
  145.     if (ie||ns6) MENUitem = "<tr><td><a class=clsMenuItemIE title='"+hint+"' href='"+location+"' target='"+linktarget+"'>"+text+"</a><br></td></tr>\n";
  146.     MENUitem += Lookup;
  147.     HTMLstr = HTMLstr.replace(Lookup, MENUitem);
  148.  
  149. }
  150.  
  151. function showMenu()
  152. {
  153.     document.writeln(HTMLstr);
  154. }
  155.  
  156. function displaySubMenu(idMainMenu)
  157. {
  158.     var menu;
  159.     var submenu;
  160.     if (n)
  161.     {
  162.         submenu = document.layers[idMainMenu+"submenu"];
  163.         if (lastMenu != null && lastMenu != submenu) hideAll();
  164.         submenu.left = document.layers[idMainMenu].pageX;
  165.         submenu.top  = document.layers[idMainMenu].pageY + 25;
  166.         submenu.visibility = fShow;
  167.  
  168.         leftX  = document.layers[idMainMenu+"submenu"].left;
  169.         rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
  170.         leftY  = document.layers[idMainMenu+"submenu"].top+
  171.             document.layers[idMainMenu+"submenu"].clip.height;
  172.         rightY = leftY;
  173.     } else if (ie||ns6) {
  174.         menu = ie? eval(idMainMenu) : document.getElementById(idMainMenu);
  175.         submenu = ie? eval(idMainMenu+"submenu.style") : document.getElementById(idMainMenu+"submenu").style;
  176.         submenu.left = calculateSumOffset(menu, 'offsetLeft');
  177.         submenu.top  = menu.style.top+23;
  178.         submenu.visibility = fShow;
  179.         if (lastMenu != null && lastMenu != submenu) hideAll();
  180.  
  181.         leftX  = ie? document.all[idMainMenu+"submenu"].style.posLeft : parseInt(document.getElementById(idMainMenu+"submenu").style.left);
  182.         rightX = ie? leftX + document.all[idMainMenu+"submenu"].offsetWidth : leftX+parseInt(document.getElementById(idMainMenu+"submenu").offsetWidth);
  183.  
  184.         leftY  = ie? document.all[idMainMenu+"submenu"].style.posTop+
  185.             document.all[idMainMenu+"submenu"].offsetHeight : parseInt(document.getElementById(idMainMenu+"submenu").style.top)+parseInt(document.getElementById(idMainMenu+"submenu").offsetHeight);
  186.         rightY = leftY;
  187.     }
  188.     lastMenu = submenu;
  189. }
  190.  
  191. function hideAll()
  192. {
  193.     if (lastMenu != null) {lastMenu.visibility = fHide;lastMenu.left = 0;}
  194. }
  195.  
  196. function calculateSumOffset(idItem, offsetName)
  197. {
  198.     var totalOffset = 0;
  199.     var item = eval('idItem');
  200.     do
  201.     {
  202.         totalOffset += eval('item.'+offsetName);
  203.         item = eval('item.offsetParent');
  204.     } while (item != null);
  205.     return totalOffset;
  206. }
  207.  
  208. function updateIt(e)
  209. {
  210.     if (ie&&!opr6)
  211.     {
  212.         var x = window.event.clientX;
  213.         var y = window.event.clientY;
  214.  
  215.         if (x > rightX || x < leftX) hideAll();
  216.         else if (y > rightY) hideAll();
  217.     }
  218.     if (n||ns6)
  219.     {
  220.         var x = e.pageX;
  221.         var y = e.pageY;
  222.  
  223.         if (x > rightX || x < leftX) hideAll();
  224.         else if (y > rightY) hideAll();
  225.     }
  226. }
  227.  
  228. function operahide(){
  229.         if (opr6){
  230.         if (!MainTable.contains(event.toElement))
  231.         hideAll()
  232. }
  233. }
  234.  
  235. if (ie||ns6)
  236. {
  237.     document.body.onclick=hideAll;
  238.     document.body.onscroll=hideAll;
  239.     document.body.onmousemove=updateIt;
  240. }
  241. if (document.layers)
  242. {
  243.     window.captureEvents(Event.MOUSEMOVE);
  244.     window.captureEvents(Event.CLICK);
  245.     window.onmousemove=updateIt;
  246.     window.onclick=hideAll;
  247. }
  248.