Skip to content

Commit

Permalink
fix auto resizer addon on init (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
ereburg authored Jun 12, 2024
1 parent b9254a2 commit 32190e7
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions static/js/with-iframe-resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ document.addEventListener('DOMContentLoaded', () => {
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
})
const isVaraTheme = params['docusaurus-data-theme-vara'] // Get the value of "docusaurus-data-theme-vara"
const isVaraTheme = params['docusaurus-data-theme-vara']

if (isVaraTheme) {
const anchors = document.body.querySelectorAll('main a[href^="/docs"]')
const transformLinks = (links) => {
Array.from(links).forEach(a => {
a.setAttribute('target', '_blank')
a.addEventListener('click', (e) => {
e.preventDefault()
window.open(e.target.href, '_blank')
})
})
}

const transformLinks = (interval) => {
const anchors = document.body.querySelectorAll('main a[href^="/docs"]')
const checkLinks = (interval) => {
const anchors = document.body.querySelectorAll('main article a[href^="/docs"]')

if (anchors.length) {
Array.from(anchors).forEach(a => {
a.setAttribute('target', '_blank')
a.addEventListener('click', (e) => {
e.preventDefault()
window.open(e.target.href, '_blank')
})
})
clearInterval(interval)
}
if (anchors.length) {
transformLinks(anchors)
clearInterval(interval)
}
}

if (isVaraTheme) {
const anchors = document.body.querySelectorAll('main a[href^="/docs"]')

if (!anchors.length) {
let count = 0
Expand All @@ -30,9 +34,9 @@ document.addEventListener('DOMContentLoaded', () => {
clearInterval(interval)
return
}
transformLinks(interval)
checkLinks(interval)
count++
}, 1000)
}
} else transformLinks(anchors)
}
})

0 comments on commit 32190e7

Please sign in to comment.