Browse Source

Capture anchors and convert them to tab if tab not present

pull/2589/head
Manny Dinssa 2 years ago
parent
commit
bf8b4f2037
  1. 11
      app/frontend/controllers/tabs_controller.js

11
app/frontend/controllers/tabs_controller.js

@ -1,7 +1,12 @@
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const tab = urlParams.get("tab");
let tab = urlParams.get('tab');
if (!tab && window.location.hash) {
tab = window.location.hash.substring(1);
urlParams.set('tab', tab);
history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`);
}
function activateTab(tabId) {
const tabElement = document.getElementById(tabId);
if (tabElement) {
@ -14,7 +19,7 @@ document.addEventListener("DOMContentLoaded", function() {
event.preventDefault();
const targetId = this.getAttribute('href').substring(1);
activateTab(targetId);
urlParams.set("tab", targetId);
urlParams.set('tab', targetId);
history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`);
}

Loading…
Cancel
Save