Skip to content

Commit 363c3cb

Browse files
committed
Show context menu on image right-click
1 parent 4db0f43 commit 363c3cb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/js/lightbox.js

+27
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
this.$overlay = $('#lightboxOverlay');
100100
this.$outerContainer = this.$lightbox.find('.lb-outerContainer');
101101
this.$container = this.$lightbox.find('.lb-container');
102+
this.$nav = this.$lightbox.find('.lb-nav')
102103

103104
// Store css values for future lookup
104105
this.containerTopPadding = parseInt(this.$container.css('padding-top'), 10);
@@ -144,6 +145,32 @@
144145
return false;
145146
});
146147

148+
/*
149+
Show context menu for image on right-click
150+
151+
There is a div containing the navigation that spans the entire image and lives above of it. If
152+
you right-click, you are right clicking this div and not the image. This prevents users from
153+
saving the image or using other context menu actions with the image.
154+
155+
To fix this, when we detect the right mouse button is pressed down, but not yet clicked, we
156+
set pointer-events to none on the nav div. This is so that the upcoming right-click event on
157+
the next mouseup will bubble down to the image. Once the right-click/contextmenu event occurs
158+
we set the pointer events back to auto for the nav div so it can capture hover and left-click
159+
events as usual.
160+
*/
161+
this.$nav.on('mousedown', function(event) {
162+
if (event.which === 3) {
163+
self.$nav.css('pointer-events', 'none');
164+
165+
self.$lightbox.on('contextmenu', function() {
166+
setTimeout(function() {
167+
this.$nav.css('pointer-events', 'auto');
168+
}.bind(self), 0)
169+
});
170+
}
171+
})
172+
173+
147174
this.$lightbox.find('.lb-loader, .lb-close').on('click', function() {
148175
self.end();
149176
return false;

0 commit comments

Comments
 (0)