/** * nav.js * * This script contains functions for properly rendering * navigation state for the site's top level nav. */ /** * Redirect to a relative URL on a new host IF the required hostname is present */ function redirectHost(requiredHostname,targetHostname) { if (document.location.host.indexOf(requiredHostname) != -1) { var l = document.location; var url = l.protocol + "//" + targetHostname + l.pathname; if (l.hash) url += l.hash; if (l.search) url += l.search; document.location = url; } } /** * Redirect to an HTTPS url if you match the current hostname * @param requiredHostname * @return */ function redirectSSL(requiredHostname,targetHostname) { var l = document.location; if (l.host.indexOf(requiredHostname) != -1) { if (l.protocol.indexOf("http:") != -1) { var host = targetHostname == undefined?l.host:targetHostname; var url = "https://" + host + l.pathname; if (l.hash) url += l.hash; if (l.search) url += l.search; document.location = url; } } } /** * Returns just the resource portion of the URL */ function getResourceName() { var file_name = document.location.href; var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?"); end = (file_name.indexOf("#") == -1)?end:file_name.indexOf("#"); // chop anchors too return file_name.substring(file_name.lastIndexOf("/")+1, end); } /** * Selected nav items are set by matching * the start of the resource with the nav item. * For example, anything starting with 'download' will match * the nav item 'download'. */ function initNav() { var resourceName = getResourceName(); $("#nav").find("a").each( function() { // Toggle selected state if (resourceName.indexOf(this.id) == 0) { // starts with id anchor $("#" + this.id).parent("li").addClass("selected"); } } ); // Assign click support // Assign hover support $("#nav > ul > li").each( function() { var anchor = $(this).find("a:first"); setNavItemClick(this,anchor); setNavItemHover(this); } ); // Assign home click support setNavItemClick( $("#home") ); // Customize search box for safari if ($.browser.safari) { $("#search-input").attr("results","5"); } } /** * Selected menu items are set by matching resource */ function initMenu() { var resourceName = getResourceName(); var el = $(".menu").find("a[href='" + resourceName +"']:first"); if (el) { // match the element whose href is the current document el.parent("li").addClass("selected"); } // Add hover support // Add click 'anywhere support $(".menu").find("li").each( function() { var anchor=$(this).find("a:first"); $(this).hover( function() { $(this).addClass("hover"); anchor.addClass("hover"); }, function() { $(this).removeClass("hover"); anchor.removeClass("hover"); } ); setNavItemClick(this,anchor); } ); } /** * Set an item click to the same href as an anchor */ function setNavItemClick(item, anchor) { var href = anchor == undefined?"index.html":$(anchor).attr("href"); $(item).click( function() { top.location.href=href; } ); } /** * Assign a hover over effect for list items */ function setNavItemHover(item) { if (!$(item).hasClass("selected")) { $(item).hover( function() { $(item).addClass("hover");}, function() { $(item).removeClass("hover");} ); } } // Browser validation code - Jquery 1.2.x does *not* work in Safari 2 or older!!! //alert($.browser.safari + $.browser.version); if ($.browser.safari && $.browser.version < 522) { top.location.href="incompatible.html"; }