-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.ui.touch-punch.min.js
1 lines (1 loc) · 2.49 KB
/
jquery.ui.touch-punch.min.js
1
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","jquery-ui"],factory)}else{factory(jQuery)}})(function($){var pointerEnabled=window.navigator.pointerEnabled||window.navigator.msPointerEnabled;$.support.touch="ontouchend"in document||pointerEnabled;if(!$.support.touch||!$.ui.mouse){return}var mouseProto=$.ui.mouse.prototype,_mouseInit=mouseProto._mouseInit,touchHandled;function fixTouch(touch){var winPageX=window.pageXOffset,winPageY=window.pageYOffset,x=touch.clientX,y=touch.clientY;if(touch.pageY===0&&Math.floor(y)>Math.floor(touch.pageY)||touch.pageX===0&&Math.floor(x)>Math.floor(touch.pageX)){x=x-winPageX;y=y-winPageY}else if(y<touch.pageY-winPageY||x<touch.pageX-winPageX){x=touch.pageX-winPageX;y=touch.pageY-winPageY}return{clientX:x,clientY:y}}function simulateMouseEvent(event,simulatedType){if(!pointerEnabled&&event.originalEvent.touches.length>1||pointerEnabled&&!event.isPrimary){return}var touch=pointerEnabled?event.originalEvent:event.originalEvent.changedTouches[0],simulatedEvent=document.createEvent("MouseEvents"),coord=fixTouch(touch);if($(touch.target).is("input")||$(touch.target).is("textarea")){event.stopPropagation()}else{event.preventDefault()}simulatedEvent.initMouseEvent(simulatedType,true,true,window,1,event.screenX||touch.screenX,event.screenY||touch.screenY,event.clientX||coord.clientX,event.clientY||coord.clientY,false,false,false,false,0,null);event.target.dispatchEvent(simulatedEvent)}mouseProto._touchStart=function(event){var self=this;if(touchHandled||!pointerEnabled&&!self._mouseCapture(event.originalEvent.changedTouches[0])){return}touchHandled=true;self._touchMoved=false;simulateMouseEvent(event,"mouseover");simulateMouseEvent(event,"mousemove");simulateMouseEvent(event,"mousedown")};mouseProto._touchMove=function(event){if(!touchHandled){return}this._touchMoved=true;simulateMouseEvent(event,"mousemove")};mouseProto._touchEnd=function(event){if(!touchHandled){return}simulateMouseEvent(event,"mouseup");simulateMouseEvent(event,"mouseout");if(!this._touchMoved){simulateMouseEvent(event,"click")}touchHandled=false};mouseProto._mouseInit=function(){var self=this;self.element.on({touchstart:$.proxy(self,"_touchStart"),touchmove:$.proxy(self,"_touchMove"),touchend:$.proxy(self,"_touchEnd"),pointerDown:$.proxy(self,"_touchStart"),pointerMove:$.proxy(self,"_touchMove"),pointerUp:$.proxy(self,"_touchEnd"),MSPointerDown:$.proxy(self,"_touchStart"),MSPointerMove:$.proxy(self,"_touchMove"),MSPointerUp:$.proxy(self,"_touchEnd")});_mouseInit.call(self)}});