Update modal.js

This change allows catching the element with the handler attached, rather than target any other child element.
This commit is contained in:
Joan Mira 2022-05-24 00:14:33 +09:00 committed by GitHub
parent 161dfa874d
commit 0438e8c24d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@ let visibleModal = null;
// Toggle modal
const toggleModal = event => {
event.preventDefault();
const modal = document.getElementById(event.target.getAttribute('data-target'));
const modal = document.getElementById(event.currentTarget.getAttribute('data-target'));
(typeof(modal) != 'undefined' && modal != null)
&& isModalOpen(modal) ? closeModal(modal) : openModal(modal)
}
@ -92,4 +92,4 @@ const getScrollbarWidth = () => {
// Is scrollbar visible
const isScrollbarVisible = () => {
return document.body.scrollHeight > screen.height;
}
}