Component-Builder/media/uikit-v2/js/core/touch.min.js

2 lines
2.7 KiB
JavaScript

/*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
!function(e){function t(e,t,n,o){return Math.abs(e-t)>=Math.abs(n-o)?e-t>0?"Left":"Right":n-o>0?"Up":"Down"}function n(){c=null,g.last&&(void 0!==g.el&&g.el.trigger("longTap"),g={})}function o(){c&&clearTimeout(c),c=null}function i(){a&&clearTimeout(a),l&&clearTimeout(l),u&&clearTimeout(u),c&&clearTimeout(c),a=l=u=c=null,g={}}function r(e){return e.pointerType==e.MSPOINTER_TYPE_TOUCH&&e.isPrimary}if(!e.fn.swipeLeft){var a,l,u,c,p,g={},s=750,v="ontouchstart"in window,w=window.PointerEvent,d=v||window.DocumentTouch&&document instanceof DocumentTouch||navigator.msPointerEnabled&&navigator.msMaxTouchPoints>0||navigator.pointerEnabled&&navigator.maxTouchPoints>0;e(function(){var y,T,f,h=0,M=0;"MSGesture"in window&&(p=new MSGesture,p.target=document.body),e(document).on("MSGestureEnd gestureend",function(e){var t=e.originalEvent.velocityX>1?"Right":e.originalEvent.velocityX<-1?"Left":e.originalEvent.velocityY>1?"Down":e.originalEvent.velocityY<-1?"Up":null;t&&void 0!==g.el&&(g.el.trigger("swipe"),g.el.trigger("swipe"+t))}).on("touchstart MSPointerDown pointerdown",function(t){("MSPointerDown"!=t.type||r(t.originalEvent))&&(f="MSPointerDown"==t.type||"pointerdown"==t.type?t:t.originalEvent.touches[0],y=Date.now(),T=y-(g.last||y),g.el=e("tagName"in f.target?f.target:f.target.parentNode),a&&clearTimeout(a),g.x1=f.pageX,g.y1=f.pageY,T>0&&250>=T&&(g.isDoubleTap=!0),g.last=y,c=setTimeout(n,s),t.originalEvent&&t.originalEvent.pointerId&&p&&("MSPointerDown"==t.type||"pointerdown"==t.type||"touchstart"==t.type)&&p.addPointer(t.originalEvent.pointerId))}).on("touchmove MSPointerMove pointermove",function(e){("MSPointerMove"!=e.type||r(e.originalEvent))&&(f="MSPointerMove"==e.type||"pointermove"==e.type?e:e.originalEvent.touches[0],o(),g.x2=f.pageX,g.y2=f.pageY,h+=Math.abs(g.x1-g.x2),M+=Math.abs(g.y1-g.y2))}).on("touchend MSPointerUp pointerup",function(n){("MSPointerUp"!=n.type||r(n.originalEvent))&&(o(),g.x2&&Math.abs(g.x1-g.x2)>30||g.y2&&Math.abs(g.y1-g.y2)>30?u=setTimeout(function(){void 0!==g.el&&(g.el.trigger("swipe"),g.el.trigger("swipe"+t(g.x1,g.x2,g.y1,g.y2))),g={}},0):"last"in g&&(isNaN(h)||30>h&&30>M?l=setTimeout(function(){var t=e.Event("tap");t.cancelTouch=i,void 0!==g.el&&g.el.trigger(t),g.isDoubleTap?(void 0!==g.el&&g.el.trigger("doubleTap"),g={}):a=setTimeout(function(){a=null,void 0!==g.el&&g.el.trigger("singleTap"),g={}},250)},0):g={},h=M=0))}).on("touchcancel MSPointerCancel pointercancel",function(e){("touchcancel"==e.type&&v&&d||!v&&"pointercancel"==e.type&&w)&&i()}),e(window).on("scroll",i)}),["swipe","swipeLeft","swipeRight","swipeUp","swipeDown","doubleTap","tap","singleTap","longTap"].forEach(function(t){e.fn[t]=function(n){return e(this).on(t,n)}})}}(jQuery);