-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathquo.gestures.js
8 lines (8 loc) · 5.59 KB
/
quo.gestures.js
1
2
3
4
5
6
7
8
/**
* QuoJS - Micro #JavaScript Library for Mobile Devices.
* @version v3.0.7
* @link http://quojs.tapquo.com
* @author Javi Jimenez Villar (@soyjavi) (https://twitter.com/soyjavi)
* @license MIT
*/
(function(){"use strict";var t=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};Quo.Gestures=function(n){var e,r,u,i,a,l,o,d,c,s,g,h,f,v;return h=!1,d={},a=null,s=null,u=["input","select","textarea"],f=function(t){return d[t.name]=t.handler,e(t.events)},v=function(t,e,r){return n(t).trigger(e,r,s)},g=function(n){var e;return e=(n.srcElement||n.target).tagName.toLowerCase(),t.call(u,e)>=0?n.stopPropagation():(h=!0,s=n||event,a=l(n),o("start",n.target,a))},c=function(t){return h?(s=t||event,a=l(t),a.length>1&&s.preventDefault(),o("move",t.target,a)):void 0},i=function(t){return h?(s=t||event,o("end",t.target,a),h=!1):void 0},r=function(t){return h=!1,o("cancel")},e=function(t){return t.forEach(function(t){return n.fn[t]=function(e){return n(document.body).delegate(this.selector,t,e)}}),this},o=function(t,n,e){var r,u,i;i=[];for(u in d)r=d[u],r[t]&&i.push(r[t].call(r,n,e));return i},l=function(t){var n,e,r,u,i;for(r=t.touches||[t],u=[],n=0,e=r.length;e>n;n++)i=r[n],u.push({x:i.pageX,y:i.pageY});return u},n(document).ready(function(){var t;return t=n(document.body),t.bind("touchstart",g),t.bind("touchmove",c),t.bind("touchend",i),t.bind("touchcancel",r)}),{add:f,trigger:v}}(Quo),Quo.Gestures.add({name:"basic",events:["touch","hold","doubleTap"],handler:function(t){var n,e,r,u,i,a,l,o,d,c,s,g;return e=15,n={TAP:200,DOUBLE_TAP:400,HOLD:400},u=null,o=!0,l=null,a=null,i=null,g=function(e,r){return 1===r.length?(a={time:new Date,x:r[0].x,y:r[0].y},l=e,u=setTimeout(function(){return t.trigger(e,"hold",r[0])},n.HOLD)):d()},s=function(t,n){var u;return null!==a&&(u=r(a,n[0]),u.x>e||u.y>e||n.length>1)?d():void 0},c=function(e,l){var o,c;if(a)return o=r(a,l[0]),0!==o.x||0!==o.y?d():(clearTimeout(u),c=new Date,c-a.time<n.TAP?c-i<n.DOUBLE_TAP?(t.trigger(e,"doubleTap",l[0]),i=null):(i=c,t.trigger(e,"touch",l[0])):void 0)},d=function(){return a=null,o=!1,clearTimeout(u)},r=function(t,n){var e;return e={x:n.x-t.x,y:n.y-t.y}},{start:g,move:s,end:c,cancel:d}}(Quo.Gestures)}),Quo.Gestures.add({name:"drag",events:["drag","dragging"],handler:function(t){var n,e,r,u,i,a,l,o,d,c,s,g;return n=window.devicePixelRatio>=2?15:20,o=null,a=null,l=null,i=null,g=function(t,n){return n.length>=2?(o=t,a=n.length,l=e(n)):void 0},s=function(t,n){var e;return n.length===a?(e=r(n),i={touches:n,delta:e},u(!0)):void 0},d=c=function(t,n){return l&&i?(u(!1),a=null,l=null,i=null):void 0},r=function(t){var n;return n=e(t),{x:n.x-l.x,y:n.y-l.y}},e=function(t){var n,e,r,u,i;for(u=0,i=0,n=0,e=t.length;e>n;n++)r=t[n],u+=parseInt(r.x),i+=parseInt(r.y);return{x:u/t.length,y:i/t.length}},u=function(e){return e?t.trigger(o,"dragging",i):Math.abs(i.delta.x)>n||Math.abs(i.delta.y)>n?t.trigger(o,"drag",i):void 0},{start:g,move:s,end:c}}(Quo.Gestures)}),Quo.Gestures.add({name:"pinch",events:["pinch","pinching","pinchIn","pinchOut"],handler:function(t){var n,e,r,u,i,a,l,o,d,c;return n=window.devicePixelRatio>=2?15:20,a=null,i=null,u=null,c=function(t,n){return 2===n.length?(a=t,i=r(n[0],n[1])):void 0},d=function(t,n){var a;return i&&2===n.length?(a=r(n[0],n[1]),u={touches:n,delta:a-i},e(!0)):void 0},l=o=function(t,n){return i&&u?(e(!1),i=null,u=null):void 0},r=function(t,n){return Math.sqrt((n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y))},e=function(e){var r;return e?t.trigger(a,"pinching",u):Math.abs(u.delta)>n?(t.trigger(a,"pinch",u),r=u.delta>0?"pinchOut":"pinchIn",t.trigger(a,r,u)):void 0},{start:c,move:d,end:o}}(Quo.Gestures)}),Quo.Gestures.add({name:"rotation",events:["rotate","rotating","rotateLeft","rotateRight"],handler:function(t){var n,e,r,u,i,a,l,o,d,c,s,g,h;return n=5,e=20,d=null,i=0,o=null,u=null,h=function(t,n){return 2===n.length?(d=t,i=0,o=a(n[0],n[1])):void 0},g=function(t,n){var d;return o&&2===n.length?(d=a(n[0],n[1])-o,u&&Math.abs(u.delta-d)>e&&(d+=360*l(u.delta)),Math.abs(d)>360&&(i++,d-=360*l(u.delta)),u={touches:n,delta:d,rotationsCount:i},r(!0)):void 0},c=s=function(t,n){return o&&u?(r(!1),d=null,i=0,o=null,u=null,o=null):void 0},l=function(t){return 0>t?-1:1},a=function(t,n){var e;return e=Math.atan2(t.y-n.y,t.x-n.x),180*(0>e?e+2*Math.PI:e)/Math.PI},r=function(e){var r;return e?t.trigger(d,"rotating",u):Math.abs(u.delta)>n?(t.trigger(d,"rotate",u),r=u.delta>0?"rotateRight":"rotateLeft",t.trigger(d,r,u)):void 0},{start:h,move:g,end:s}}(Quo.Gestures)}),Quo.Gestures.add({name:"swipe",events:["swipe","swipeLeft","swipeRight","swipeUp","swipeDown","swiping","swipingHorizontal","swipingVertical"],handler:function(t){var n,e,r,u,i,a,l,o,d,c,s;return n=Math.round(20/window.devicePixelRatio),l=null,i=null,a=null,u=null,s=function(t,n){return 1===n.length?(l=t,i=n[0],u=null):void 0},c=function(t,n){var r,a;return 1===n.length?(r={x:n[0].x-i.x,y:n[0].y-i.y},a=null===u,u={x:n[0].x,y:n[0].y,delta:r},e(!0,a)):u=null},o=d=function(t,n){var r;return null==u&&n.length>=1&&(r={x:n[0].x-i.x,y:n[0].y-i.y},u={x:n[0].x,y:n[0].y,delta:r}),u?(e(!1),u=null):void 0},e=function(e,i){var o,d,c,s,g;if(null==i&&(i=!1),e)return i&&(a=r(u.delta.x,u.delta.y)),null!==a&&t.trigger(l,"swiping"+a,u),t.trigger(l,"swiping",u);if(d=[],Math.abs(u.delta.y)>n?d.push(u.delta.y<0?"Up":"Down"):Math.abs(u.delta.x)>n&&d.push(u.delta.x<0?"Left":"Right"),d.length){for(t.trigger(l,"swipe",u),g=[],c=0,s=d.length;s>c;c++)o=d[c],g.push(t.trigger(l,"swipe"+o,u));return g}},r=function(t,n){var e;return e=null,Math.round(Math.abs(t/n))>=2?e="Horizontal":Math.round(Math.abs(n/t))>=2&&(e="Vertical"),e},{start:s,move:c,end:d}}(Quo.Gestures)})}).call(this);