Skip to content

Commit

Permalink
Touch listeners passive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
laukstein committed May 13, 2018
1 parent 1c7c462 commit f2c4a29
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@
error: {e: null},
// addEventListener supported since IE9
eventListener: !!d.addEventListener,
eventListenerOptions: (function () {
// Resource http://tonsky.me/blog/chrome-intervention/
// Spec issue https://github.com/whatwg/dom/issues/491
var supports = false;

try {
d.addEventListener && addEventListener("test", null, {
get passive() {
supports = true;
}
});
} catch (e) {}

return supports;
}()),
// Pointer Events vs touch vs click
// https://bugs.chromium.org/p/chromium/issues/detail?id=152149
// http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
Expand Down Expand Up @@ -317,7 +302,7 @@
},
toggleReal: function (e) {
if (ui.status.classList.contains("expand")) {
if (e.type !== "touchstart" || !has.eventListenerOptions) {
if (e.type !== "touchstart") {
// preventDefault is required, otherwise when focused element, click will colapse and expand
e.preventDefault();
}
Expand All @@ -333,11 +318,7 @@
ui.status.classList.remove("expand");
}, 10);
} else if (e.type === "touchstart") {
if (!has.eventListenerOptions) {
// Unable to preventDefault inside passive event listener invocation
e.preventDefault();
}

e.preventDefault();
event.nav.expand();
} else {
setTimeout(function () {
Expand Down Expand Up @@ -435,7 +416,6 @@
if (eventName && eventName !== has.pointer || (ui.wrapper.offsetWidth <= api.viewportWidth ? !self.events : self.events)) {
self.events = !self.events;
self.listener = self.events ? "addEventListener" : "removeEventListener";
self.options = has.pointer === "touchstart" && has.eventListenerOptions ? {passive: true} : true;

ui.bar[self.listener](has.pointer, self.toggleReal, true);

Expand Down

0 comments on commit f2c4a29

Please sign in to comment.