document.addEventListener('DOMContentLoaded', function () {
  // Selects all internal links generated by Sphinx on the page
  internalLinks = document.querySelectorAll('a.reference.internal')

  internalLinks.forEach(link => {
    // Excludes links from table of contents or menus (class toctree-l*)
    if (link.closest('.toctree-l1, .toctree-l2, .toctree-l3')) return

    // Excludes the links towards source code generated by viewcode
    if (link.querySelector('.viewcode-link')) return

    // Excludes anchors towards the same page
    isSamePageAnchor = link.pathname === window.location.pathname && link.hash.length > 0
    if (isSamePageAnchor) return

    // Makes link openable in a new tab
    link.setAttribute('target', '_blank')
    link.setAttribute('rel', 'noopener')
  })
})


document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll("a[href^='http']").forEach(function(link){
        link.setAttribute('target', '_blank')
        link.setAttribute('rel', 'noopener noreferrer')
    })
})

document.addEventListener('DOMContentLoaded', function() {
    modal = document.createElement('div')
    modal.id = 'image-modal'
    document.body.appendChild(modal)

    modal.addEventListener('click', () => {
        modal.classList.remove('show')
        while (modal.firstChild) {
            modal.removeChild(modal.firstChild)
        }
    })

    document.querySelectorAll('img.zoomable-image').forEach(img => {
        img.style.cursor = 'zoom-in'
        img.addEventListener('click', () => {
            // Nettoyage au cas où il reste quelque chose
            while (modal.firstChild) {
                modal.removeChild(modal.firstChild)
            }

            modalImg = document.createElement('img')
            modalImg.src = img.src
            modal.appendChild(modalImg)
            modal.classList.add('show')
        })
    })
})