-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1473 from CuBoulder/issue/1353
Expandable url has updates
- Loading branch information
Showing
5 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
// Check if there is a hash in the URL and open the corresponding item | ||
if (window.location.hash) { | ||
openAccordionItem(window.location.hash.substring(1)); | ||
} | ||
|
||
// Add event listeners for all accordion or tab elements | ||
document.querySelectorAll('.accordion-button, .nav-link').forEach(function (link) { | ||
link.addEventListener("click", function () { | ||
const href = this.getAttribute("href"); | ||
if (href) { | ||
const hash = href.substring(1); | ||
setHashWithoutJump(hash); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
// Function to set the URL hash without causing the page to jump | ||
function setHashWithoutJump(hash) { | ||
if (history.pushState) { | ||
history.pushState(null, null, "#" + hash); | ||
} else { | ||
window.location.hash = hash; | ||
} | ||
} | ||
|
||
// Function to open an accordion or tab item based on the hash | ||
function openAccordionItem(hash) { | ||
if (!hash) return; | ||
|
||
// Try to find the link that matches the hash | ||
const targetLink = document.querySelector(`.accordion-button[href="#${hash}"], .nav-link[href="#${hash}"]`); | ||
if (targetLink) { | ||
targetLink.click(); // Programmatically click to open the item | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters