-
Notifications
You must be signed in to change notification settings - Fork 3
/
angular-touch.min.js
13 lines (13 loc) · 3.54 KB
/
angular-touch.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
AngularJS v1.3.0-local+sha.363fb4f
(c) 2010-2014 Google, Inc. http://angularjs.org
License: MIT
*/
(function(y,u,z){'use strict';function t(h,k,s){r.directive(h,["$parse","$swipe",function(b,d){var p=75,m=0.3,g=30;return function(f,q,e){function l(a){if(!c)return!1;var b=Math.abs(a.y-c.y);a=(a.x-c.x)*k;return v&&b<p&&0<a&&a>g&&b/a<m}var a=b(e[h]),c,v,n=["touch"];u.isDefined(e.ngSwipeDisableMouse)||n.push("mouse");d.bind(q,{start:function(a,b){c=a;v=!0},cancel:function(a){v=!1},end:function(c,b){l(c)&&f.$apply(function(){q.triggerHandler(s);a(f,{$event:b})})}},n)}}])}var r=u.module("ngTouch",[]);
r.factory("$swipe",[function(){function h(b){var d=b.touches&&b.touches.length?b.touches:[b];b=b.changedTouches&&b.changedTouches[0]||b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]||d[0].originalEvent||d[0];return{x:b.clientX,y:b.clientY}}function k(b,d){var p=[];u.forEach(b,function(b){(b=s[b][d])&&p.push(b)});return p.join(" ")}var s={mouse:{start:"mousedown",move:"mousemove",end:"mouseup"},touch:{start:"touchstart",move:"touchmove",end:"touchend",cancel:"touchcancel"}};
return{bind:function(b,d,p){var m,g,f,q,e=!1;p=p||["mouse","touch"];b.on(k(p,"start"),function(a){f=h(a);e=!0;g=m=0;q=f;d.start&&d.start(f,a)});var l=k(p,"cancel");if(l)b.on(l,function(a){e=!1;d.cancel&&d.cancel(a)});b.on(k(p,"move"),function(a){if(e&&f){var c=h(a);m+=Math.abs(c.x-q.x);g+=Math.abs(c.y-q.y);q=c;10>m&&10>g||(g>m?(e=!1,d.cancel&&d.cancel(a)):(a.preventDefault(),d.move&&d.move(c,a)))}});b.on(k(p,"end"),function(a){e&&(e=!1,d.end&&d.end(h(a),a))})}}}]);r.config(["$provide",function(h){h.decorator("ngClickDirective",
["$delegate",function(k){k.shift();return k}])}]);r.directive("ngClick",["$parse","$timeout","$rootElement",function(h,k,s){function b(a,c,b){for(var n=0;n<a.length;n+=2)if(Math.abs(a[n]-c)<g&&Math.abs(a[n+1]-b)<g)return a.splice(n,n+2),!0;return!1}function d(a){if(!(Date.now()-q>m)){var c=a.touches&&a.touches.length?a.touches:[a],d=c[0].clientX,c=c[0].clientY;1>d&&1>c||l&&l[0]===d&&l[1]===c||(l&&(l=null),"label"===a.target.tagName.toLowerCase()&&(l=[d,c]),b(e,d,c)||(a.stopPropagation(),a.preventDefault(),
a.target&&a.target.blur()))}}function p(a){a=a.touches&&a.touches.length?a.touches:[a];var c=a[0].clientX,b=a[0].clientY;e.push(c,b);k(function(){for(var a=0;a<e.length;a+=2)if(e[a]==c&&e[a+1]==b){e.splice(a,a+2);break}},m,!1)}var m=2500,g=25,f="ng-click-active",q,e,l;return function(a,c,k){function n(){m=!1;c.removeClass(f)}var l=h(k.ngClick),m=!1,g,r,t,w;c.on("touchstart",function(a){m=!0;g=a.target?a.target:a.srcElement;3==g.nodeType&&(g=g.parentNode);c.addClass(f);r=Date.now();a=a.touches&&a.touches.length?
a.touches:[a];a=a[0].originalEvent||a[0];t=a.clientX;w=a.clientY});c.on("touchmove",function(a){n()});c.on("touchcancel",function(a){n()});c.on("touchend",function(a){var l=Date.now()-r,f=a.changedTouches&&a.changedTouches.length?a.changedTouches:a.touches&&a.touches.length?a.touches:[a],h=f[0].originalEvent||f[0],f=h.clientX,h=h.clientY,x=Math.sqrt(Math.pow(f-t,2)+Math.pow(h-w,2));m&&(750>l&&12>x)&&(e||(s[0].addEventListener("click",d,!0),s[0].addEventListener("touchstart",p,!0),e=[]),q=Date.now(),
b(e,f,h),g&&g.blur(),u.isDefined(k.disabled)&&!1!==k.disabled||c.triggerHandler("click",[a]));n()});c.onclick=function(a){};c.on("click",function(b,c){a.$apply(function(){l(a,{$event:c||b})})});c.on("mousedown",function(a){c.addClass(f)});c.on("mousemove mouseup",function(a){c.removeClass(f)})}}]);t("ngSwipeLeft",-1,"swipeleft");t("ngSwipeRight",1,"swiperight")})(window,window.angular);
//# sourceMappingURL=angular-touch.min.js.map