Skip to content

Commit

Permalink
(fix) Fix preventDefault inside passive events
Browse files Browse the repository at this point in the history
  • Loading branch information
feimosi committed Mar 31, 2020
1 parent ca8c54d commit 65f6b6e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/baguetteBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,27 +317,31 @@
}

function bindEvents() {
var options = supports.passiveEvents ? { passive: true } : null;
var passiveEvent = supports.passiveEvents ? { passive: false } : null;
var nonPassiveEvent = supports.passiveEvents ? { passive: false } : null;

bind(overlay, 'click', overlayClickHandler);
bind(previousButton, 'click', previousButtonClickHandler);
bind(nextButton, 'click', nextButtonClickHandler);
bind(closeButton, 'click', closeButtonClickHandler);
bind(slider, 'contextmenu', contextmenuHandler);
bind(overlay, 'touchstart', touchstartHandler, options);
bind(overlay, 'touchmove', touchmoveHandler, options);
bind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
bind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
bind(overlay, 'touchend', touchendHandler);
bind(document, 'focus', trapFocusInsideOverlay, true);
}

function unbindEvents() {
var options = supports.passiveEvents ? { passive: true } : null;
var passiveEvent = supports.passiveEvents ? { passive: false } : null;
var nonPassiveEvent = supports.passiveEvents ? { passive: false } : null;

unbind(overlay, 'click', overlayClickHandler);
unbind(previousButton, 'click', previousButtonClickHandler);
unbind(nextButton, 'click', nextButtonClickHandler);
unbind(closeButton, 'click', closeButtonClickHandler);
unbind(slider, 'contextmenu', contextmenuHandler);
unbind(overlay, 'touchstart', touchstartHandler, options);
unbind(overlay, 'touchmove', touchmoveHandler, options);
unbind(overlay, 'touchstart', touchstartHandler, nonPassiveEvent);
unbind(overlay, 'touchmove', touchmoveHandler, passiveEvent);
unbind(overlay, 'touchend', touchendHandler);
unbind(document, 'focus', trapFocusInsideOverlay, true);
}
Expand Down

0 comments on commit 65f6b6e

Please sign in to comment.