Last active
June 14, 2022 03:29
-
-
Save reinink/db2700d3deb4234cc5605c42fa723c0f to your computer and use it in GitHub Desktop.
Global Inertia.js click event handler
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
import { Inertia } from '@inertiajs/inertia' | |
document.addEventListener('click', (event) => { | |
if ( | |
event.target.tagName.toLowerCase() === 'a' && | |
event.target.hasAttribute('inertia') && | |
!event.target.isContentEditable && | |
!event.defaultPrevented && | |
!event.shiftKey && | |
!event.ctrlKey && | |
!event.metaKey && | |
!event.altKey | |
) { | |
event.preventDefault() | |
const options = JSON.parse(event.target.getAttribute('inertia') || '{}') | |
Inertia.visit(event.target.href, options) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment