Skip to content

Commit 6e8fc24

Browse files
committed
(fix) Fix preventDefault inside passive events
Resolves #202 Resolves #223 Resolves #211 Closes #224
1 parent ca8c54d commit 6e8fc24

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/baguetteBox.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,27 +317,31 @@
317317
}
318318

319319
function bindEvents() {
320-
var options = supports.passiveEvents ? { passive: true } : null;
320+
var passiveEvent = supports.passiveEvents ? { passive: false } : null;
321+
var nonPassiveEvent = supports.passiveEvents ? { passive: true } : null;
322+
321323
bind(overlay, 'click', overlayClickHandler);
322324
bind(previousButton, 'click', previousButtonClickHandler);
323325
bind(nextButton, 'click', nextButtonClickHandler);
324326
bind(closeButton, 'click', closeButtonClickHandler);
325327
bind(slider, 'contextmenu', contextmenuHandler);
326-
bind(overlay, 'touchstart', touchstartHandler, options);
327-
bind(overlay, 'touchmove', touchmoveHandler, options);
328+
bind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
329+
bind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
328330
bind(overlay, 'touchend', touchendHandler);
329331
bind(document, 'focus', trapFocusInsideOverlay, true);
330332
}
331333

332334
function unbindEvents() {
333-
var options = supports.passiveEvents ? { passive: true } : null;
335+
var passiveEvent = supports.passiveEvents ? { passive: false } : null;
336+
var nonPassiveEvent = supports.passiveEvents ? { passive: true } : null;
337+
334338
unbind(overlay, 'click', overlayClickHandler);
335339
unbind(previousButton, 'click', previousButtonClickHandler);
336340
unbind(nextButton, 'click', nextButtonClickHandler);
337341
unbind(closeButton, 'click', closeButtonClickHandler);
338342
unbind(slider, 'contextmenu', contextmenuHandler);
339-
unbind(overlay, 'touchstart', touchstartHandler, options);
340-
unbind(overlay, 'touchmove', touchmoveHandler, options);
343+
unbind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
344+
unbind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
341345
unbind(overlay, 'touchend', touchendHandler);
342346
unbind(document, 'focus', trapFocusInsideOverlay, true);
343347
}

0 commit comments

Comments
 (0)