From f52554a4146bc60c2f797c16b8667de4bad6f8d5 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 20 Jan 2021 01:04:24 +0100 Subject: Hash navigation --- result/index.html | 4 ++-- result/krafcik.js | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'result') diff --git a/result/index.html b/result/index.html index e136110..cfd2473 100644 --- a/result/index.html +++ b/result/index.html @@ -38,7 +38,7 @@
-
+
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); + }); + }); -- cgit v1.2.3