Skip to content

Commit

Permalink
Merge pull request #15261 from catboxanon/fix/imageviewer-click
Browse files Browse the repository at this point in the history
Make imageviewer event listeners browser consistent
  • Loading branch information
AUTOMATIC1111 authored Mar 16, 2024
2 parents 3ffe47c + 76fd487 commit 0cc3647
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions javascript/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,15 @@ function setupImageForLightbox(e) {
e.style.cursor = 'pointer';
e.style.userSelect = 'none';

var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

// For Firefox, listening on click first switched to next image then shows the lightbox.
// If you know how to fix this without switching to mousedown event, please.
// For other browsers the event is click to make it possiblr to drag picture.
var event = isFirefox ? 'mousedown' : 'click';

e.addEventListener(event, function(evt) {
e.addEventListener('mousedown', function(evt) {
if (evt.button == 1) {
open(evt.target.src);
evt.preventDefault();
return;
}
}, true);

e.addEventListener('click', function(evt) {
if (!opts.js_modal_lightbox || evt.button != 0) return;

modalZoomSet(gradioApp().getElementById('modalImage'), opts.js_modal_lightbox_initially_zoomed);
Expand Down

0 comments on commit 0cc3647

Please sign in to comment.