Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #85 from aslafy-z/patch-1
Browse files Browse the repository at this point in the history
Add feature detection for passive event option
  • Loading branch information
Mobius1 committed Nov 15, 2018
2 parents 57e35a0 + 7f63e13 commit c4d9baa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/selectr.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,8 @@
this.customOption = this.config.hasOwnProperty("renderOption") && typeof this.config.renderOption === "function";
this.customSelected = this.config.hasOwnProperty("renderSelection") && typeof this.config.renderSelection === "function";

this.supportsEventPassiveOption = this.detectEventPassiveOption();

// Enable event emitter
Events.mixin(this);

Expand Down Expand Up @@ -1088,6 +1090,24 @@
return values;
};

/**
* Feature detection: addEventListener passive option
* https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-passive
* https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
*/
Selectr.prototype.detectEventPassiveOption = function () {
var supportsPassiveOption = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassiveOption = true;
}
});
window.addEventListener('test', null, opts);
} catch (e) {}
return supportsPassiveOption;
}

/**
* Attach the required event listeners
*/
Expand All @@ -1107,7 +1127,7 @@
if (e.changedTouches[0].target === that.el) {
that.toggle();
}
});
}, this.supportsEventPassiveOption ? { passive: true } : false);

this.container.addEventListener("click", function(e) {
if (e.target === that.el) {
Expand Down

0 comments on commit c4d9baa

Please sign in to comment.