in src/assets/js/tabs.js [1:56]
function setupTabs(container, storageName, defaultTab) {
var tabs = $('li a', container);
// console.log('>> #tabs', tabs.length, storageName);
// Return 'foo' from either '#foo' or '?tab=foo'
function getTabIdFromQuery(query) {
var match = query.match(/(#|\btab=)([\w-]+)/);
return match ? match[2] : '';
}
function clickHandler(e) {
// console.log('>> click event for tab:', $(this));
e.preventDefault();
$(this).tab('show');
var id = getTabIdFromQuery($(this).attr('href'));
// Persist to local storage so we can pre-select around the site
if (storageName && window.localStorage) {
// console.log('>> setting localStorage', storageName, id);
window.localStorage.setItem(storageName, id);
}
var l = location, query = '?tab=' + id;
if (id && l.search != query) {
var url = l.protocol + '//' + l.host + l.pathname + query + l.hash;
// console.log('>> history.replaceState of', url);
history.replaceState(undefined, undefined, url);
} else {
// console.log('>> location.search is already "', query, '"');
}
}
function selectTab(id) {
var tab = tabs.filter('[href="#' + id + '"]');
// console.log('>> selectedTab:', id, tab);
tab.click();
}
tabs.click(clickHandler);
var selectedTab;
if (selectedTab = getTabIdFromQuery(location.search)) {
// console.log('>> setting tab from location:', selectedTab)
selectTab(selectedTab);
} else if (storageName && window.localStorage
&& (selectedTab = window.localStorage.getItem(storageName))) {
// console.log('>> setting tab from localStorage: ', selectedTab)
selectTab(selectedTab);
} else if (defaultTab) {
// console.log('>> setting tab from defaultTab')
selectTab(defaultTab);
} else {
// console.log('>> not setting the tab - using page default')
}
}