From 1dfde3501818ce43345a929e4d033d915bda7843 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 6 Sep 2019 14:57:39 +0200 Subject: [slx-fixes.js] Put current tab on pages with tab-panes in history Also restore tab properly on reload or when sending link to other people. --- script/slx-fixes.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/script/slx-fixes.js b/script/slx-fixes.js index e8380702..e3b42812 100644 --- a/script/slx-fixes.js +++ b/script/slx-fixes.js @@ -122,3 +122,17 @@ jQuery.cachedScript = function(url, callback, options) { }); return jQuery.ajax( options ); }; + +// Restore tab state on refresh and add it to URL so copying URLs works +$(document).ready(function() { + if ($('a[data-toggle="tab"]').click(function (e) { + history.pushState(null, null, this.getAttribute('href')); + }).length === 0) return; + var initTab = $('li.active > a[data-toggle="tab"]').attr('href'); + var bla = function() { + var h = location.hash || initTab; + $('a[data-toggle="tab"][href="' + h + '"]').tab('show'); + }; + bla(); + $(window).on('popstate', bla); +}); -- cgit v1.2.3-55-g7522