forked from RyanMullins/angular-hammer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular.hammer.min.js
8 lines (8 loc) · 5.96 KB
/
angular.hammer.min.js
1
2
3
4
5
6
7
8
// ---- Angular Hammer ----
// Copyright (c) 2015 Ryan S Mullins <ryan@ryanmullins.org>
// Licensed under the MIT Software License
//
// (fairly heavy) modifications by James Wilson <me@unbui.lt>
//
!function(a,b){"use strict";function c(a,c){if(void 0===a||void 0===c)return null;var d;return d=c.indexOf("pan")>-1?new b.Pan:c.indexOf("pinch")>-1?new b.Pinch:c.indexOf("press")>-1?new b.Press:c.indexOf("rotate")>-1?new b.Rotate:c.indexOf("swipe")>-1?new b.Swipe:new b.Tap,a.add(d),d}function d(a,b){return a&&(b.preventGhosts=a.preventGhosts),b}function e(a){return a.indexOf("pan")>-1?"pan":a.indexOf("pinch")>-1?"pinch":a.indexOf("press")>-1?"press":a.indexOf("rotate")>-1?"rotate":a.indexOf("swipe")>-1?"swipe":a.indexOf("tap")>-1?"tap":"custom"}function f(a,b,d){if(null==a||null==b||null==b.type)return console.error("ERROR: Angular Hammer could not setup the recognizer. Values of the passed manager and options: ",a,b);var e=a.get(b._name);if(e||(e=c(a,b._name)),b.directions||("pan"===b._name||"swipe"===b._name?b.directions="DIRECTION_ALL":b._name.indexOf("left")>-1?b.directions="DIRECTION_LEFT":b._name.indexOf("right")>-1?b.directions="DIRECTION_RIGHT":b._name.indexOf("up")>-1?b.directions="DIRECTION_UP":b._name.indexOf("down")>-1?b.directions="DIRECTION_DOWN":b.directions=""),b.direction=g(b.directions),e.set(b),"string"==typeof b.recognizeWith){var f;null==a.get(b.recognizeWith)&&(f=c(a,b.recognizeWith)),null!=f&&e.recognizeWith(f)}if("string"==typeof b.dropRecognizeWith&&null!=a.get(b.dropRecognizeWith)&&e.dropRecognizeWith(a.get(b.dropRecognizeWith)),"string"==typeof b.requireFailure){var i;null==a.get(b.requireFailure)&&(i=c(a,{type:b.requireFailure})),null!=i&&e.requireFailure(i)}"string"==typeof b.dropRequireFailure&&null!=a.get(b.dropRequireFailure)&&e.dropRequireFailure(a.get(b.dropRequireFailure)),b.preventGhosts===!0&&null!=d&&h(d)}function g(c){var d=0;return a.forEach(c.split("|"),function(a){b.hasOwnProperty(a)&&(d|=b[a])}),d}function h(a){function b(a){for(var b=0;b<f.length;b++){var c=f[b][0],d=f[b][1];if(Math.abs(a.clientX-c)<g&&Math.abs(a.clientY-d)<g){a.stopPropagation(),a.preventDefault();break}}}function c(){f=[]}function d(){f.splice(0,1)}function e(a){if(a.touches.length-a.changedTouches.length<=0){var b=a.changedTouches[0];f.push([b.clientX,b.clientY]),setTimeout(d,h)}}if(a){var f=[],g=25,h=2500;"ontouchstart"in window&&(a[0].addEventListener("touchstart",c,!0),a[0].addEventListener("touchend",e,!0),a[0].addEventListener("click",b,!0),a[0].addEventListener("mouseup",b,!0))}}if("undefined"==typeof a)throw Error("angular-hammer: AngularJS (angular) is undefined but is necessary.");if("undefined"==typeof b)throw Error("angular-hammer: HammerJS (Hammer) is undefined but is necessary.");var i=["hmCustom:custom","hmSwipe:swipe","hmSwipeleft:swipeleft","hmSwiperight:swiperight","hmSwipeup:swipeup","hmSwipedown:swipedown","hmPan:pan","hmPanstart:panstart","hmPanmove:panmove","hmPanend:panend","hmPancancel:pancancel","hmPanleft:panleft","hmPanright:panright","hmPanup:panup","hmPandown:pandown","hmPress:press","hmPressup:pressup","hmRotate:rotate","hmRotatestart:rotatestart","hmRotatemove:rotatemove","hmRotateend:rotateend","hmRotatecancel:rotatecancel","hmPinch:pinch","hmPinchstart:pinchstart","hmPinchmove:pinchmove","hmPinchend:pinchend","hmPinchcancel:pinchcancel","hmPinchin:pinchin","hmPinchout:pinchout","hmTap:tap","hmDoubletap:doubletap"],j="hmTouchEvents",k=a.module("hmTouchEvents",[]);k.provider(j,function(){function c(b){return b=a.copy(b),b.event?"doubletap"==b.event?(b.type="tap",b.taps||(b.taps=2),b._name="doubletap"):b._name=!1:b._name=b.type||!1,b}function d(a){if("custom"==a)throw Error(j+"Provider: no defaults exist for custom events");var b=e(a);return c("doubletap"==a?{type:b,event:"doubletap"}:{type:b})}var f=this,g=!1,h={},i={},k={};k[b.Tap.toString()]="tap",k[b.Pan.toString()]="pan",k[b.Pinch.toString()]="pinch",k[b.Press.toString()]="press",k[b.Rotate.toString()]="rotate",k[b.Swipe.toString()]="swipe",f.applyHammerPresets=function(){var d=b.defaults.preset;a.forEach(d,function(a){var b=a[1];b.type||(b.type=k[a[0]]),b=c(b),b._name&&(h[b._name]=b)})},f.addManagerOption=function(b,c){"object"==typeof b?a.extend(i,b):i[b]=c},f.addRecognizerOption=function(a){if(Array.isArray(a))for(var b=0;b<a.length;b++)f.addRecognizerOption(a[b]);else{if("object"!=typeof a)throw Error(j+"Provider: addRecognizerOption: should be object or array of objects");a=c(a),a._name?h[a.type]=a:a.event||(g=a)}},f.$get=function(){return{extendWithDefaultManagerOpts:function(b){b="object"!=typeof b?{}:a.copy(b);for(var c in i)b[c]||(b[c]=a.copy(i[c]));return b},extendWithDefaultRecognizerOpts:function(b,f){if("object"!=typeof f&&(f=[]),Array.isArray(f)||(f=[f]),"custom"==b)return f;var i,j=e(b),k=h[b]||h[j],l=!1,m=a.extend({},g||{},k||{});return f.forEach(function(c){return c.event||c.type?void(l||(c.event==b?(i=c,l=!0):c.event||c.type!=j||(i=c))):a.extend(m,c)}),i=i?c(i):d(b),[a.extend(m,i)]}}}}),a.forEach(i,function(c){var g=c.split(":"),h=g[0],i=g[1];k.directive(h,["$parse","$window",j,function(c,g,k){return{restrict:"A",scope:!1,link:function(l,m,n){if(!b||!g.addEventListener)throw Error(j+": window.Hammer or window.addEventListener not found, can't add event "+h);var o=m.data("hammer"),p=k.extendWithDefaultManagerOpts(l.$eval(n.hmManagerOptions)),q=k.extendWithDefaultRecognizerOpts(i,l.$eval(n.hmRecognizerOptions));o||(o=new b.Manager(m[0],p),m.data("hammer",o),l.$on("$destroy",function(){o.destroy()}));var r=c(n[h]).bind(null,l),s=function(b){b.element=m;var c=!0,d=o.get(e(b.type));if(d){var f=d.options;f.preventDefault&&b.preventDefault(),f.stopPropagation&&b.srcEvent.stopPropagation(),c=a.isUndefined(f.invokeApply)||f.invokeApply}c?l.$apply(function(){r({$event:b})}):r({$event:b})};a.forEach(q,function(a){"custom"!==i&&("doubletap"===i&&o.get("tap")?a.recognizeWith="tap":"pan"==a.type&&o.get("swipe")?a.recognizeWith="swipe":"pinch"==a.type&&o.get("rotate")&&(a.recognizeWith="rotate")),f(o,d(p,a),m),o.on(i,s)})}}}])})}(angular,Hammer);
//# sourceMappingURL=angular.hammer.min.js.map