home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 2000 August / AUG2000.BIN / nav_2 / menucode.js < prev    next >
Encoding:
Text File  |  2000-03-12  |  13.2 KB  |  428 lines

  1.     topCount = 0;
  2.   if (!window.imgHspace) imgHspace=0;
  3.     
  4. function Initialise() {
  5.     bIsLoaded = false;
  6.     bAllFinished = false;
  7.     bBeingCreated = true;
  8.     bOverMenu = false;
  9.     
  10.     iHighestZ = 50000;
  11.     mSecsVis = iSecondsVisible * 1000;
  12.     topCount = 1;
  13.     allTimer = null;
  14.  
  15.     iImageSpan = (IE4) ? iImageSize : iImageSize + 12;
  16.     sImageHTML = "<SPAN STYLE='width:" + iImageSpan + ";height:100%;float:right'>";
  17.     sImageHTML += "<IMG SRC='" + sImage + "' WIDTH=" + iImageSize + " HEIGHT=" + iImageSize + " BORDER=0>";
  18.     sImageHTML += "</SPAN>";
  19. }
  20.  
  21. function LoadMenus() {
  22.     Initialise();
  23.     while(eval("window.arMenu" + topCount)) {
  24.         (IE4) ? GenerateTreesIE(false, topCount) : makeMenuNN(false, topCount);
  25.         topCount++ }
  26.     bIsLoaded = true;
  27.     //                                        status = (topCount-1) + " Hierarchical Menu Trees Created"
  28.     bAllFinished = true;
  29.     bBeingCreated = false;
  30. }
  31.  
  32. function makeMenuNN(bIsChild, menuCount, parentMenu, parItem) {
  33.     menu = eval("Menu" + menuCount + "= new Layer(null, window)");
  34.     menu.array = eval("arMenu" + menuCount);
  35.     menu.SetTreeProperties = SetTreeProperties;
  36.     menu.SetTreeProperties(bIsChild,parentMenu);
  37.  
  38.     while (menu.itemCount < menu.maxItems) {
  39.         menu.itemCount++;
  40.         // status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;
  41.         prevItem = (menu.itemCount > 1) ? menu.item : null;
  42.         sArrayName = "item" + menuCount + "_" + menu.itemCount;
  43.  
  44.         menu.item = eval(sArrayName + "= new Layer(width, menu)");
  45.         menu.item.prevItem = prevItem;
  46.         menu.item.setup = itemSetup;
  47.         menu.item.setup(menu.itemCount,menu.array);
  48.         if (menu.item.hasChildren) {
  49.             makeMenuNN(true, menuCount + "_" + menu.itemCount, menu, menu.item);
  50.             menu = menu.parentMenu; }
  51.     }
  52.     menu.lastItem = menu.item;
  53.     menu.setup(bIsChild, parentMenu, parItem);
  54.     menu.xPos = aPosX[menuCount - 1];
  55.     menu.yPos = aPosY[menuCount - 1];
  56. }
  57.  
  58. function GenerateTreesIE(bIsChild, menuCount, parentMenu) {
  59.     sMenuID = "Menu" + menuCount;
  60.     sElementHTML = "<DIV ID=" + sMenuID + " STYLE='position:absolute'></DIV>";
  61.     window.document.body.insertAdjacentHTML("BeforeEnd", sElementHTML);
  62.     
  63.     menu = eval(sMenuID);
  64.     menu.array = eval("arMenu" + menuCount);
  65.     menu.SetTreeProperties = SetTreeProperties;
  66.     menu.SetTreeProperties(bIsChild, parentMenu);
  67.     menu.itemStr = "";
  68.     
  69.     while (menu.itemCount < menu.maxItems) {
  70.         menu.itemCount++;
  71.             //                status = "Creating Hierarchical Menus: " + menuCount + " / " + menu.itemCount;
  72.         sItemID = "item" + menuCount + "_" + menu.itemCount;
  73.         iArrayNum = (menu.itemCount - 1) * 3;
  74.         text = menu.array[iArrayNum];
  75.         bHasChildren = menu.array[iArrayNum + 2];
  76.         sTextHTML = (bHasChildren) ? sImageHTML + text : text;
  77.         menu.itemStr += "<SPAN ID=" + sItemID + " STYLE=\"width:" + width + "\">" + sTextHTML + "</SPAN><BR>";
  78.         if (bHasChildren) {
  79.             GenerateTreesIE(true, menuCount + "_" + menu.itemCount, menu);
  80.             menu = menu.parentMenu; }    
  81.     }
  82.     menu.innerHTML = menu.itemStr;
  83.     itemCol = menu.children.tags("SPAN");
  84.     for (i=0; i<itemCol.length; i++) {
  85.         it = itemCol(i);
  86.         it.setup = itemSetup;
  87.         it.setup(i+1, menu.array);
  88.   }
  89.     menu.lastItem = itemCol(itemCol.length-1);
  90.     menu.setup(bIsChild, parentMenu);
  91.     menu.xPos = aPosX[menuCount - 1];
  92.     menu.yPos = aPosY[menuCount - 1];
  93. }
  94.  
  95. function SetTreeProperties(bIsChild, parentMenu) {
  96.     this.width = width;
  97.     this.backColour = backCol;
  98.     this.overColour = overCol;
  99.     this.borderColour =  borCol;
  100.     this.maxItems = this.array.length / 3;
  101.     this.hasParent = bIsChild;
  102.   this.setup = menuSetup;
  103.     this.itemCount = 0;
  104.     
  105.     if (!bIsChild) {
  106.         this.parentTree = this;
  107.         this.startChild = this; }
  108.     else { this.parentTree = parentMenu.parentTree; }
  109. }
  110.  
  111. function itemSetup(whichItem, whichArray) {
  112.     this.onmouseover = itemOver;
  113.     this.onmouseout = itemOut;
  114.     this.container = (IE4) ? this.offsetParent : this.parentLayer;
  115.     iArrayNum = (whichItem - 1) * 3;
  116.     this.text = whichArray[iArrayNum];
  117.     this.URL = whichArray[iArrayNum + 1];
  118.     this.hasChildren = whichArray[iArrayNum + 2];
  119.  
  120.     if (IE4 && this.hasChildren) {
  121.         this.child = eval("Menu" + this.id.substr(4));
  122.         this.child.parentMenu = this.container;
  123.         this.child.parentItem = this;
  124.     }
  125.     if (this.URL) {
  126.         if (IE4) { this.onclick = linkIt; this.style.cursor = "hand"; }
  127.         if (NN4) { this.captureEvents(Event.MOUSEUP); this.onmouseup = linkIt; }
  128.     }
  129.     if (IE4) {
  130.         with (this.style) {
  131.             padding = itemPad;
  132.             paddingRight = itemPad;
  133.             color = sFontColour;
  134.             fontSize = iFontSize + "pt";
  135.             fontWeight = "normal";
  136.             fontFamily = sFontFace;
  137.             borderBottomWidth = "1px";
  138.             borderBottomColor = borCol;
  139.             borderBottomStyle = "solid";
  140.             backgroundColor = backCol; }
  141.     }
  142.     if (NN4) {
  143.         this.HTML = "<FONT FACE='" + sFontFace + "' POINT-SIZE=" + iFontSize + " COLOR='" + sFontColour + "'>" + this.text + "</FONT>";
  144.         if(this.hasChildren) { this.document.write(sImageHTML); this.document.close(); }  
  145.         this.visibility = "inherit";
  146.         this.bgColor = backCol;
  147.         if (whichItem == 1) { this.top = itemPad; }
  148.         else { this.top = (this.prevItem.top + this.prevItem.clip.height + 1) }
  149.         this.left = itemPad;
  150.         this.clip.top = this.clip.left = -itemPad + 1;
  151.         this.clip.right = (this.container.width - itemPad - 1);
  152.         iMaxSpace= this.container.width - (itemPad*2);
  153.         this.textLayer = new Layer(iMaxSpace, this);
  154.         this.textLayer.document.write(this.HTML);
  155.         this.textLayer.document.close();
  156.         this.textLayer.visibility = "inherit";
  157.         this.clip.bottom = this.textLayer.document.height + itemPad;
  158.         this.dummyLyr = new Layer(100, this);
  159.         this.dummyLyr.left = this.dummyLyr.top = -itemPad;
  160.         this.dummyLyr.clip.width = this.clip.width;
  161.         this.dummyLyr.clip.height = this.clip.height;
  162.         this.dummyLyr.visibility = "inherit"; }
  163. }    
  164.  
  165. function menuSetup(hasParent, openCont, openItem) {
  166.     this.onmouseover = menuOver;
  167.     this.onmouseout = menuOut;
  168.     
  169.     this.showIt = showIt;
  170.     this.keepInWindow = keepInWindow;
  171.     this.hideTree = hideTree
  172.     this.hideParents = hideParents;
  173.     this.hideChildren = hideChildren;
  174.     this.hideTop = hideTop;
  175.     this.hasChildVisible = false;
  176.     this.isOn = false;
  177.     this.hideTimer = null;
  178.     this.childOverlap = childOverlap;
  179.     this.currentItem = null;
  180.     this.hideSelf = hideSelf;
  181.         
  182.     if (hasParent) {
  183.         this.hasParent = true;
  184.         this.parentMenu = openCont;
  185.         if (NN4) { this.parentItem = openItem; this.parentItem.child = this }}
  186.     else { this.hasParent = false; }
  187.   if (IE4) {
  188.         with (this.style) {
  189.             width = this.width;
  190.             borderWidth = 1;
  191.             borderColor = this.borderColour;
  192.             borderStyle = "solid";
  193.             zIndex = iHighestZ; }
  194.         this.lastItem.style.border="";
  195.         this.showIt(false);
  196.         this.onselectstart = cancelSelect;
  197.         this.moveTo = moveTo;
  198.         this.moveTo(0,0);
  199.     }
  200.     if (NN4) {
  201.         this.bgColor = this.borderColour;
  202.         this.fullHeight = this.lastItem.top + this.lastItem.clip.bottom + 1;
  203.         this.clip.right = this.width;
  204.         this.clip.bottom = this.fullHeight;
  205.     }
  206. }
  207.  
  208. function Show(menuName, e){
  209.     if (!bIsLoaded) return;
  210.     LinkElement = (IE4) ? event.srcElement : e.target;
  211.     if (!bBeingCreated && !bAllFinished) LoadMenus();
  212.     LinkElement.menuName = menuName;    
  213.     ShowIt(e);
  214. }
  215.  
  216. function ShowIt(e){
  217.     if (!bIsLoaded || !bAllFinished) return true;
  218.     hideAll();
  219.     
  220.     LinkElement = (IE4) ? event.srcElement : e.target;
  221.     currentMenu = eval(LinkElement.menuName);
  222.     currentMenu.hasParent = false;
  223.     currentMenu.parentTree.startChild = currentMenu;
  224.     currentMenu.moveTo(currentMenu.xPos, currentMenu.yPos);
  225.     currentMenu.isOn = true;
  226.     currentMenu.showIt(true);
  227.     return false;
  228. }
  229.  
  230. function menuOver(e) {
  231.     this.isOn = true;
  232.     bOverMenu = true;
  233.     currentMenu = this;
  234.     if (this.hideTimer) clearTimeout(this.hideTimer);
  235. }
  236.  
  237. function menuOut() {
  238.     if (IE4) { if (window.event.srcElement.contains(window.event.toElement)) return; }
  239.     this.isOn = false;
  240.     bOverMenu = false;
  241.     window.status = "";
  242.     allTimer = setTimeout("currentMenu.hideTree()",10);
  243. }
  244.  
  245. function itemOver(){
  246.     if (keepHilite) {
  247.         if (this.container.currentItem && this.container.currentItem != this) {
  248.             if (IE4) with (this.container.currentItem.style) { backgroundColor = backCol }
  249.             if (NN4) this.container.currentItem.bgColor = backCol
  250.         }}
  251.     if (IE4) {
  252.         theEvent = window.event;
  253.         if (theEvent.srcElement.tagName == "IMG") return;
  254.         this.style.backgroundColor = this.container.overColour; }
  255.     else { this.bgColor = this.container.overColour; }
  256.  
  257.     window.status = this.text;
  258.     this.container.currentItem = this;
  259.     if (this.container.hasChildVisible) { this.container.hideChildren(this); }
  260.     if (this.hasChildren) { 
  261.         horOffset = (this.container.width - this.container.childOverlap);
  262.         if (NN4) {
  263.             this.childX = this.container.left + horOffset;
  264.             this.childY = (this.pageY+this.clip.top) + childOffset; }
  265.         else {
  266.             this.childX = this.container.style.pixelLeft + horOffset;
  267.             this.childY = this.offsetTop + this.container.style.pixelTop + childOffset + 1; }
  268.         this.child.moveTo(this.childX, this.childY);
  269.         this.child.keepInWindow();
  270.         this.container.hasChildVisible = true;
  271.         this.container.visibleChild = this.child;
  272.         this.child.showIt(true);
  273.     }
  274. }
  275.  
  276. function itemOut() {
  277.     if (IE4) {
  278.         theEvent = window.event;
  279.         if (theEvent.srcElement.contains(theEvent.toElement)
  280.      || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement)))
  281.         return;
  282.         if (!keepHilite) this.style.backgroundColor = backCol; }
  283.     else {
  284.         if (!keepHilite) this.bgColor = backCol;
  285.         if (!bOverMenu) { allTimer = setTimeout("currentMenu.hideTree()",10); }
  286.     }
  287. }
  288.  
  289. function moveTo(xPos, yPos) {
  290.     this.style.pixelLeft = xPos;
  291.     this.style.pixelTop = yPos;
  292. }
  293.  
  294. function showIt(on) {
  295.     if (NN4) {
  296.         this.visibility = (on) ? "show" : "hide";
  297.         if (keepHilite && this.currentItem) { this.currentItem.bgColor = this.backColour; }}
  298.     else {
  299.         this.style.visibility = (on) ? "visible" : "hidden";
  300.         if (keepHilite && this.currentItem) {
  301.             with (this.currentItem.style) {
  302.                 backgroundColor = this.backColour;
  303.                 color = this.fontColour; }}}
  304.     this.currentItem = null;
  305. }
  306.  
  307. function keepInWindow() {
  308.     scrBars = 20;
  309.     botScrBar = scrBars;
  310.     rtScrBar = scrBars;
  311.     if (NN4) {
  312.         winRight = (window.pageXOffset + window.innerWidth) - rtScrBar;
  313.         rightPos = this.left + this.width;
  314.         if (rightPos > winRight) {
  315.             if (this.hasParent) {
  316.                 parentLeft = this.parentMenu.left;
  317.                 newLeft = ((parentLeft-this.width) + this.childOverlap);
  318.                 this.left = newLeft;}
  319.             else {
  320.                 dif = rightPos - winRight;
  321.                 this.left -= dif; }}
  322.         winBot = (window.pageYOffset + window.innerHeight) - botScrBar ;
  323.         botPos = this.top + this.fullHeight;
  324.         if (botPos > winBot) {
  325.             dif = botPos - winBot;
  326.             this.top -= dif; }
  327.         winLeft = window.pageXOffset;
  328.         leftPos = this.left;
  329.         if (leftPos < winLeft) {
  330.             if (this.hasParent) {
  331.                 parentLeft = this.parentMenu.left;
  332.                 newLeft = ((parentLeft+this.width) - this.childOverlap);
  333.                 this.left = newLeft; }
  334.             else { this.left = 5;}}}
  335.     else {
  336.     winRight = (window.document.body.scrollLeft + window.document.body.clientWidth) - rtScrBar;
  337.         rightPos = this.style.pixelLeft + this.width;
  338.         if (rightPos > winRight) {
  339.             if (this.hasParent) {
  340.                 parentLeft = this.parentMenu.style.pixelLeft;
  341.                 newLeft = ((parentLeft - this.width) + this.childOverlap);
  342.                 this.style.pixelLeft = newLeft; }
  343.             else {
  344.                 dif = rightPos - winRight;
  345.                 this.style.pixelLeft -= dif; }}
  346.  
  347.         winBot = (window.document.body.scrollTop + window.document.body.clientHeight) - botScrBar;
  348.         botPos = this.style.pixelTop + this.fullHeight;
  349.  
  350.         if (botPos > winBot) {
  351.             dif = botPos - winBot;
  352.             this.style.pixelTop -= dif; }
  353.         
  354.         winLeft = window.document.body.scrollLeft;
  355.         leftPos = this.style.pixelLeft;
  356.  
  357.         if (leftPos < winLeft) {
  358.             if (this.hasParent) {
  359.                 parentLeft = this.parentMenu.style.pixelLeft;
  360.                 newLeft = ((parentLeft+this.width) - this.childOverlap);
  361.                 this.style.pixelLeft = newLeft; }
  362.             else { this.style.pixelLeft = 5; }}}
  363. }
  364.  
  365. function linkIt() {
  366.     if (this.URL.indexOf("javascript:")!=-1) eval(this.URL)
  367.     else window.location.href = this.URL;
  368. }
  369.  
  370. function Hide(menuName){
  371.     if (!bIsLoaded || !bAllFinished) return;
  372.     whichEl = eval(menuName);
  373.     whichEl.isOn = false;
  374.     whichEl.hideTop();
  375. }
  376.  
  377. function hideAll() {
  378.     for(i=1; i<topCount; i++) {
  379.         temp = eval("Menu" + i + ".startChild");
  380.         temp.isOn = false;
  381.         if (temp.hasChildVisible) temp.hideChildren();
  382.         temp.showIt(false);
  383.     }    
  384. }
  385.  
  386. function hideTree() {
  387.     allTimer = null;
  388.     if (bOverMenu) return;
  389.     if (this.hasChildVisible) {
  390.         this.hideChildren(); }
  391.     this.hideParents();
  392. }
  393.  
  394. function hideTop() {
  395.     whichTop = this;
  396.     this.hideTimer = setTimeout("if(whichTop.hideSelf)whichTop.hideSelf()",mSecsVis);
  397. }
  398.  
  399. function hideSelf() {
  400.     this.hideTimer = null;
  401.     if (!this.isOn && !bOverMenu) { 
  402.         this.showIt(false);}
  403. }
  404.  
  405. function hideParents() {
  406.     tempMenu = this;
  407.     while (tempMenu.hasParent) {
  408.         tempMenu.showIt(false);
  409.         tempMenu.parentMenu.isOn = false;        
  410.         tempMenu = tempMenu.parentMenu;
  411.     }
  412.     tempMenu.hideTop();
  413. }
  414.  
  415. function hideChildren(item) {
  416.     tempMenu = this.visibleChild;
  417.     while (tempMenu.hasChildVisible) {
  418.         tempMenu.visibleChild.showIt(false);
  419.         tempMenu.hasChildVisible = false;
  420.         tempMenu = tempMenu.visibleChild;
  421.     }
  422.     if (!this.isOn || !item.hasChildren || this.visibleChild != this.child) {
  423.         this.visibleChild.showIt(false);
  424.         this.hasChildVisible = false; }
  425. }
  426.  
  427. function cancelSelect(){ return false }
  428.