From bba932ab2c8cf3552eb4b4215894de99e9a5bb56 Mon Sep 17 00:00:00 2001 From: Nicolas Ong Date: Sat, 1 Mar 2025 23:15:39 +0100 Subject: [PATCH] Handling middle click in image viewer --- js/image_viewer.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/image_viewer.js b/js/image_viewer.js index c5a4275..08c2cf1 100644 --- a/js/image_viewer.js +++ b/js/image_viewer.js @@ -22,6 +22,18 @@ function unpop(event) { } } +function display(event) { + if (event.button != 1) { + return; + } + var target = event.target.parentNode; + if (target.nodeName != "FIGURE") { + target = event.target; + } + var href = target.parentNode.dataset.href; + window.open(href, '_blank'); +} + function displayNeighbour(which) { var viewer = document.getElementById('viewer'); var current = viewer.lastChild; @@ -98,6 +110,8 @@ document.body.addEventListener( /* Makes thumbnails interactive */ for (var thumb of document.getElementsByClassName('thumbnail')) { thumb.dataset.href = thumb.href; - thumb.href = 'javascript: void(0);'; + thumb.removeAttribute('href'); + thumb.style = "cursor: pointer;"; thumb.addEventListener('click', pop); + thumb.addEventListener('auxclick', display); }