/** * Version 2.0 * Author: Rob Perez * Date: August 20, 2010 * * Usage: * * Set a flag at the beginning of generateLeftNav to modify expansion behavior of the nav if desired. * * Somewhere prior to including the nav, set either noLeftNavExpansion or parentUrl var. * * * * */ generateLefNav = function(){ generateLeftNav(); } generateLeftNav = function(){ var hasParentUrl = false; var urlMatch = false; if (typeof (noLeftNavExpansion) != 'undefined'){ return false; // the no left nav expansion flag has been set. No expansion. We are done. } if (typeof (parentUrl) != 'undefined'){ parentUrl = window.location.protocol + "//" + window.location.host + parentUrl; // goes where you go, works where you work! hasParentUrl = true; //there is a parent url set. We'll attempt to expand the parent category of this page. } $("div#leftnav ul a").each(function(i){ if (hasParentUrl) { if (this.href == parentUrl || this.href == parentUrl+"index.html") { $(this).parents("li:eq(0):not([class='main'])").addClass("activechild"); return true; // a match to the parent. Menu expanded. } } else var myLocation = "" + window.location; if (this.href == myLocation || this.href + "index.html" == myLocation) { if ($(this).parents().length > 1) { $(this).parents("li:eq(1):not([class='main'])").addClass("activechild"); } $(this).parents("li:eq(0):not([class='main'])").addClass("active"); $(this).css("cursor", "text"); $(this).css("textDecoration", "none"); $(this).click(function(){ return false; }); urlMatch = true; return true; // a match with this page's URL; menu expanded. And...we're done. } }); if(hasParentUrl){ return false; // if we've tried to match a parent and failed, pull the ripcord to avoid lots of unwanted recursion. } if(!urlMatch){ // if there's no match for the current location, try to derive and set a parentUrl and go once more. parentUrl = deriveParent(); generateLefNav(); } } deriveParent = function(){ pathArray = window.location.pathname.split( '/' ); newPathname = ""; for ( i = 0; i < pathArray.length-3; i++ ) { if (i != 0) { newPathname += "/"; } newPathname += pathArray[i]; } return newPathname + "/"; }