From c9416d543c7539b1a6538a1a65bb614dfb81dc67 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Thu, 29 Sep 2016 16:25:24 +0300
Subject: [PATCH] Improved record tab hash handling for the initially active
 tab.

---
 themes/bootstrap3/js/record.js | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/themes/bootstrap3/js/record.js b/themes/bootstrap3/js/record.js
index 04ca8f2d523..6d51bc0476f 100644
--- a/themes/bootstrap3/js/record.js
+++ b/themes/bootstrap3/js/record.js
@@ -183,6 +183,8 @@ function ajaxLoadTab($newTab, tabid, setHash) {
     }
     if (typeof setHash == 'undefined' || setHash) {
       window.location.hash = tabid;
+    } else {
+      removeHashFromLocation();
     }
   });
   return false;
@@ -264,6 +266,15 @@ function applyRecordTabHash() {
   }
 }
 
+function removeHashFromLocation() {
+  if (window.history.replaceState) {
+    var href = window.location.href.split('#');
+    window.history.replaceState({}, document.title, href[0]);  
+  } else {
+    window.location.hash = '#';  
+  }
+}
+
 $(window).on('hashchange', applyRecordTabHash);
 
 function recordDocReady() {
@@ -293,7 +304,11 @@ function recordDocReady() {
     $(this).tab('show');
     if ($top.find('.' + tabid + '-tab').length > 0) {
       $top.find('.' + tabid + '-tab').addClass('active');
-      window.location.hash = tabid;
+      if ($(this).parent().hasClass('initiallyActive')) {
+        removeHashFromLocation();
+      } else {
+        window.location.hash = tabid;
+      }
       return false;
     } else {
       var newTab = getNewRecordTab(tabid).addClass('active');
-- 
GitLab