website/web/static/js/right-click.js
Noah Petherbridge cf6249c415 Alt Text for Photos
* Add an Alt Text field for users to describe their photos for accessibility.
* Alt texts appear on mouse over on Gallery pages, in the lightbox modal (on
  mouse over or by clicking the ALT button that appears), and in a box on the
  permalink page below the photo caption.
* Max length of Alt Text is 5,000 characters.
* Fix a bug with the right-click blocker not working on the lightbox modal.
2024-03-15 22:02:24 -07:00

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);
});
});