website/web/static/js/right-click.js

28 lines
896 B
JavaScript

// Right-click button handler, to dissuade downloading.
document.addEventListener('DOMContentLoaded', () => {
const $modal = document.querySelector("#rightclick-modal"),
$button = $modal.querySelector("button"),
cls = 'is-active';
// Disable context menu on all images.
(document.querySelectorAll('img, video, #detailImg') || []).forEach(node => {
node.addEventListener('contextmenu', (e) => {
$modal.classList.add(cls);
e.preventDefault();
});
});
// 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);
});
});