Difference between revisions of "MediaWiki:Common.js"

From Legislation Community Editorial Wiki
Jump to navigation Jump to search
 
Line 6: Line 6:
 
$(".nav-level2").hide();
 
$(".nav-level2").hide();
  
 +
/*
 
// determine current url's place within the site navigation
 
// determine current url's place within the site navigation
 
if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/revising_legislation") != -1) {
 
if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/revising_legislation") != -1) {
Line 22: Line 23:
 
$.cookie("showNavigationDrawer", "false", { path: "/" });
 
$.cookie("showNavigationDrawer", "false", { path: "/" });
 
}
 
}
+
*/
 +
/*
 
// if cookie has been set to show navigation drawer then display relevant nav-level2 items
 
// if cookie has been set to show navigation drawer then display relevant nav-level2 items
 
if ($.cookie("showNavigationDrawer") == "true") {
 
if ($.cookie("showNavigationDrawer") == "true") {
Line 29: Line 31:
 
$("ul.nav-level2."+$.cookie("currentNavParent")).show();
 
$("ul.nav-level2."+$.cookie("currentNavParent")).show();
 
}
 
}
 +
*/
  
 
// When a top-level link from the navigation is clicked  
 
// When a top-level link from the navigation is clicked  

Latest revision as of 11:23, 28 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", { path: "/" });
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_principles") != -1) {
		$.cookie("currentNavParent", "nav-2", { path: "/" });
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/preparation_tasks") != -1) {
		$.cookie("currentNavParent", "nav-3", { path: "/" });
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_update") != -1) {
		$.cookie("currentNavParent", "nav-4", { path: "/" });
	} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/corrective_work") != -1) {
		$.cookie("currentNavParent", "nav-5", { path: "/" });
	} else {
		$("ul.nav-level1 li a").removeClass("active");
		$("ul.nav-level2").removeClass("active");
		$.cookie("showNavigationDrawer", "false", { path: "/" });
	}
	*/
	/*
	// 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', { path: "/" });
		}
		// 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', { path: "/" });
		}
	});
});