From 68a03bc6748439da18c951ff1497b457c4150023 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Jun 2013 00:55:14 +0200 Subject: [PATCH] When a tab is selected, change the fragment id And when a page is visited, active the tab identified by the fragment id. This allows linking to a specific tab. Fixes #93. --- src/root/layout.tt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/root/layout.tt b/src/root/layout.tt index 688d099e..8768ad40 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -85,6 +85,23 @@ bootbox.animate(false); $(".hydra-popover").popover({}); + + /* Ensure that pressing the back button on another page + navigates back to the previously selected tab on this + page. */ + $(function() { + $('.nav-tabs').bind('show', function(e) { + var pattern = /#.+/gi; + var id = e.target.toString().match(pattern)[0]; + history.replaceState(null, "", id); + }); + }); + + $(function() { + if (window.location.hash) { + $(".nav a[href='" + window.location.hash + "']").tab('show'); + } + }) });