From 7d9bb5fee50561bdce8fe7440ae9d1b8aae48bd0 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 14 Jun 2022 20:35:37 +0200 Subject: Update --- content/main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'content/main.js') diff --git a/content/main.js b/content/main.js index 3257c39..760d40a 100644 --- a/content/main.js +++ b/content/main.js @@ -22,6 +22,7 @@ (() => { let currentIndex = 0; let visible = false; + let mouseDown = false; const mainEl = document.querySelector("main"); const lightboxContainerEl = document.querySelector(".js-lightbox"); @@ -90,6 +91,21 @@ return thumbnailButtonEl; }); + document.addEventListener('mousedown', (e) => { + if (visible) { + mouseDown = !lightboxEl.contains(e.target) || lightboxEl === e.target; + } + }); + + document.addEventListener('click', (e) => { + if (visible && mouseDown) { + mouseDown = false; + e.preventDefault(); + e.stopPropagation(); + hide(); + } + }, { capture: true }); + window.addEventListener("keydown", e => { if (e.defaultPrevented || !visible) { return; -- cgit v1.2.3-54-g00ecf