summaryrefslogtreecommitdiff
path: root/result/krafcik.js
diff options
context:
space:
mode:
Diffstat (limited to 'result/krafcik.js')
-rw-r--r--result/krafcik.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/result/krafcik.js b/result/krafcik.js
index cac3371..ba8ccf9 100644
--- a/result/krafcik.js
+++ b/result/krafcik.js
@@ -1,5 +1,16 @@
$(document).ready(function() {
+ var initTab = function(tab, push) {
+ if (!tab) {
+ tab = location.hash.replace('#', '') || 'styles';
+ }
+ console.log(tab, push);
+ $(`a#${tab}-tab`).tab('show');
+ if (push) {
+ history.pushState({}, '', '#' + tab);
+ }
+ };
+
$.when(
$.getJSON('beers.json'),
$.getJSON('breweries.json'),
@@ -400,13 +411,19 @@ $(document).ready(function() {
changeTimeout = setTimeout(updateCharts, 500);
});
- var pageHash = location.hash.replace('#', '') || 'styles';
- $(`a#${pageHash}-tab`).click().trigger('shown.bs.tab');
+ initTab(false, true);
updateCharts();
});
$('#tab-menu a').on('click', function (e) {
e.preventDefault();
- $(this).tab('show');
+ e.stopImmediatePropagation();
+ initTab($(this).attr('aria-controls'), true);
+ return false;
});
+
+ $(window).on('popstate', function(ev) {
+ initTab(false, false);
+ });
+
});