/** * JS file using jQuery to add necessary styling to HTML leftnav menu's for VeriSign sites * Author: E Grobler * Version: 1.2 * Date: 25/08/2009 */ $(document).ready(function(){ /* Check if url contains 'index.html'. If not then add it to the url. */ //First check if it's got some other name than index.html... var curr_url = ""; var fname = ($.url.attr("file") == null) ? "" : $.url.attr("file"); switch(fname) { case "": curr_url = $.url.attr("path") + "index.html"; break; case "index.html": curr_url = $.url.attr("path");break; default: curr_url = $.url.attr("path").substr(0,($.url.attr("path").length - $.url.attr("file").length)) + "index.html";break; } var parent_url = ""; var notthere = 0; while (notthere < 1) { //If topmost URL, then parent and current url is the same, otherwise generate parent url. parent_url = (curr_url == $("div#leftnav ul a:first").attr("href")) ? curr_url : curr_url.substr(0, curr_url.substr(0, curr_url.lastIndexOf("/")).lastIndexOf("/")+1) + "index.html"; //If the current url doesn't exist in the leftnav, then set it equal to its parent if ($("div#leftnav ul").find("li a[href^='"+curr_url+"']").length == 0) { curr_url = parent_url; } //set variable to length (occurences of the current url) notthere = $("div#leftnav ul").find("li a[href^='"+curr_url+"']").length; //If current page url isn't part of the navigation, just set notthere var to 1 to get out of the endless loop if ((notthere < 1) && (curr_url == "/index.html")) { notthere = 1; } } //Adding classes to relevant
  • tags so the correct items are highlighted var curr_url_el = $("a[href='" + curr_url + "']"); var parent_count = curr_url_el.parents("li").length; curr_url_el.parents("li:eq(0):not([class='main'])").addClass("active"); if (parent_count == 2) { curr_url_el.parents("li:eq(1):not([class='main'])").addClass("activechild"); } });