Disable image dragging

This commit is contained in:
Noah Petherbridge 2023-12-21 20:38:18 -08:00
parent 319fab3da9
commit 50434ae7d2

View File

@ -4,6 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
$button = $modal.querySelector("button"),
cls = 'is-active';
// Disable context menu on all images.
(document.querySelectorAll('img, video') || []).forEach(node => {
node.addEventListener('contextmenu', (e) => {
$modal.classList.add(cls);
@ -11,6 +12,15 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
// Make images not draggable.
(document.querySelectorAll('img') || []).forEach(node => {
node.addEventListener('dragstart', (e) => {
e.preventDefault();
return false;
});
node.setAttribute("draggable", "false");
});
$button.addEventListener('click', () => {
$modal.classList.remove(cls);
});