-
Notifications
You must be signed in to change notification settings - Fork 526
/
index.min.js
1 lines (1 loc) · 8.4 KB
/
index.min.js
1
!function(){"use strict";Date.now||(Date.now=function(){return new Date().getTime()});for(var t=["webkit","moz"],i=0;i<t.length&&!window.requestAnimationFrame;++i){var e=t[i];window.requestAnimationFrame=window[e+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e+"CancelAnimationFrame"]||window[e+"CancelRequestAnimationFrame"]}if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent)||!window.requestAnimationFrame||!window.cancelAnimationFrame){var s=0;window.requestAnimationFrame=function(t){var i=Date.now(),e=Math.max(s+16,i);return setTimeout(function(){t(s=e)},e-i)},window.cancelAnimationFrame=clearTimeout}}(),function(){function t(t,i,e,s){var n=s||!1;return t.addEventListener(i,e,n),function s(){t.removeEventListener(i,e,n)}}function i(t){return Math.sqrt(1-Math.pow(t-1,2))}function e(t){return 1-Math.sqrt(1-t*t)}function s(){let t=["down","move","up","cancel"];return"PointerEvent"in window||window.navigator&&"msPointerEnabled"in window.navigator?t.map(t=>"pointer"+t):"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0?["touchstart","touchmove","touchend","touchcancel"]:t.map(t=>"mouse"+t)}var n=s(),h=function(){},a=function(t,i){return void 0===t?i:t},r=function(i){this.reverse=a(i.reverse,!1),this.element="string"==typeof i.touch?document.querySelector(i.touch):i.touch,this.target=a(i.target,this.element);var e=a(i.followers,[]);this.followers=e.map(function(t){return{element:"string"==typeof t.element?document.querySelector(t.element):t.element,offset:t.offset}}),this.vertical=a(i.vertical,!0),this.property=i.property,this.tickID=0,this.value=a(i.value,this.target[this.property]),this.target[this.property]=this.value,this.followers.forEach((function(t){t.element[this.property]=this.value+t.offset}).bind(this)),this.fixed=a(i.fixed,!1),this.sensitivity=a(i.sensitivity,1),this.moveFactor=a(i.moveFactor,1),this.factor=a(i.factor,1),this.outFactor=a(i.outFactor,.3),this.min=i.min,this.max=i.max,this.deceleration=a(i.deceleration,6e-4),this.maxRegion=a(i.maxRegion,600),this.springMaxRegion=a(i.springMaxRegion,60),this.maxSpeed=i.maxSpeed,this.hasMaxSpeed=void 0!==this.maxSpeed,this.lockDirection=a(i.lockDirection,!0);var s=function(){return!0};this.change=i.change||h,this.touchEnd=i.touchEnd||h,this.touchStart=i.touchStart||h,this.touchMove=i.touchMove||h,this.touchCancel=i.touchCancel||h,this.reboundEnd=i.reboundEnd||h,this.animationEnd=i.animationEnd||h,this.correctionEnd=i.correctionEnd||h,this.tap=i.tap||h,this.pressMove=i.pressMove||h,this.shouldRebound=i.shouldRebound||s,this.preventDefault=a(i.preventDefault,!0),this.preventDefaultException={tagName:/^(INPUT|TEXTAREA|BUTTON|SELECT)$/},this.hasMin=void 0!==this.min,this.hasMax=void 0!==this.max,this.isTouchStart=!1,this.step=i.step,this.inertia=a(i.inertia,!0),this._calculateIndex(),this.eventTarget=window,i.bindSelf&&(this.eventTarget=this.element);var r=this;(function t(i){return r[i]=r[i].bind(r),t})("_start")("_end")("_cancel")("_move");var o=t(this.element,n[0],this._start),c=t(this.eventTarget,n[1],this._move,{passive:!1,capture:!1}),u=t(this.eventTarget,n[2],this._end),l=t(this.eventTarget,n[3],this._cancel);this.destory=function(){o(),c(),u(),l(),r.followers=r.element=r.target=null,cancelAnimationFrame(r.tickID)},this.x1=this.x2=this.y1=this.y2=null};r.prototype={_events:s(),isAtMax:function(){return this.hasMax&&this.target[this.property]>=this.max},isAtMin:function(){return this.hasMin&&this.target[this.property]<=this.min},stop:function(){cancelAnimationFrame(this.tickID),this._calculateIndex()},_start:function(t){var i=t.touches?t.touches[0]:t;this.isTouchStart=!0,this.touchStart.call(this,t,this.target[this.property]),cancelAnimationFrame(this.tickID),this._calculateIndex(),this.startTime=new Date().getTime(),this.x1=this.preX=i.pageX,this.y1=this.preY=i.pageY,this.start=this.vertical?this.preY:this.preX,this._firstTouchMove=!0,this._preventMove=!1},_move:function(t){if(this.isTouchStart){var i=t.touches?t.touches[0]:t,e=t.touches?t.touches.length:1,s=i.pageX,n=i.pageY;if(this._firstTouchMove&&this.lockDirection){var h=Math.abs(s-this.x1)-Math.abs(n-this.y1);h>0&&this.vertical?this._preventMove=!0:h<0&&!this.vertical&&(this._preventMove=!0),this._firstTouchMove=!1}if(!this._preventMove){var a=(this.vertical?n-this.preY:s-this.preX)*this.sensitivity,r=this.moveFactor;if(this.isAtMax()&&(this.reverse?-a:a)>0?r=this.outFactor:this.isAtMin()&&(this.reverse?-a:a)<0&&(r=this.outFactor),a*=r,this.preX=s,this.preY=n,!this.fixed){var o=this.reverse?-a:a;this.target[this.property]+=o,this.followers.forEach((function(t){t.element[this.property]+=o}).bind(this))}this.change.call(this,this.target[this.property]);var c=new Date().getTime();c-this.startTime>300&&(this.startTime=c,this.start=this.vertical?this.preY:this.preX),this.touchMove.call(this,t,this.target[this.property])}this.preventDefault&&!function t(i,e){for(var s in e)if(e[s].test(i[s]))return!0;return!1}(t.target,this.preventDefaultException)&&t.preventDefault(),1===e&&(null!==this.x2?(t.deltaX=s-this.x2,t.deltaY=n-this.y2):(t.deltaX=0,t.deltaY=0),this.pressMove.call(this,t,this.target[this.property])),this.x2=s,this.y2=n}},_cancel:function(t){var i=this.target[this.property];this.touchCancel.call(this,t,i),this._end(t)},to:function(t,e,s,n){this._to(t,a(e,600),s||i,this.change,(function(t){this._calculateIndex(),this.reboundEnd.call(this,t),this.animationEnd.call(this,t),n&&n.call(this,t)}).bind(this))},_calculateIndex:function(){this.hasMax&&this.hasMin&&(this.currentPage=Math.round((this.max-this.target[this.property])/this.step))},_end:function(t){var s=t.changedTouches?t.changedTouches[0]:t;if(this.isTouchStart){this.isTouchStart=!1;var n=s.pageX,h=s.pageY,a=this,r=this.target[this.property],o=30>Math.abs(n-this.x1)&&30>Math.abs(h-this.y1);if(o&&this.tap.call(this,t,r),!1===this.touchEnd.call(this,t,r,this.currentPage))return;if(this.hasMax&&r>this.max){if(!this.shouldRebound(r))return;this._to(this.max,200,i,this.change,(function(t){this.reboundEnd.call(this,t),this.animationEnd.call(this,t)}).bind(this))}else if(this.hasMin&&r<this.min){if(!this.shouldRebound(r))return;this._to(this.min,200,i,this.change,(function(t){this.reboundEnd.call(this,t),this.animationEnd.call(this,t)}).bind(this))}else if(!this.inertia||o||this._preventMove||this.fixed)a._correction();else{var c=new Date().getTime()-this.startTime;if(c<300){var u=((this.vertical?h:n)-this.start)*this.sensitivity,l=Math.abs(u)/c,p=this.factor*l;this.hasMaxSpeed&&p>this.maxSpeed&&(p=this.maxSpeed);var m=u<0?-1:1;this.reverse&&(m=-m);var v=r+p*p/(2*this.deceleration)*m,f=1;v<this.min?v<this.min-this.maxRegion?(f=e((r-this.min+this.springMaxRegion)/(r-v)),v=this.min-this.springMaxRegion):(f=e((r-this.min+this.springMaxRegion*(this.min-v)/this.maxRegion)/(r-v)),v=this.min-this.springMaxRegion*(this.min-v)/this.maxRegion):v>this.max&&(v>this.max+this.maxRegion?(f=e((this.max+this.springMaxRegion-r)/(v-r)),v=this.max+this.springMaxRegion):(f=e((this.max+this.springMaxRegion*(v-this.max)/this.maxRegion-r)/(v-r)),v=this.max+this.springMaxRegion*(v-this.max)/this.maxRegion));var d=Math.round(l/a.deceleration)*f;isNaN(v)||a._to(Math.round(v),d,i,a.change,function(t){if(a.hasMax&&a.target[a.property]>a.max){if(!this.shouldRebound(a.target[a.property]))return;cancelAnimationFrame(a.tickID),a._to(a.max,600,i,a.change,a.animationEnd)}else if(a.hasMin&&a.target[a.property]<a.min){if(!this.shouldRebound(a.target[a.property]))return;cancelAnimationFrame(a.tickID),a._to(a.min,600,i,a.change,a.animationEnd)}else a.step?a._correction():a.animationEnd.call(a,t);a.change.call(this,t)})}else a._correction()}}this.x1=this.x2=this.y1=this.y2=null},_to:function(t,i,e,s,n){var h=this.target,a=this.property,r=this.followers,o=h[a],c=t-o,u=+new Date,l=this,p=function(){var m=+new Date-u;if(m>=i){h[a]=t,s&&s.call(l,t),n&&n.call(l,t);return}var v=c*e(m/i)+o;h[a]=v,r.forEach(function(t){t.element[a]=v+t.offset}),l.tickID=requestAnimationFrame(p),s&&s.call(l,h[a])};p()},_correction:function(){if(void 0!==this.step){var t,e=this.target[this.property],s=Math.floor(Math.abs(e/this.step));Math.abs(e%this.step)>this.step/2?this._to((e<0?-1:1)*(s+1)*this.step,400,i,this.change,(function(t){this._calculateIndex(),this.correctionEnd.call(this,t),this.animationEnd.call(this,t)}).bind(this)):this._to((e<0?-1:1)*s*this.step,400,i,this.change,(function(t){this._calculateIndex(),this.correctionEnd.call(this,t),this.animationEnd.call(this,t)}).bind(this))}},destory:h},"undefined"!=typeof module&&"object"==typeof exports?module.exports=r:window.PhyTouch=r}();