diff --git a/dist/impetus.js b/dist/impetus.js index c609f23..3c26bed 100644 --- a/dist/impetus.js +++ b/dist/impetus.js @@ -19,13 +19,11 @@ var bounceDeceleration = 0.04; var bounceAcceleration = 0.11; - // fixes weird safari 10 bug where preventDefault is prevented - // @see https://github.com/metafizzy/flickity/issues/457#issuecomment-254501356 - window.addEventListener('touchmove', function () {}); - var Impetus = function Impetus(_ref) { + var _ref$window = _ref.window; + var win = _ref$window === undefined ? window : _ref$window; var _ref$source = _ref.source; - var sourceEl = _ref$source === undefined ? document : _ref$source; + var sourceEl = _ref$source === undefined ? window : _ref$source; var updateCallback = _ref.update; var _ref$multiplier = _ref.multiplier; var multiplier = _ref$multiplier === undefined ? 1 : _ref$multiplier; @@ -49,11 +47,15 @@ var decelerating = false; var trackingPoints = []; + // fixes weird safari 10 bug where preventDefault is prevented + // @see https://github.com/metafizzy/flickity/issues/457#issuecomment-254501356 + win.addEventListener('touchmove', function () {}); + /** * Initialize instance */ (function init() { - sourceEl = typeof sourceEl === 'string' ? document.querySelector(sourceEl) : sourceEl; + sourceEl = typeof sourceEl === 'string' ? win.document.querySelector(sourceEl) : sourceEl; if (!sourceEl) { throw new Error('IMPETUS: source not found.'); } @@ -210,11 +212,11 @@ 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); + win.addEventListener('touchmove', onMove, getPassiveSupported() ? { passive: false } : false); + win.addEventListener('touchend', onUp); + win.addEventListener('touchcancel', stopTracking); + win.addEventListener('mousemove', onMove, getPassiveSupported() ? { passive: false } : false); + win.addEventListener('mouseup', onUp); } } @@ -254,11 +256,11 @@ addTrackingPoint(pointerLastX, pointerLastY); startDecelAnim(); - document.removeEventListener('touchmove', onMove); - document.removeEventListener('touchend', onUp); - document.removeEventListener('touchcancel', stopTracking); - document.removeEventListener('mouseup', onUp); - document.removeEventListener('mousemove', onMove); + win.removeEventListener('touchmove', onMove); + win.removeEventListener('touchend', onUp); + win.removeEventListener('touchcancel', stopTracking); + win.removeEventListener('mouseup', onUp); + win.removeEventListener('mousemove', onMove); } /** diff --git a/dist/impetus.min.js b/dist/impetus.min.js index 49fd819..486f502 100644 --- a/dist/impetus.min.js +++ b/dist/impetus.min.js @@ -1 +1 @@ -!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var n={exports:{}};t(n.exports,n),e.Impetus=n.exports}}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t)}catch(e){}return o=function(){return e},e}var i=.04,u=.11;window.addEventListener("touchmove",function(){});var r=function e(t){function r(){b.call(L,O,G)}function c(e){if("touchmove"===e.type||"touchstart"===e.type||"touchend"===e.type){var t=e.targetTouches[0]||e.changedTouches[0];return{x:t.clientX,y:t.clientY,id:t.identifier}}return{x:e.clientX,y:e.clientY,id:null}}function d(e){var t=c(e);K||N||(K=!0,Q=!1,k=t.id,R=V=t.x,U=j=t.y,W=[],m(R,U),document.addEventListener("touchmove",a,!!o()&&{passive:!1}),document.addEventListener("touchend",f),document.addEventListener("touchcancel",v),document.addEventListener("mousemove",a,!!o()&&{passive:!1}),document.addEventListener("mouseup",f))}function a(e){e.preventDefault();var t=c(e);K&&t.id===k&&(V=t.x,j=t.y,m(R,U),p())}function f(e){var t=c(e);K&&t.id===k&&v()}function v(){K=!1,m(R,U),x(),document.removeEventListener("touchmove",a),document.removeEventListener("touchend",f),document.removeEventListener("touchcancel",v),document.removeEventListener("mouseup",f),document.removeEventListener("mousemove",a)}function m(e,t){for(var n=Date.now();W.length>0&&!(n-W[0].time<=100);)W.shift();W.push({x:e,y:t,time:n})}function l(){var e=V-R,t=j-U;if(O+=e*g,G+=t*g,F){var n=y();0!==n.x&&(O-=e*h(n.x)*g),0!==n.y&&(G-=t*h(n.y)*g)}else y(!0);r(),R=V,U=j,J=!1}function h(e){return 5e-6*Math.pow(e,2)+1e-4*e+.55}function p(){J||s(l),J=!0}function y(e){var t=0,n=0;return void 0!==I&&OP&&(t=P-O),void 0!==S&&GD&&(n=D-G),e&&(0!==t&&(O=t>0?I:P),0!==n&&(G=n>0?S:D)),{x:t,y:n,inBounds:0===t&&0===n}}function x(){var e=W[0],t=W[W.length-1],n=t.x-e.x,o=t.y-e.y,i=t.time-e.time,u=i/15/g;z=n/u||0,C=o/u||0;var r=y();(Math.abs(z)>1||Math.abs(C)>1||!r.inBounds)&&(Q=!0,s(w))}function w(){if(Q){z*=B,C*=B,O+=z,G+=C;var e=y();if(Math.abs(z)>H||Math.abs(C)>H||!e.inBounds){if(F){if(0!==e.x)if(e.x*z<=0)z+=e.x*i;else{var t=e.x>0?2.5:-2.5;z=(e.x+t)*u}if(0!==e.y)if(e.y*C<=0)C+=e.y*i;else{var t=e.y>0?2.5:-2.5;C=(e.y+t)*u}}else 0!==e.x&&(O=e.x>0?I:P,z=0),0!==e.y&&(G=e.y>0?S:D,C=0);r(),s(w)}else Q=!1}}var E=t.source,L=void 0===E?document:E,b=t.update,M=t.multiplier,g=void 0===M?1:M,T=t.friction,B=void 0===T?.92:T,q=t.initialValues,X=t.boundX,Y=t.boundY,A=t.bounce,F=void 0===A||A;n(this,e);var I,P,S,D,R,U,V,j,k,z,C,O=0,G=0,H=.3*g,J=!1,K=!1,N=!1,Q=!1,W=[];!function(){if(!(L="string"==typeof L?document.querySelector(L):L))throw new Error("IMPETUS: source not found.");if(!b)throw new Error("IMPETUS: update function not defined.");q&&(q[0]&&(O=q[0]),q[1]&&(G=q[1]),r()),X&&(I=X[0],P=X[1]),Y&&(S=Y[0],D=Y[1]),L.addEventListener("touchstart",d),L.addEventListener("mousedown",d)}(),this.destroy=function(){return L.removeEventListener("touchstart",d),L.removeEventListener("mousedown",d),null},this.pause=function(){K=!1,N=!0},this.resume=function(){N=!1},this.setValues=function(e,t){"number"==typeof e&&(O=e),"number"==typeof t&&(G=t)},this.setMultiplier=function(e){g=e,H=.3*g},this.setBoundX=function(e){I=e[0],P=e[1]},this.setBoundY=function(e){S=e[0],D=e[1]}};t.exports=r;var s=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}()}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var n={exports:{}};t(n.exports,n),e.Impetus=n.exports}}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t)}catch(e){}return i=function(){return e},e}var o=.04,r=.11,u=function e(t){function u(){g.call(M,H,J)}function d(e){if("touchmove"===e.type||"touchstart"===e.type||"touchend"===e.type){var t=e.targetTouches[0]||e.changedTouches[0];return{x:t.clientX,y:t.clientY,id:t.identifier}}return{x:e.clientX,y:e.clientY,id:null}}function a(e){var t=d(e);Q||W||(Q=!0,Z=!1,C=t.id,V=k=t.x,j=z=t.y,$=[],m(V,j),L.addEventListener("touchmove",c,!!i()&&{passive:!1}),L.addEventListener("touchend",f),L.addEventListener("touchcancel",v),L.addEventListener("mousemove",c,!!i()&&{passive:!1}),L.addEventListener("mouseup",f))}function c(e){e.preventDefault();var t=d(e);Q&&t.id===C&&(k=t.x,z=t.y,m(V,j),p())}function f(e){var t=d(e);Q&&t.id===C&&v()}function v(){Q=!1,m(V,j),w(),L.removeEventListener("touchmove",c),L.removeEventListener("touchend",f),L.removeEventListener("touchcancel",v),L.removeEventListener("mouseup",f),L.removeEventListener("mousemove",c)}function m(e,t){for(var n=Date.now();$.length>0&&!(n-$[0].time<=100);)$.shift();$.push({x:e,y:t,time:n})}function l(){var e=k-V,t=z-j;if(H+=e*B,J+=t*B,P){var n=y();0!==n.x&&(H-=e*h(n.x)*B),0!==n.y&&(J-=t*h(n.y)*B)}else y(!0);u(),V=k,j=z,N=!1}function h(e){return 5e-6*Math.pow(e,2)+1e-4*e+.55}function p(){N||s(l),N=!0}function y(e){var t=0,n=0;return void 0!==S&&HD&&(t=D-H),void 0!==R&&JU&&(n=U-J),e&&(0!==t&&(H=t>0?S:D),0!==n&&(J=n>0?R:U)),{x:t,y:n,inBounds:0===t&&0===n}}function w(){var e=$[0],t=$[$.length-1],n=t.x-e.x,i=t.y-e.y,o=t.time-e.time,r=o/15/B;O=n/r||0,G=i/r||0;var u=y();(Math.abs(O)>1||Math.abs(G)>1||!u.inBounds)&&(Z=!0,s(x))}function x(){if(Z){O*=X,G*=X,H+=O,J+=G;var e=y();if(Math.abs(O)>K||Math.abs(G)>K||!e.inBounds){if(P){if(0!==e.x)if(e.x*O<=0)O+=e.x*o;else{var t=e.x>0?2.5:-2.5;O=(e.x+t)*r}if(0!==e.y)if(e.y*G<=0)G+=e.y*o;else{var t=e.y>0?2.5:-2.5;G=(e.y+t)*r}}else 0!==e.x&&(H=e.x>0?S:D,O=0),0!==e.y&&(J=e.y>0?R:U,G=0);u(),s(x)}else Z=!1}}var E=t.window,L=void 0===E?window:E,b=t.source,M=void 0===b?window:b,g=t.update,T=t.multiplier,B=void 0===T?1:T,q=t.friction,X=void 0===q?.92:q,Y=t.initialValues,A=t.boundX,F=t.boundY,I=t.bounce,P=void 0===I||I;n(this,e);var S,D,R,U,V,j,k,z,C,O,G,H=0,J=0,K=.3*B,N=!1,Q=!1,W=!1,Z=!1,$=[];L.addEventListener("touchmove",function(){}),function(){if(!(M="string"==typeof M?L.document.querySelector(M):M))throw new Error("IMPETUS: source not found.");if(!g)throw new Error("IMPETUS: update function not defined.");Y&&(Y[0]&&(H=Y[0]),Y[1]&&(J=Y[1]),u()),A&&(S=A[0],D=A[1]),F&&(R=F[0],U=F[1]),M.addEventListener("touchstart",a),M.addEventListener("mousedown",a)}(),this.destroy=function(){return M.removeEventListener("touchstart",a),M.removeEventListener("mousedown",a),null},this.pause=function(){Q=!1,W=!0},this.resume=function(){W=!1},this.setValues=function(e,t){"number"==typeof e&&(H=e),"number"==typeof t&&(J=t)},this.setMultiplier=function(e){B=e,K=.3*B},this.setBoundX=function(e){S=e[0],D=e[1]},this.setBoundY=function(e){R=e[0],U=e[1]}};t.exports=u;var s=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}()}); \ No newline at end of file diff --git a/docs/impetus.min.js b/docs/impetus.min.js index 49fd819..486f502 100644 --- a/docs/impetus.min.js +++ b/docs/impetus.min.js @@ -1 +1 @@ -!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var n={exports:{}};t(n.exports,n),e.Impetus=n.exports}}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t)}catch(e){}return o=function(){return e},e}var i=.04,u=.11;window.addEventListener("touchmove",function(){});var r=function e(t){function r(){b.call(L,O,G)}function c(e){if("touchmove"===e.type||"touchstart"===e.type||"touchend"===e.type){var t=e.targetTouches[0]||e.changedTouches[0];return{x:t.clientX,y:t.clientY,id:t.identifier}}return{x:e.clientX,y:e.clientY,id:null}}function d(e){var t=c(e);K||N||(K=!0,Q=!1,k=t.id,R=V=t.x,U=j=t.y,W=[],m(R,U),document.addEventListener("touchmove",a,!!o()&&{passive:!1}),document.addEventListener("touchend",f),document.addEventListener("touchcancel",v),document.addEventListener("mousemove",a,!!o()&&{passive:!1}),document.addEventListener("mouseup",f))}function a(e){e.preventDefault();var t=c(e);K&&t.id===k&&(V=t.x,j=t.y,m(R,U),p())}function f(e){var t=c(e);K&&t.id===k&&v()}function v(){K=!1,m(R,U),x(),document.removeEventListener("touchmove",a),document.removeEventListener("touchend",f),document.removeEventListener("touchcancel",v),document.removeEventListener("mouseup",f),document.removeEventListener("mousemove",a)}function m(e,t){for(var n=Date.now();W.length>0&&!(n-W[0].time<=100);)W.shift();W.push({x:e,y:t,time:n})}function l(){var e=V-R,t=j-U;if(O+=e*g,G+=t*g,F){var n=y();0!==n.x&&(O-=e*h(n.x)*g),0!==n.y&&(G-=t*h(n.y)*g)}else y(!0);r(),R=V,U=j,J=!1}function h(e){return 5e-6*Math.pow(e,2)+1e-4*e+.55}function p(){J||s(l),J=!0}function y(e){var t=0,n=0;return void 0!==I&&OP&&(t=P-O),void 0!==S&&GD&&(n=D-G),e&&(0!==t&&(O=t>0?I:P),0!==n&&(G=n>0?S:D)),{x:t,y:n,inBounds:0===t&&0===n}}function x(){var e=W[0],t=W[W.length-1],n=t.x-e.x,o=t.y-e.y,i=t.time-e.time,u=i/15/g;z=n/u||0,C=o/u||0;var r=y();(Math.abs(z)>1||Math.abs(C)>1||!r.inBounds)&&(Q=!0,s(w))}function w(){if(Q){z*=B,C*=B,O+=z,G+=C;var e=y();if(Math.abs(z)>H||Math.abs(C)>H||!e.inBounds){if(F){if(0!==e.x)if(e.x*z<=0)z+=e.x*i;else{var t=e.x>0?2.5:-2.5;z=(e.x+t)*u}if(0!==e.y)if(e.y*C<=0)C+=e.y*i;else{var t=e.y>0?2.5:-2.5;C=(e.y+t)*u}}else 0!==e.x&&(O=e.x>0?I:P,z=0),0!==e.y&&(G=e.y>0?S:D,C=0);r(),s(w)}else Q=!1}}var E=t.source,L=void 0===E?document:E,b=t.update,M=t.multiplier,g=void 0===M?1:M,T=t.friction,B=void 0===T?.92:T,q=t.initialValues,X=t.boundX,Y=t.boundY,A=t.bounce,F=void 0===A||A;n(this,e);var I,P,S,D,R,U,V,j,k,z,C,O=0,G=0,H=.3*g,J=!1,K=!1,N=!1,Q=!1,W=[];!function(){if(!(L="string"==typeof L?document.querySelector(L):L))throw new Error("IMPETUS: source not found.");if(!b)throw new Error("IMPETUS: update function not defined.");q&&(q[0]&&(O=q[0]),q[1]&&(G=q[1]),r()),X&&(I=X[0],P=X[1]),Y&&(S=Y[0],D=Y[1]),L.addEventListener("touchstart",d),L.addEventListener("mousedown",d)}(),this.destroy=function(){return L.removeEventListener("touchstart",d),L.removeEventListener("mousedown",d),null},this.pause=function(){K=!1,N=!0},this.resume=function(){N=!1},this.setValues=function(e,t){"number"==typeof e&&(O=e),"number"==typeof t&&(G=t)},this.setMultiplier=function(e){g=e,H=.3*g},this.setBoundX=function(e){I=e[0],P=e[1]},this.setBoundY=function(e){S=e[0],D=e[1]}};t.exports=r;var s=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}()}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var n={exports:{}};t(n.exports,n),e.Impetus=n.exports}}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t)}catch(e){}return i=function(){return e},e}var o=.04,r=.11,u=function e(t){function u(){g.call(M,H,J)}function d(e){if("touchmove"===e.type||"touchstart"===e.type||"touchend"===e.type){var t=e.targetTouches[0]||e.changedTouches[0];return{x:t.clientX,y:t.clientY,id:t.identifier}}return{x:e.clientX,y:e.clientY,id:null}}function a(e){var t=d(e);Q||W||(Q=!0,Z=!1,C=t.id,V=k=t.x,j=z=t.y,$=[],m(V,j),L.addEventListener("touchmove",c,!!i()&&{passive:!1}),L.addEventListener("touchend",f),L.addEventListener("touchcancel",v),L.addEventListener("mousemove",c,!!i()&&{passive:!1}),L.addEventListener("mouseup",f))}function c(e){e.preventDefault();var t=d(e);Q&&t.id===C&&(k=t.x,z=t.y,m(V,j),p())}function f(e){var t=d(e);Q&&t.id===C&&v()}function v(){Q=!1,m(V,j),w(),L.removeEventListener("touchmove",c),L.removeEventListener("touchend",f),L.removeEventListener("touchcancel",v),L.removeEventListener("mouseup",f),L.removeEventListener("mousemove",c)}function m(e,t){for(var n=Date.now();$.length>0&&!(n-$[0].time<=100);)$.shift();$.push({x:e,y:t,time:n})}function l(){var e=k-V,t=z-j;if(H+=e*B,J+=t*B,P){var n=y();0!==n.x&&(H-=e*h(n.x)*B),0!==n.y&&(J-=t*h(n.y)*B)}else y(!0);u(),V=k,j=z,N=!1}function h(e){return 5e-6*Math.pow(e,2)+1e-4*e+.55}function p(){N||s(l),N=!0}function y(e){var t=0,n=0;return void 0!==S&&HD&&(t=D-H),void 0!==R&&JU&&(n=U-J),e&&(0!==t&&(H=t>0?S:D),0!==n&&(J=n>0?R:U)),{x:t,y:n,inBounds:0===t&&0===n}}function w(){var e=$[0],t=$[$.length-1],n=t.x-e.x,i=t.y-e.y,o=t.time-e.time,r=o/15/B;O=n/r||0,G=i/r||0;var u=y();(Math.abs(O)>1||Math.abs(G)>1||!u.inBounds)&&(Z=!0,s(x))}function x(){if(Z){O*=X,G*=X,H+=O,J+=G;var e=y();if(Math.abs(O)>K||Math.abs(G)>K||!e.inBounds){if(P){if(0!==e.x)if(e.x*O<=0)O+=e.x*o;else{var t=e.x>0?2.5:-2.5;O=(e.x+t)*r}if(0!==e.y)if(e.y*G<=0)G+=e.y*o;else{var t=e.y>0?2.5:-2.5;G=(e.y+t)*r}}else 0!==e.x&&(H=e.x>0?S:D,O=0),0!==e.y&&(J=e.y>0?R:U,G=0);u(),s(x)}else Z=!1}}var E=t.window,L=void 0===E?window:E,b=t.source,M=void 0===b?window:b,g=t.update,T=t.multiplier,B=void 0===T?1:T,q=t.friction,X=void 0===q?.92:q,Y=t.initialValues,A=t.boundX,F=t.boundY,I=t.bounce,P=void 0===I||I;n(this,e);var S,D,R,U,V,j,k,z,C,O,G,H=0,J=0,K=.3*B,N=!1,Q=!1,W=!1,Z=!1,$=[];L.addEventListener("touchmove",function(){}),function(){if(!(M="string"==typeof M?L.document.querySelector(M):M))throw new Error("IMPETUS: source not found.");if(!g)throw new Error("IMPETUS: update function not defined.");Y&&(Y[0]&&(H=Y[0]),Y[1]&&(J=Y[1]),u()),A&&(S=A[0],D=A[1]),F&&(R=F[0],U=F[1]),M.addEventListener("touchstart",a),M.addEventListener("mousedown",a)}(),this.destroy=function(){return M.removeEventListener("touchstart",a),M.removeEventListener("mousedown",a),null},this.pause=function(){Q=!1,W=!0},this.resume=function(){W=!1},this.setValues=function(e,t){"number"==typeof e&&(H=e),"number"==typeof t&&(J=t)},this.setMultiplier=function(e){B=e,K=.3*B},this.setBoundX=function(e){S=e[0],D=e[1]},this.setBoundY=function(e){R=e[0],U=e[1]}};t.exports=u;var s=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}()}); \ No newline at end of file diff --git a/src/Impetus.js b/src/Impetus.js index 920d895..3d71c88 100644 --- a/src/Impetus.js +++ b/src/Impetus.js @@ -3,15 +3,10 @@ const stopThresholdDefault = 0.3; const bounceDeceleration = 0.04; const bounceAcceleration = 0.11; - -// fixes weird safari 10 bug where preventDefault is prevented -// @see https://github.com/metafizzy/flickity/issues/457#issuecomment-254501356 -window.addEventListener('touchmove', function() {}); - - export default class Impetus { constructor({ - source: sourceEl = document, + window: win = window, + source: sourceEl = window, update: updateCallback, multiplier = 1, friction = 0.92, @@ -30,12 +25,16 @@ export default class Impetus { var decelerating = false; var trackingPoints = []; + // fixes weird safari 10 bug where preventDefault is prevented + // @see https://github.com/metafizzy/flickity/issues/457#issuecomment-254501356 + win.addEventListener('touchmove', function() {}); + /** * Initialize instance */ (function init() { - sourceEl = (typeof sourceEl === 'string') ? document.querySelector(sourceEl) : sourceEl; + sourceEl = (typeof sourceEl === 'string') ? win.document.querySelector(sourceEl) : sourceEl; if (!sourceEl) { throw new Error('IMPETUS: source not found.'); } @@ -191,11 +190,11 @@ export default class Impetus { 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); + win.addEventListener('touchmove', onMove, getPassiveSupported() ? {passive: false} : false); + win.addEventListener('touchend', onUp); + win.addEventListener('touchcancel', stopTracking); + win.addEventListener('mousemove', onMove, getPassiveSupported() ? {passive: false} : false); + win.addEventListener('mouseup', onUp); } } @@ -235,11 +234,11 @@ export default class Impetus { addTrackingPoint(pointerLastX, pointerLastY); startDecelAnim(); - document.removeEventListener('touchmove', onMove); - document.removeEventListener('touchend', onUp); - document.removeEventListener('touchcancel', stopTracking); - document.removeEventListener('mouseup', onUp); - document.removeEventListener('mousemove', onMove); + win.removeEventListener('touchmove', onMove); + win.removeEventListener('touchend', onUp); + win.removeEventListener('touchcancel', stopTracking); + win.removeEventListener('mouseup', onUp); + win.removeEventListener('mousemove', onMove); } /**