-
Notifications
You must be signed in to change notification settings - Fork 51
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 #674 from dpfens/accordion-hash
Open accordions using URL hashes
- Loading branch information
Showing
6 changed files
with
65 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<script src="/assets/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script> | ||
<script src="/assets/js/toc-scroll.js" async></script> | ||
<script src="/assets/js/external-links.js" defer></script> | ||
<script src="/assets/js/hashes.js"></script> | ||
|
||
{% include google_analytics.html %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
window.addEventListener('load', function() { | ||
setupHashTrigger(); | ||
setupHashUpdates(); | ||
|
||
function setupHashTrigger() { | ||
if (!window.location.hash) { | ||
return; | ||
} | ||
const element = document.querySelector(window.location.hash); | ||
if (!element) { | ||
return; | ||
} | ||
if (element.className.indexOf('accordion-collapse') > -1) { | ||
new bootstrap.Collapse(element, { show: true }); | ||
recordAccordionOpen(element); | ||
} | ||
} | ||
|
||
function setupHashUpdates() { | ||
const accordionElements = document.querySelectorAll('.accordion'); | ||
accordionElements.forEach(function(element) { | ||
element.addEventListener('show.bs.collapse', function(event) { | ||
const hash = '#' + event.target.id; | ||
window.history.replaceState('', '', hash); | ||
recordAccordionOpen(element); | ||
}); | ||
|
||
element.addEventListener('hide.bs.collapse', function(event) { | ||
const hash = '#' + event.target.id; | ||
if (window.location.hash == hash) { | ||
window.history.replaceState('', '', window.location.pathname + window.location.search); | ||
} | ||
}); | ||
|
||
}); | ||
} | ||
|
||
function recordAccordionOpen(element) { | ||
if (typeof _paq !== 'undefined') { | ||
_paq.push(['trackEvent', 'Accordion', 'Opened', element.id]); | ||
} | ||
} | ||
}); |
Large diffs are not rendered by default.
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