Difference between revisions of "MediaWiki:Common.js"

From Legislation Community Editorial Wiki
Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: // When the document loads do everything inside here ... $(document).ready(function(){ // hide all...")
 
Line 18: Line 18:
 
$.cookie("currentNavParent", "nav-5");
 
$.cookie("currentNavParent", "nav-5");
 
} else {
 
} else {
$.removeCookie("currentNavParent");
+
// $.removeCookie("currentNavParent");
 
$("ul.nav-level1 li a").removeClass("active");
 
$("ul.nav-level1 li a").removeClass("active");
 
$("ul.nav-level2").removeClass("active");
 
$("ul.nav-level2").removeClass("active");

Revision as of 11:52, 23 October 2014

/* Any JavaScript here will be loaded for all users on every page load. */

// When the document loads do everything inside here ...
$(document).ready(function(){
	// hide all nav-level2 content
	$(".nav-level2").hide();

	// determine current url's place within the site navigation
	if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/revising_legislation") != -1) {
		$.cookie("currentNavParent", "nav-1");
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_principles") != -1) {
		$.cookie("currentNavParent", "nav-2");
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/preparation_tasks") != -1) {
		$.cookie("currentNavParent", "nav-3");
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_update") != -1) {
		$.cookie("currentNavParent", "nav-4");
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/corrective_work") != -1) {
		$.cookie("currentNavParent", "nav-5");
	} else {
//		$.removeCookie("currentNavParent");
		$("ul.nav-level1 li a").removeClass("active");
		$("ul.nav-level2").removeClass("active");
		$.cookie("showNavigationDrawer", "false");
	}
	
	// if cookie has been set to show navigation drawer then display relevant nav-level2 items
	if ($.cookie("showNavigationDrawer") == "true") {
		$("#"+$.cookie("currentNavParent")).addClass("active");
		$("ul.nav-level2."+$.cookie("currentNavParent")).addClass("active");
		$("ul.nav-level2."+$.cookie("currentNavParent")).show();
	}

	// When a top-level link from the navigation is clicked 
	$("nav > ul > li > a").click(function() {
		var active_link = $(this).attr("id");

		// if the nav-level1 item clicked was already active then remove its active status, slide up navigation drawer, and update cookie
		if ($(this).hasClass("active")) {
			$("ul.nav-level1 li a").removeClass("active");
			$("ul.nav-level2.active").removeClass("active");
			$("ul.nav-level2").slideUp();
			$.cookie('showNavigationDrawer', 'false');
		}
		// else slide up previously active nav-level2 content, set the new active nav-level1 item, slide down navigation drawer, and update cookie
		else {
			$("ul.nav-level2.active").hide();
			$("ul.nav-level1 li a").removeClass("active");
			$("ul.nav-level2").removeClass("active");
			$(this).addClass("active");
			$("ul.nav-level2."+active_link).addClass("active");
			$("ul.nav-level2."+active_link).slideDown();
			$.cookie('showNavigationDrawer', 'true');
		}
	});
});