Skip to content

Commit

Permalink
add internal link auto replacement for iframe resizer (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ereburg authored Jun 12, 2024
1 parent 4c7ca0b commit b9254a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export default {
src: 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.11/iframeResizer.contentWindow.min.js',
defer: true,
},
{
src: '/js/with-iframe-resizer.js',
defer: true,
},
// {
// src: 'https://cdn.jsdelivr.net/npm/@iframe-resizer/child',
// defer: true,
Expand Down
38 changes: 38 additions & 0 deletions static/js/with-iframe-resizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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"

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

const transformLinks = (interval) => {
const anchors = document.body.querySelectorAll('main 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) {
let count = 0
let interval
interval = setInterval(function () {
if (count === 10) {
clearInterval(interval)
return
}
transformLinks(interval)
count++
}, 1000)
}
}
})

0 comments on commit b9254a2

Please sign in to comment.