Navigation menu

MediaWiki:Gadget-Tabs.js: Difference between revisions

From Metroid Wiki
m (1 revision imported)
(remove section linking and update classes)
 
Line 3: Line 3:
$(".tab").click(function () {
$(".tab").click(function () {
var $siblings= $(this).parent().children();
var $siblings= $(this).parent().children();
var $alltabs = $(this).closest(".tabcontainer");
var $alltabs = $(this).closest(".tabheader");
var $content = $alltabs.parent().children(".tabcontents");
var $content = $alltabs.parent().children(".tabcontents");


Line 14: Line 14:
var index = $siblings.index(this);
var index = $siblings.index(this);
$content.children().eq(index).addClass("content--active");
$content.children().eq(index).addClass("content--active");
});
// When a section link is clicked or a page is loaded with a section link,
// we select the tab containing the section anchor
function selectAnchorTab() {
if (window.location.hash) {
var tabIndex = $(window.location.hash).closest(".tabcontents .content").index();
$(window.location.hash).closest(".zw-tabs")
.children(".tabcontainer")
.children(".tab")
.eq(tabIndex)
.click();
}
}
selectAnchorTab();
addEventListener("hashchange", function() {
selectAnchorTab();
});
});
});
});

Latest revision as of 20:11, 31 January 2024

$(document).ready(function(){
	// When a tab is clicked
	$(".tab").click(function () {
		var $siblings= $(this).parent().children();
		var $alltabs = $(this).closest(".tabheader");
		var $content = $alltabs.parent().children(".tabcontents");

		// switch all tabs off
		$siblings.removeClass("active");
		$content.children().removeClass("content--active");

		// switch this tab on
		$(this).addClass("active");
		var index = $siblings.index(this);
		$content.children().eq(index).addClass("content--active");
	});
});