Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/implosion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ const requestAnimFrame = (function() {
);
})();

function getPassiveSupported() {
let passiveSupported = false;
const passiveSupported = (() => {
let _passiveSupported = false;

try {
let options = Object.defineProperty({}, 'passive', {
get: function() {
passiveSupported = true;
_passiveSupported = true;
},
});

window.addEventListener('test', null, options);
} catch (err) {}

getPassiveSupported = () => passiveSupported;
return passiveSupported;
}
return _passiveSupported;
})();

class Implosion {
constructor({
Expand All @@ -61,6 +60,8 @@ class Implosion {
decVelY;
let targetX = 0;
let targetY = 0;
let prevTargetX = null;
let prevTargetY = null;
let stopThreshold = stopThresholdDefault * multiplier;
let ticking = false;
let pointerActive = false;
Expand Down Expand Up @@ -192,10 +193,10 @@ class Implosion {
*/
function cleanUpRuntimeEvents() {
// Remove all touch events added during 'onDown' as well.
document.removeEventListener('touchmove', onMove, getPassiveSupported() ? { passive: false } : false);
document.removeEventListener('touchmove', onMove, passiveSupported ? { passive: false } : false);
document.removeEventListener('touchend', onUp);
document.removeEventListener('touchcancel', stopTracking);
document.removeEventListener('mousemove', onMove, getPassiveSupported() ? { passive: false } : false);
document.removeEventListener('mousemove', onMove, passiveSupported ? { passive: false } : false);
document.removeEventListener('mouseup', onUp);
}

Expand All @@ -206,18 +207,20 @@ class Implosion {
cleanUpRuntimeEvents();

// @see https://developers.google.com/web/updates/2017/01/scrolling-intervention
document.addEventListener('touchmove', onMove, getPassiveSupported() ? { passive: false } : false);
document.addEventListener('touchmove', onMove, passiveSupported ? { passive: false } : false);
document.addEventListener('touchend', onUp);
document.addEventListener('touchcancel', stopTracking);
document.addEventListener('mousemove', onMove, getPassiveSupported() ? { passive: false } : false);
document.addEventListener('mousemove', onMove, passiveSupported ? { passive: false } : false);
document.addEventListener('mouseup', onUp);
}

/**
* Executes the update function
*/
function callUpdateCallback() {
updateCallback.call(sourceEl, targetX, targetY);
updateCallback.call(sourceEl, targetX, targetY, prevTargetX, prevTargetY);
prevTargetX = targetX;
prevTargetY = targetY;
}

/**
Expand Down