| 1 |
- define(function(t,e,i){"use strict";function n(t,e,i){return setTimeout(u(t,i),e)}function r(t,e,i){return!!Array.isArray(t)&&(s(t,i[e],i),!0)}function s(t,e,i){var n;if(t)if(t.forEach)t.forEach(e,i);else if(void 0!==t.length)for(n=0;n<t.length;)e.call(i,t[n],n,t),n++;else for(n in t)t.hasOwnProperty(n)&&e.call(i,t[n],n,t)}function o(t,e,i){for(var n=Object.keys(e),r=0;r<n.length;)(!i||i&&void 0===t[n[r]])&&(t[n[r]]=e[n[r]]),r++;return t}function h(t,e){return o(t,e,!0)}function a(t,e,i){var n,r=e.prototype;n=t.prototype=Object.create(r),n.constructor=t,n._super=r,i&&o(n,i)}function u(t,e){return function(){return t.apply(e,arguments)}}function c(t,e){return typeof t==ut?t.apply(e?e[0]||void 0:void 0,e):t}function l(t,e){return void 0===t?e:t}function p(t,e,i){s(m(e),function(e){t.addEventListener(e,i,!1)})}function f(t,e,i){s(m(e),function(e){t.removeEventListener(e,i,!1)})}function d(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function v(t,e){return t.indexOf(e)>-1}function m(t){return t.trim().split(/\s+/g)}function g(t,e,i){if(t.indexOf&&!i)return t.indexOf(e);for(var n=0;n<t.length;){if(i&&t[n][i]==e||!i&&t[n]===e)return n;n++}return-1}function T(t){return Array.prototype.slice.call(t,0)}function y(t,e,i){for(var n=[],r=[],s=0;s<t.length;){var o=e?t[s][e]:t[s];g(r,o)<0&&n.push(t[s]),r[s]=o,s++}return i&&(n=e?n.sort(function(t,i){return t[e]>i[e]}):n.sort()),n}function E(t,e){for(var i,n,r=e[0].toUpperCase()+e.slice(1),s=0;s<ht.length;){if(i=ht[s],n=i?i+r:e,n in t)return n;s++}}function I(){return ft++}function A(t){var e=t.ownerDocument;return e.defaultView||e.parentWindow}function _(t,e){var i=this;this.manager=t,this.callback=e,this.element=t.element,this.target=t.options.inputTarget,this.domHandler=function(e){c(t.options.enable,[t])&&i.handler(e)},this.init()}function w(t){var e,i=t.options.inputClass;return new(e=i?i:mt?F:gt?L:vt?k:Y)(t,D)}function D(t,e,i){var n=i.pointers.length,r=i.changedPointers.length,s=e&_t&&n-r===0,o=e&(Dt|St)&&n-r===0;i.isFirst=!!s,i.isFinal=!!o,s&&(t.session={}),i.eventType=e,S(t,i),t.emit("hammer.input",i),t.recognize(i),t.session.prevInput=i}function S(t,e){var i=t.session,n=e.pointers,r=n.length;i.firstInput||(i.firstInput=R(e)),r>1&&!i.firstMultiple?i.firstMultiple=R(e):1===r&&(i.firstMultiple=!1);var s=i.firstInput,o=i.firstMultiple,h=o?o.center:s.center,a=e.center=z(n);e.timeStamp=pt(),e.deltaTime=e.timeStamp-s.timeStamp,e.angle=O(h,a),e.distance=M(h,a),b(i,e),e.offsetDirection=P(e.deltaX,e.deltaY),e.scale=o?X(o.pointers,n):1,e.rotation=o?x(o.pointers,n):0,C(i,e);var u=t.element;d(e.srcEvent.target,u)&&(u=e.srcEvent.target),e.target=u}function b(t,e){var i=e.center,n=t.offsetDelta||{},r=t.prevDelta||{},s=t.prevInput||{};e.eventType!==_t&&s.eventType!==Dt||(r=t.prevDelta={x:s.deltaX||0,y:s.deltaY||0},n=t.offsetDelta={x:i.x,y:i.y}),e.deltaX=r.x+(i.x-n.x),e.deltaY=r.y+(i.y-n.y)}function C(t,e){var i,n,r,s,o=t.lastInterval||e,h=e.timeStamp-o.timeStamp;if(e.eventType!=St&&(h>At||void 0===o.velocity)){var a=o.deltaX-e.deltaX,u=o.deltaY-e.deltaY,c=N(h,a,u);n=c.x,r=c.y,i=lt(c.x)>lt(c.y)?c.x:c.y,s=P(a,u),t.lastInterval=e}else i=o.velocity,n=o.velocityX,r=o.velocityY,s=o.direction;e.velocity=i,e.velocityX=n,e.velocityY=r,e.direction=s}function R(t){for(var e=[],i=0;i<t.pointers.length;)e[i]={clientX:ct(t.pointers[i].clientX),clientY:ct(t.pointers[i].clientY)},i++;return{timeStamp:pt(),pointers:e,center:z(e),deltaX:t.deltaX,deltaY:t.deltaY}}function z(t){var e=t.length;if(1===e)return{x:ct(t[0].clientX),y:ct(t[0].clientY)};for(var i=0,n=0,r=0;r<e;)i+=t[r].clientX,n+=t[r].clientY,r++;return{x:ct(i/e),y:ct(n/e)}}function N(t,e,i){return{x:e/t||0,y:i/t||0}}function P(t,e){return t===e?bt:lt(t)>=lt(e)?t>0?Ct:Rt:e>0?zt:Nt}function M(t,e,i){i||(i=xt);var n=e[i[0]]-t[i[0]],r=e[i[1]]-t[i[1]];return Math.sqrt(n*n+r*r)}function O(t,e,i){i||(i=xt);var n=e[i[0]]-t[i[0]],r=e[i[1]]-t[i[1]];return 180*Math.atan2(r,n)/Math.PI}function x(t,e){return O(e[1],e[0],Xt)-O(t[1],t[0],Xt)}function X(t,e){return M(e[0],e[1],Xt)/M(t[0],t[1],Xt)}function Y(){this.evEl=Ft,this.evWin=Wt,this.allow=!0,this.pressed=!1,_.apply(this,arguments)}function F(){this.evEl=Ht,this.evWin=kt,_.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}function W(){this.evTarget=jt,this.evWin=Gt,this.started=!1,_.apply(this,arguments)}function q(t,e){var i=T(t.touches),n=T(t.changedTouches);return e&(Dt|St)&&(i=y(i.concat(n),"identifier",!0)),[i,n]}function L(){this.evTarget=Zt,this.targetIds={},_.apply(this,arguments)}function H(t,e){var i=T(t.touches),n=this.targetIds;if(e&(_t|wt)&&1===i.length)return n[i[0].identifier]=!0,[i,i];var r,s,o=T(t.changedTouches),h=[],a=this.target;if(s=i.filter(function(t){return d(t.target,a)}),e===_t)for(r=0;r<s.length;)n[s[r].identifier]=!0,r++;for(r=0;r<o.length;)n[o[r].identifier]&&h.push(o[r]),e&(Dt|St)&&delete n[o[r].identifier],r++;return h.length?[y(s.concat(h),"identifier",!0),h]:void 0}function k(){_.apply(this,arguments);var t=u(this.handler,this);this.touch=new L(this.manager,t),this.mouse=new Y(this.manager,t)}function U(t,e){this.manager=t,this.set(e)}function j(t){if(v(t,te))return te;var e=v(t,ee),i=v(t,ie);return e&&i?ee+" "+ie:e||i?e?ee:ie:v(t,$t)?$t:Qt}function G(t){this.id=I(),this.manager=null,this.options=h(t||{},this.defaults),this.options.enable=l(this.options.enable,!0),this.state=ne,this.simultaneous={},this.requireFail=[]}function V(t){return t&ae?"cancel":t&oe?"end":t&se?"move":t&re?"start":""}function Z(t){return t==Nt?"down":t==zt?"up":t==Ct?"left":t==Rt?"right":""}function B(t,e){var i=e.manager;return i?i.get(t):t}function J(){G.apply(this,arguments)}function K(){J.apply(this,arguments),this.pX=null,this.pY=null}function Q(){J.apply(this,arguments)}function $(){G.apply(this,arguments),this._timer=null,this._input=null}function tt(){J.apply(this,arguments)}function et(){J.apply(this,arguments)}function it(){G.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function nt(t,e){return e=e||{},e.recognizers=l(e.recognizers,nt.defaults.preset),new rt(t,e)}function rt(t,e){e=e||{},this.options=h(e,nt.defaults),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.element=t,this.input=w(this),this.touchAction=new U(this,this.options.touchAction),st(this,!0),s(e.recognizers,function(t){var e=this.add(new t[0](t[1]));t[2]&&e.recognizeWith(t[2]),t[3]&&e.requireFailure(t[3])},this)}function st(t,e){var i=t.element;s(t.options.cssProps,function(t,n){i.style[E(i.style,n)]=e?t:""})}function ot(t,e){var i=document.createEvent("Event");i.initEvent(t,!0,!0),i.gesture=e,e.target.dispatchEvent(i)}var ht=["","webkit","moz","MS","ms","o"],at=document.createElement("div"),ut="function",ct=Math.round,lt=Math.abs,pt=Date.now,ft=1,dt=/mobile|tablet|ip(ad|hone|od)|android/i,vt="ontouchstart"in window,mt=void 0!==E(window,"PointerEvent"),gt=vt&&dt.test(navigator.userAgent),Tt="touch",yt="pen",Et="mouse",It="kinect",At=25,_t=1,wt=2,Dt=4,St=8,bt=1,Ct=2,Rt=4,zt=8,Nt=16,Pt=Ct|Rt,Mt=zt|Nt,Ot=Pt|Mt,xt=["x","y"],Xt=["clientX","clientY"];_.prototype={handler:function(){},init:function(){this.evEl&&p(this.element,this.evEl,this.domHandler),this.evTarget&&p(this.target,this.evTarget,this.domHandler),this.evWin&&p(A(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&f(this.element,this.evEl,this.domHandler),this.evTarget&&f(this.target,this.evTarget,this.domHandler),this.evWin&&f(A(this.element),this.evWin,this.domHandler)}};var Yt={mousedown:_t,mousemove:wt,mouseup:Dt},Ft="mousedown",Wt="mousemove mouseup";a(Y,_,{handler:function(t){var e=Yt[t.type];e&_t&&0===t.button&&(this.pressed=!0),e&wt&&1!==t.which&&(e=Dt),this.pressed&&this.allow&&(e&Dt&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:Et,srcEvent:t}))}});var qt={pointerdown:_t,pointermove:wt,pointerup:Dt,pointercancel:St,pointerout:St},Lt={2:Tt,3:yt,4:Et,5:It},Ht="pointerdown",kt="pointermove pointerup pointercancel";window.MSPointerEvent&&(Ht="MSPointerDown",kt="MSPointerMove MSPointerUp MSPointerCancel"),a(F,_,{handler:function(t){var e=this.store,i=!1,n=t.type.toLowerCase().replace("ms",""),r=qt[n],s=Lt[t.pointerType]||t.pointerType,o=s==Tt,h=g(e,t.pointerId,"pointerId");r&_t&&(0===t.button||o)?h<0&&(e.push(t),h=e.length-1):r&(Dt|St)&&(i=!0),h<0||(e[h]=t,this.callback(this.manager,r,{pointers:e,changedPointers:[t],pointerType:s,srcEvent:t}),i&&e.splice(h,1))}});var Ut={touchstart:_t,touchmove:wt,touchend:Dt,touchcancel:St},jt="touchstart",Gt="touchstart touchmove touchend touchcancel";a(W,_,{handler:function(t){var e=Ut[t.type];if(e===_t&&(this.started=!0),this.started){var i=q.call(this,t,e);e&(Dt|St)&&i[0].length-i[1].length===0&&(this.started=!1),this.callback(this.manager,e,{pointers:i[0],changedPointers:i[1],pointerType:Tt,srcEvent:t})}}});var Vt={touchstart:_t,touchmove:wt,touchend:Dt,touchcancel:St},Zt="touchstart touchmove touchend touchcancel";a(L,_,{handler:function(t){var e=Vt[t.type],i=H.call(this,t,e);i&&this.callback(this.manager,e,{pointers:i[0],changedPointers:i[1],pointerType:Tt,srcEvent:t})}}),a(k,_,{handler:function(t,e,i){var n=i.pointerType==Tt,r=i.pointerType==Et;if(n)this.mouse.allow=!1;else if(r&&!this.mouse.allow)return;e&(Dt|St)&&(this.mouse.allow=!0),this.callback(t,e,i)},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var Bt=E(at.style,"touchAction"),Jt=void 0!==Bt,Kt="compute",Qt="auto",$t="manipulation",te="none",ee="pan-x",ie="pan-y";U.prototype={set:function(t){t==Kt&&(t=this.compute()),Jt&&(this.manager.element.style[Bt]=t),this.actions=t.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var t=[];return s(this.manager.recognizers,function(e){c(e.options.enable,[e])&&(t=t.concat(e.getTouchAction()))}),j(t.join(" "))},preventDefaults:function(t){if(!Jt){var e=t.srcEvent,i=t.offsetDirection;if(this.manager.session.prevented)return void e.preventDefault();var n=this.actions,r=v(n,te),s=v(n,ie),o=v(n,ee);return r||s&&i&Pt||o&&i&Mt?this.preventSrc(e):void 0}},preventSrc:function(t){this.manager.session.prevented=!0,t.preventDefault()}};var ne=1,re=2,se=4,oe=8,he=oe,ae=16,ue=32;G.prototype={defaults:{},set:function(t){return o(this.options,t),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(t){if(r(t,"recognizeWith",this))return this;var e=this.simultaneous;return t=B(t,this),e[t.id]||(e[t.id]=t,t.recognizeWith(this)),this},dropRecognizeWith:function(t){return r(t,"dropRecognizeWith",this)?this:(t=B(t,this),delete this.simultaneous[t.id],this)},requireFailure:function(t){if(r(t,"requireFailure",this))return this;var e=this.requireFail;return t=B(t,this),g(e,t)===-1&&(e.push(t),t.requireFailure(this)),this},dropRequireFailure:function(t){if(r(t,"dropRequireFailure",this))return this;t=B(t,this);var e=g(this.requireFail,t);return e>-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){function e(e){i.manager.emit(i.options.event+(e?V(n):""),t)}var i=this,n=this.state;n<oe&&e(!0),e(),n>=oe&&e(!0)},tryEmit:function(t){return this.canEmit()?this.emit(t):void(this.state=ue)},canEmit:function(){for(var t=0;t<this.requireFail.length;){if(!(this.requireFail[t].state&(ue|ne)))return!1;t++}return!0},recognize:function(t){var e=o({},t);return c(this.options.enable,[this,e])?(this.state&(he|ae|ue)&&(this.state=ne),this.state=this.process(e),void(this.state&(re|se|oe|ae)&&this.tryEmit(e))):(this.reset(),void(this.state=ue))},process:function(t){},getTouchAction:function(){},reset:function(){}},a(J,G,{defaults:{pointers:1},attrTest:function(t){var e=this.options.pointers;return 0===e||t.pointers.length===e},process:function(t){var e=this.state,i=t.eventType,n=e&(re|se),r=this.attrTest(t);return n&&(i&St||!r)?e|ae:n||r?i&Dt?e|oe:e&re?e|se:re:ue}}),a(K,J,{defaults:{event:"pan",threshold:10,pointers:1,direction:Ot},getTouchAction:function(){var t=this.options.direction,e=[];return t&Pt&&e.push(ie),t&Mt&&e.push(ee),e},directionTest:function(t){var e=this.options,i=!0,n=t.distance,r=t.direction,s=t.deltaX,o=t.deltaY;return r&e.direction||(e.direction&Pt?(r=0===s?bt:s<0?Ct:Rt,i=s!=this.pX,n=Math.abs(t.deltaX)):(r=0===o?bt:o<0?zt:Nt,i=o!=this.pY,n=Math.abs(t.deltaY))),t.direction=r,i&&n>e.threshold&&r&e.direction},attrTest:function(t){return J.prototype.attrTest.call(this,t)&&(this.state&re||!(this.state&re)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Z(t.direction);e&&this.manager.emit(this.options.event+e,t),this._super.emit.call(this,t)},reset:function(){}}),a(Q,J,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[te]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||this.state&re)},emit:function(t){if(this._super.emit.call(this,t),1!==t.scale){var e=t.scale<1?"in":"out";this.manager.emit(this.options.event+e,t)}}}),a($,G,{defaults:{event:"press",pointers:1,time:500,threshold:5},getTouchAction:function(){return[Qt]},process:function(t){var e=this.options,i=t.pointers.length===e.pointers,r=t.distance<e.threshold,s=t.deltaTime>e.time;if(this._input=t,!r||!i||t.eventType&(Dt|St)&&!s)this.reset();else if(t.eventType&_t)this.reset(),this._timer=n(function(){this.state=he,this.tryEmit()},e.time,this);else if(t.eventType&Dt)return he;return ue},reset:function(){clearTimeout(this._timer)},emit:function(t){this.state===he&&(t&&t.eventType&Dt?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=pt(),this.manager.emit(this.options.event,this._input)))}}),a(tt,J,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[te]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||this.state&re)}}),a(et,J,{defaults:{event:"swipe",threshold:10,velocity:.65,direction:Pt|Mt,pointers:1},getTouchAction:function(){return K.prototype.getTouchAction.call(this)},attrTest:function(t){var e,i=this.options.direction;return i&(Pt|Mt)?e=t.velocity:i&Pt?e=t.velocityX:i&Mt&&(e=t.velocityY),this._super.attrTest.call(this,t)&&i&t.direction&&t.distance>this.options.threshold&<(e)>this.options.velocity&&t.eventType&Dt},emit:function(t){var e=Z(t.direction);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),a(it,G,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:10,posThreshold:10},getTouchAction:function(){return[$t]},process:function(t){var e=this.options,i=t.pointers.length===e.pointers,r=t.distance<e.threshold,s=t.deltaTime<e.time;if(this.reset(),t.eventType&_t&&0===this.count)return this.failTimeout();if(r&&s&&i){if(t.eventType!=Dt)return this.failTimeout();var o=!this.pTime||t.timeStamp-this.pTime<e.interval,h=!this.pCenter||M(this.pCenter,t.center)<e.posThreshold;this.pTime=t.timeStamp,this.pCenter=t.center,h&&o?this.count+=1:this.count=1,this._input=t;var a=this.count%e.taps;if(0===a)return this.hasRequireFailures()?(this._timer=n(function(){this.state=he,this.tryEmit()},e.interval,this),re):he}return ue},failTimeout:function(){return this._timer=n(function(){this.state=ue},this.options.interval,this),ue},reset:function(){clearTimeout(this._timer)},emit:function(){this.state==he&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),nt.VERSION="2.0.4",nt.defaults={domEvents:!1,touchAction:Kt,enable:!0,inputTarget:null,inputClass:null,preset:[[tt,{enable:!1}],[Q,{enable:!1},["rotate"]],[et,{direction:Pt}],[K,{direction:Pt},["swipe"]],[it],[it,{event:"doubletap",taps:2},["tap"]],[$]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};var ce=1,le=2;return rt.prototype={set:function(t){return o(this.options,t),t.touchAction&&this.touchAction.update(),t.inputTarget&&(this.input.destroy(),this.input.target=t.inputTarget,this.input.init()),this},stop:function(t){this.session.stopped=t?le:ce},recognize:function(t){var e=this.session;if(!e.stopped){this.touchAction.preventDefaults(t);var i,n=this.recognizers,r=e.curRecognizer;(!r||r&&r.state&he)&&(r=e.curRecognizer=null);for(var s=0;s<n.length;)i=n[s],e.stopped===le||r&&i!=r&&!i.canRecognizeWith(r)?i.reset():i.recognize(t),!r&&i.state&(re|se|oe)&&(r=e.curRecognizer=i),s++}},get:function(t){if(t instanceof G)return t;for(var e=this.recognizers,i=0;i<e.length;i++)if(e[i].options.event==t)return e[i];return null},add:function(t){if(r(t,"add",this))return this;var e=this.get(t.options.event);return e&&this.remove(e),this.recognizers.push(t),t.manager=this,this.touchAction.update(),t},remove:function(t){if(r(t,"remove",this))return this;var e=this.recognizers;return t=this.get(t),e.splice(g(e,t),1),this.touchAction.update(),this},on:function(t,e){var i=this.handlers;return s(m(t),function(t){i[t]=i[t]||[],i[t].push(e)}),this},off:function(t,e){var i=this.handlers;return s(m(t),function(t){e?i[t].splice(g(i[t],e),1):delete i[t]}),this},emit:function(t,e){this.options.domEvents&&ot(t,e);var i=this.handlers[t]&&this.handlers[t].slice();if(i&&i.length){e.type=t,e.preventDefault=function(){e.srcEvent.preventDefault()};for(var n=0;n<i.length;)i[n](e),n++}},destroy:function(){this.element&&st(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},o(nt,{INPUT_START:_t,INPUT_MOVE:wt,INPUT_END:Dt,INPUT_CANCEL:St,STATE_POSSIBLE:ne,STATE_BEGAN:re,STATE_CHANGED:se,STATE_ENDED:oe,STATE_RECOGNIZED:he,STATE_CANCELLED:ae,STATE_FAILED:ue,DIRECTION_NONE:bt,DIRECTION_LEFT:Ct,DIRECTION_RIGHT:Rt,DIRECTION_UP:zt,DIRECTION_DOWN:Nt,DIRECTION_HORIZONTAL:Pt,DIRECTION_VERTICAL:Mt,DIRECTION_ALL:Ot,Manager:rt,Input:_,TouchAction:U,TouchInput:L,MouseInput:Y,PointerEventInput:F,TouchMouseInput:k,SingleTouchInput:W,Recognizer:G,AttrRecognizer:J,Tap:it,Pan:K,Swipe:et,Pinch:Q,Rotate:tt,Press:$,on:p,off:f,each:s,merge:h,extend:o,inherit:a,bindFn:u,prefixed:E}),"object"==typeof i&&i.exports?void(i.exports=nt):nt});
|