diff --git a/impetus.min.js b/impetus.min.js index 475498d..cfac440 100644 --- a/impetus.min.js +++ b/impetus.min.js @@ -1,7 +1,7 @@ /** - * Impetus - v0.8.0 + * Impetus - v0.8.1 * http://chrisbateman.github.io/impetus/ * Copyright (c) 2015 Chris Bateman * Licensed MIT */ -!function(){var a=function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l,m,n,o=0,p=0,q=1,r=.92,s=.3,t=s,u=!1,v=!1,w=!1,x=!1,y=[],z=!0,A=.05,B=.09,C=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}();this.pause=function(){v=!1,w=!0},this.resume=function(){w=!1},this.setValues=function(a,b){"number"==typeof a&&(o=a),"number"==typeof b&&(p=b)},this.setMultiplier=function(a){q=a,t=s*q};var D=function(){c.call(b,o,p)},E=function(a){if("touchmove"===a.type||"touchstart"===a.type||"touchend"===a.type){var b=a.targetTouches[0]||a.changedTouches[0];return{x:b.clientX,y:b.clientY,id:b.identifier}}return{x:a.clientX,y:a.clientY,id:null}},F=function(a){var b=E(a);v||w||(v=!0,x=!1,l=b.id,h=j=b.x,i=k=b.y,y=[],J(h,i),document.addEventListener("touchmove",G),document.addEventListener("touchend",H),document.addEventListener("touchcancel",I),document.addEventListener("mousemove",G),document.addEventListener("mouseup",H))},G=function(a){a.preventDefault();var b=E(a);v&&b.id===l&&(j=b.x,k=b.y,J(h,i),M())},H=function(a){var b=E(a);v&&b.id===l&&I()},I=function(){v=!1,J(h,i),P(),document.removeEventListener("touchmove",G),document.removeEventListener("touchend",H),document.removeEventListener("touchcancel",I),document.removeEventListener("mouseup",H),document.removeEventListener("mousemove",G)},J=function(a,b){for(var c=Date.now();y.length>0&&!(c-y[0].time<=100);)y.shift();y.push({x:a,y:b,time:c})},K=function(){var a=j-h,b=k-i;if(o+=a*q,p+=b*q,z){var c=O();0!==c.x&&(o-=a*L(c.x)*q),0!==c.y&&(p-=b*L(c.y)*q)}else O(!0);D(),h=j,i=k,u=!1},L=function(a){return 5e-6*Math.pow(a,2)+1e-4*a+.55},M=function(){u||C(K),u=!0},N=function(){a.boundX&&(d=a.boundX[0],e=a.boundX[1]),a.boundY&&(f=a.boundY[0],g=a.boundY[1])},O=function(a){var b=0,c=0;return void 0!==d&&d>o?b=d-o:void 0!==e&&o>e&&(b=e-o),void 0!==f&&f>p?c=f-p:void 0!==g&&p>g&&(c=g-p),a&&(0!==b&&(o=b>0?d:e),0!==c&&(p=c>0?f:g)),{x:b,y:c,inBounds:0===b&&0===c}},P=function(){var a=y[0],b=y[y.length-1],c=b.x-a.x,d=b.y-a.y,e=b.time-a.time,f=e/15/q;m=c/f||0,n=d/f||0;var g=O();(Math.abs(m)>1||Math.abs(n)>1||!g.inBounds)&&(x=!0,C(Q))},Q=function(){if(x){m*=r,n*=r,o+=m,p+=n;var a=O();if(Math.abs(m)>t||Math.abs(n)>t||!a.inBounds){if(z){var b=2.5;if(0!==a.x)if(a.x*m<=0)m+=a.x*A;else{var c=a.x>0?b:-b;m=(a.x+c)*B}if(0!==a.y)if(a.y*n<=0)n+=a.y*A;else{var c=a.y>0?b:-b;n=(a.y+c)*B}}else 0!==a.x&&(o=a.x>0?d:e,m=0),0!==a.y&&(p=a.y>0?f:g,n=0);D(),C(Q)}else x=!1}};!function(){if(a.source){if(b="string"==typeof a.source?document.querySelector(a.source):a.source,!b)throw new Error("IMPETUS: source not found.")}else b=document;if(!a.update)throw new Error("IMPETUS: update function not defined.");c=a.update,"undefined"!=typeof a.multiplier&&(q=a.multiplier||q,t=s*q),"undefined"!=typeof a.friction&&(r=a.friction||r),a.bounces===!1&&(z=!1),a.initialValues&&(a.initialValues[0]&&(o=a.initialValues[0]),a.initialValues[1]&&(p=a.initialValues[1]),D()),N(),b.addEventListener("touchstart",F),b.addEventListener("mousedown",F)}()};"function"==typeof define&&define.amd?define(function(){return a}):this.Impetus=a}(); \ No newline at end of file +!function(){var a=function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l,m,n,o=0,p=0,q=1,r=.92,s=.3,t=s,u=!1,v=!1,w=!1,x=!1,y=[],z=!0,A=.04,B=.11,C=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}();this.pause=function(){v=!1,w=!0},this.resume=function(){w=!1},this.setValues=function(a,b){"number"==typeof a&&(o=a),"number"==typeof b&&(p=b)},this.setMultiplier=function(a){q=a,t=s*q};var D=function(){c.call(b,o,p)},E=function(a){if("touchmove"===a.type||"touchstart"===a.type||"touchend"===a.type){var b=a.targetTouches[0]||a.changedTouches[0];return{x:b.clientX,y:b.clientY,id:b.identifier}}return{x:a.clientX,y:a.clientY,id:null}},F=function(a){var b=E(a);v||w||(v=!0,x=!1,l=b.id,h=j=b.x,i=k=b.y,y=[],J(h,i),document.addEventListener("touchmove",G),document.addEventListener("touchend",H),document.addEventListener("touchcancel",I),document.addEventListener("mousemove",G),document.addEventListener("mouseup",H))},G=function(a){a.preventDefault();var b=E(a);v&&b.id===l&&(j=b.x,k=b.y,J(h,i),M())},H=function(a){var b=E(a);v&&b.id===l&&I()},I=function(){v=!1,J(h,i),P(),document.removeEventListener("touchmove",G),document.removeEventListener("touchend",H),document.removeEventListener("touchcancel",I),document.removeEventListener("mouseup",H),document.removeEventListener("mousemove",G)},J=function(a,b){for(var c=Date.now();y.length>0&&!(c-y[0].time<=100);)y.shift();y.push({x:a,y:b,time:c})},K=function(){var a=j-h,b=k-i;if(o+=a*q,p+=b*q,z){var c=O();0!==c.x&&(o-=a*L(c.x)*q),0!==c.y&&(p-=b*L(c.y)*q)}else O(!0);D(),h=j,i=k,u=!1},L=function(a){return 5e-6*Math.pow(a,2)+1e-4*a+.55},M=function(){u||C(K),u=!0},N=function(){a.boundX&&(d=a.boundX[0],e=a.boundX[1]),a.boundY&&(f=a.boundY[0],g=a.boundY[1])},O=function(a){var b=0,c=0;return void 0!==d&&d>o?b=d-o:void 0!==e&&o>e&&(b=e-o),void 0!==f&&f>p?c=f-p:void 0!==g&&p>g&&(c=g-p),a&&(0!==b&&(o=b>0?d:e),0!==c&&(p=c>0?f:g)),{x:b,y:c,inBounds:0===b&&0===c}},P=function(){var a=y[0],b=y[y.length-1],c=b.x-a.x,d=b.y-a.y,e=b.time-a.time,f=e/15/q;m=c/f||0,n=d/f||0;var g=O();(Math.abs(m)>1||Math.abs(n)>1||!g.inBounds)&&(x=!0,C(Q))},Q=function(){if(x){m*=r,n*=r,o+=m,p+=n;var a=O();if(Math.abs(m)>t||Math.abs(n)>t||!a.inBounds){if(z){var b=2.5;if(0!==a.x)if(a.x*m<=0)m+=a.x*A;else{var c=a.x>0?b:-b;m=(a.x+c)*B}if(0!==a.y)if(a.y*n<=0)n+=a.y*A;else{var c=a.y>0?b:-b;n=(a.y+c)*B}}else 0!==a.x&&(o=a.x>0?d:e,m=0),0!==a.y&&(p=a.y>0?f:g,n=0);D(),C(Q)}else x=!1}};!function(){if(a.source){if(b="string"==typeof a.source?document.querySelector(a.source):a.source,!b)throw new Error("IMPETUS: source not found.")}else b=document;if(!a.update)throw new Error("IMPETUS: update function not defined.");c=a.update,"undefined"!=typeof a.multiplier&&(q=a.multiplier||q,t=s*q),"undefined"!=typeof a.friction&&(r=a.friction||r),a.bounce===!1&&(z=!1),a.initialValues&&(a.initialValues[0]&&(o=a.initialValues[0]),a.initialValues[1]&&(p=a.initialValues[1]),D()),N(),b.addEventListener("touchstart",F),b.addEventListener("mousedown",F)}()};"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:this.Impetus=a}(); \ No newline at end of file