Skip to content
Open
Show file tree
Hide file tree
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
44 changes: 33 additions & 11 deletions dist/impetus.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
this.destroy = function () {
sourceEl.removeEventListener('touchstart', onDown);
sourceEl.removeEventListener('mousedown', onDown);

cleanUpRuntimeEvents();

// however it won't "destroy" a reference
// to instance if you'd like to do that
// it returns null as a convinience.
Expand All @@ -106,6 +109,8 @@
* @public
*/
this.pause = function () {
cleanUpRuntimeEvents();

pointerActive = false;
paused = true;
};
Expand Down Expand Up @@ -163,6 +168,32 @@
boundYmax = boundY[1];
};

/**
* Removes all events set by this instance during runtime
*/
function cleanUpRuntimeEvents() {
// Remove all touch events added during 'onDown' as well.
document.removeEventListener('touchmove', onMove, getPassiveSupported() ? { passive: false } : false);
document.removeEventListener('touchend', onUp);
document.removeEventListener('touchcancel', stopTracking);
document.removeEventListener('mousemove', onMove, getPassiveSupported() ? { passive: false } : false);
document.removeEventListener('mouseup', onUp);
}

/**
* Add all required runtime events
*/
function addRuntimeEvents() {
cleanUpRuntimeEvents();

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

/**
* Executes the update function
*/
Expand Down Expand Up @@ -209,12 +240,7 @@
trackingPoints = [];
addTrackingPoint(pointerLastX, pointerLastY);

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

Expand Down Expand Up @@ -254,11 +280,7 @@
addTrackingPoint(pointerLastX, pointerLastY);
startDecelAnim();

document.removeEventListener('touchmove', onMove);
document.removeEventListener('touchend', onUp);
document.removeEventListener('touchcancel', stopTracking);
document.removeEventListener('mouseup', onUp);
document.removeEventListener('mousemove', onMove);
cleanUpRuntimeEvents();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/impetus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/impetus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading