Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- * Filename:
- * vertnav.js
- *
- * Purpose:
- * Facilitate a vertical navigation menu with collapsable submenus.
- * This code will automatically detect which menu items have submenus
- * and handle them accordingly.
- *
- * Notes:
- * DON'T bother using this file to:
- * -change look/feel of menu: this is done from CSS script (ie: vertnav.css).
- * -add/remove/edit menu items: this is done within the HTML
- *
- * .
- *
- *
- */
- /*
- *
- * CSS settings:
- * Normally never has to be touched, unless class names are changed
- * in the CSS or id is changed of the div wrapping the navigation <li>
- * tags(list items) in the HTML.
- * TO CHANGE LOOK/FEEL: simly edit the corresponding CSS class entries (not here)!!
- *
- * The navconfig_ settings should match with existing class entries in a linked stylesheet or CSS script
- *
- *
- */
- var vertnavcfg_subshow_class = "subshow"; /* class used when toggled visible */
- var vertnavcfg_subhide_class = "subhide"; /* class used when toggled hidden */
- var vertnavcfg_hashiddensub_class = "hashiddensub"; /* class used when parent has a hidden submenu */
- var vertnavcfg_hasvisiblesub_class = "hasvisiblesub"; /* class used when parent has a visible submenu */
- var vertnavcfg_navlistdiv_id = "vertnavlist"; /* div wrapping the navigation <li> tags (list items) */
- /*
- *
- * register event handler to initialize the navigation system on page load
- *
- */
- window.onload=vertnav_init;
- /*
- *
- * state handling variables
- *
- */
- var vertnavst_subclick = false;
- /**
- * Function:
- * toggleNav
- *
- * Purpose:
- * for use on click event to
- * appropriately change the classes according to above configuration
- * typically to expand the menu to reveal a submenu
- *
- */
- function vertnav_toggle(what){
- /*
- * get submenu within the expected <li> calling this function (aka var what)
- */
- var subnav = what.getElementsByTagName("ul");
- for(i=0;i<subnav.length;i++) { /*--loop thru 'submenu', typically should only be 1 iteration--*/
- if (vertnavst_subclick) { /* if a submenu item is being clicked */
- vertnavst_subclick = false;
- return false;
- }
- if (subnav[i].className == vertnavcfg_subshow_class)
- { /* if visible, make hidden */
- subnav[i].className = vertnavcfg_subhide_class;
- subnav[i].parentNode.className = vertnavcfg_hashiddensub_class;
- }
- else
- { /* if hidden, make visible */
- subnav[i].className = vertnavcfg_subshow_class;
- subnav[i].parentNode.className = vertnavcfg_hasvisiblesub_class;
- }
- } /*--end 'submenu' loop--*/
- } /*--vertnav_toggle()--*/
- /**
- * Function:
- * initNav
- *
- * Purpose:
- * for use on page load (or similar) to
- * appropriately change the classes according to above configuration
- *
- */
- function vertnav_init() {
- /*
- * hide all the nested ULs ('submenus') the #leftnavlist div
- */
- var subnav = document.getElementById(vertnavcfg_navlistdiv_id).getElementsByTagName("ul");
- for (i = 0; i < subnav.length ; i++) { /*--loop thru all the 'submenus'--*/
- subnav[i].className = vertnavcfg_subhide_class; /* change class to the one indicated as 'hidden' */
- subnav[i].parentNode.className = vertnavcfg_hashiddensub_class; /* change class to one indicating the parent li has a 'hidden' submenu */
- subnav[i].parentNode.onclick = function(){vertnav_toggle(this);} /* register toggleNav() as the onclick event handler for the parent li */
- var subnavli = subnav[i].parentNode.getElementsByTagName("li"); /* get submenu entries */
- for(j=0;j<subnavli.length;j++) { /* loop thru submenu entries */
- subnavli[j].onclick = function() {vertnavst_subclick = true;} /* register state handling */
- }
- } /*--end 'submenus' loop--*/
- } /*--vertnav_init()--*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement