Difference between revisions of "MediaWiki:Common.js"

From Legislation Community Editorial Wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
// 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) {
$.cookie("currentNavParent", "nav-1");
+
$.cookie("currentNavParent", "nav-1", { path: "/" });
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_principles") != -1) {
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_principles") != -1) {
$.cookie("currentNavParent", "nav-2");
+
$.cookie("currentNavParent", "nav-2", { path: "/" });
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/preparation_tasks") != -1) {
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/preparation_tasks") != -1) {
$.cookie("currentNavParent", "nav-3");
+
$.cookie("currentNavParent", "nav-3", { path: "/" });
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_update") != -1) {
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/editorial_update") != -1) {
$.cookie("currentNavParent", "nav-4");
+
$.cookie("currentNavParent", "nav-4", { path: "/" });
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/corrective_work") != -1) {
 
} else if (decodeURIComponent(window.location.pathname).toLowerCase().indexOf("/wiki/corrective_work") != -1) {
$.cookie("currentNavParent", "nav-5");
+
$.cookie("currentNavParent", "nav-5", { path: "/" });
 
} else {
 
} else {
 
$("ul.nav-level1 li a").removeClass("active");
 
$("ul.nav-level1 li a").removeClass("active");
 
$("ul.nav-level2").removeClass("active");
 
$("ul.nav-level2").removeClass("active");
$.cookie("showNavigationDrawer", "false");
+
$.cookie("showNavigationDrawer", "false", { path: "/" });
 
}
 
}
 
 
Line 39: Line 39:
 
$("ul.nav-level2.active").removeClass("active");
 
$("ul.nav-level2.active").removeClass("active");
 
$("ul.nav-level2").slideUp();
 
$("ul.nav-level2").slideUp();
$.cookie('showNavigationDrawer', 'false');
+
$.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 slide up previously active nav-level2 content, set the new active nav-level1 item, slide down navigation drawer, and update cookie
Line 49: Line 49:
 
$("ul.nav-level2."+active_link).addClass("active");
 
$("ul.nav-level2."+active_link).addClass("active");
 
$("ul.nav-level2."+active_link).slideDown();
 
$("ul.nav-level2."+active_link).slideDown();
$.cookie('showNavigationDrawer', 'true');
+
$.cookie('showNavigationDrawer', 'true', { path: "/" });
 
}
 
}
 
});
 
});
 
});
 
});

Revision as of 12:02, 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", { 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: "/" });
		}
	});
});