lightbox: Prevent undesired closing of lightbox during pan.

This commit adds a method of marking an overlay as being meant to be
left open despite click events triggering that would normally close it.
This is to prevent the case where a user drags an image and "unclicks"
in an area where normally clicking would close the overlay.
This commit is contained in:
Austin Riba 2022-01-24 12:27:33 -08:00 committed by Tim Abbott
parent 1c2fd19d69
commit 81b1b18886
4 changed files with 25 additions and 6 deletions

View File

@ -26,6 +26,23 @@ export class PanZoomControl {
cursor: "auto",
});
// The following events are necessary to prevent the click event
// firing where the user "unclicks" at the end of the drag, which
// was causing accidental overlay closes in some situations.
this.container.addEventListener("panzoomstart", () => {
// Marks this overlay as needing to stay open.
$("#lightbox_overlay").data("noclose", true);
});
this.container.addEventListener("panzoomend", () => {
// Don't remove the noclose attribute on this overlay until after paint,
// otherwise it will be removed too early and close the lightbox
// unintentionally.
setTimeout(() => {
$("#lightbox_overlay").data("noclose", false);
}, 0);
});
// keybinds
document.addEventListener("keydown", (e) => {
if (!overlays.lightbox_open()) {

View File

@ -337,6 +337,11 @@ export function initialize() {
return;
}
if ($target.data("noclose")) {
// This overlay has been marked explicitly to not be closed.
return;
}
const target_name = $target.attr("data-overlay");
close_overlay(target_name);

View File

@ -149,9 +149,6 @@
}
.image-description {
width: 100%;
/* approx width of screen minus action buttons on the side. */
max-width: calc(100% - 450px);
/* add some extra margin top and remove some bottom to keep the
height the same. and vertically center the text with the buttons. */
margin-top: 25px;

View File

@ -1,4 +1,4 @@
<div id="lightbox_overlay" class="overlay new-style" data-overlay="lightbox">
<div id="lightbox_overlay" class="overlay new-style" data-overlay="lightbox" data-noclose="false">
<div class="image-info-wrapper">
<div class="image-description">
<div class="title"></div>
@ -16,8 +16,8 @@
<div class="clear-float"></div>
</div>
<div class="image-preview overlay-content no-select">
<div class="zoom-element"></div>
<div class="image-preview no-select">
<div class="zoom-element no-select"></div>
</div>
<div class="player-container"></div>
<div class="center">