m (select first non-hidden tab, change page hash according to selected tab) |
m (preserve hash when initializing each tab) |
||
Line 1: | Line 1: | ||
$('div.tabdiv').each(function() { | $('div.tabdiv').each(function() { | ||
var hash = window.location.hash; | |||
var tabs = $(this); | var tabs = $(this); | ||
tabs.find('> ul a').removeAttr('href'); | tabs.find('> ul a').removeAttr('href'); | ||
Line 10: | Line 11: | ||
}); | }); | ||
tabs.find('> ul > li:not(".hidden")').first().click(); | tabs.find('> ul > li:not(".hidden")').first().click(); | ||
window.location.hash = hash; | |||
}); | }); | ||
Revision as of 01:19, 17 June 2020
$('div.tabdiv').each(function() {
var hash = window.location.hash;
var tabs = $(this);
tabs.find('> ul a').removeAttr('href');
tabs.find('> ul > li').click(function() {
var li = $(this);
var index = li.index();
li.addClass('active').siblings('li').removeClass('active');
tabs.children('div').eq(index).show().siblings('div').hide();
window.location.hash = $(li).attr("id");
});
tabs.find('> ul > li:not(".hidden")').first().click();
window.location.hash = hash;
});
(function(window, $) {
var tabbers = window.location.hash;
tabbers = tabbers.replace(/tabtag/, '@');
tabbers = tabbers.split('/') || [];
while(tabbers.length) {
var route = tabbers.shift() || '';
route = route.split('@');
var child = route[1] || '';
var parent = route[0] || '';
$(parent + 'tabtag' + child).click();
}
})(window, $);