mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-15 11:40:57 -05:00
ba460a6755
De-Angularise bookmarkable-tabset GitOrigin-RevId: fc80f0c42fded9b0856dc7c62de2c87e66b5d85c
21 lines
581 B
JavaScript
21 lines
581 B
JavaScript
function bookmarkableTab(tabEl) {
|
|
tabEl.addEventListener('click', () => {
|
|
window.location.hash = tabEl.getAttribute('href')
|
|
})
|
|
}
|
|
|
|
function handleHashChange() {
|
|
const hash = window.location.hash
|
|
if (!hash) return
|
|
|
|
// Find the bookmarkable tab that links to the hash
|
|
const $tabEl = $(`[data-ol-bookmarkable-tab][href="${hash}"]`)
|
|
if (!$tabEl) return
|
|
|
|
// Select the tab via Bootstrap
|
|
$tabEl.tab('show')
|
|
}
|
|
|
|
document.querySelectorAll('[data-ol-bookmarkable-tab]').forEach(bookmarkableTab)
|
|
window.addEventListener('hashchange', handleHashChange)
|
|
handleHashChange()
|