17 lines
2.3 KiB
JavaScript
17 lines
2.3 KiB
JavaScript
/*!
|
||
* jQuery UI Touch Punch 1.0.5 as modified by RWAP Software
|
||
* based on original touchpunch v0.2.3 which has not been updated since 2014
|
||
*
|
||
* Updates by RWAP Software to take account of various suggested changes on the original code issues
|
||
*
|
||
* Original: https://github.com/furf/jquery-ui-touch-punch
|
||
* Copyright 2011–2014, Dave Furfero
|
||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||
*
|
||
* Fork: https://github.com/RWAP/jquery-ui-touch-punch
|
||
*
|
||
* Depends:
|
||
* jquery.ui.widget.js
|
||
* jquery.ui.mouse.js
|
||
*/
|
||
(function(t){if(typeof define==="function"&&define.amd){define(["jquery","jquery.ui"],t)}else{t(jQuery)}})((function(t){t.support.touch="ontouchstart"in document||"ontouchstart"in window||window.TouchEvent||window.DocumentTouch&&document instanceof DocumentTouch||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;if(!t.support.touch||!t.ui.mouse){return}var e=t.ui.mouse.prototype,o=e._mouseInit,n=e._mouseDestroy,u;function i(t){return{x:t.originalEvent.changedTouches[0].pageX,y:t.originalEvent.changedTouches[0].pageY}}function c(t,e){if(t.originalEvent.touches.length>1){return}t.preventDefault();var o=t.originalEvent.changedTouches[0],n=document.createEvent("MouseEvents");n.initMouseEvent(e,true,true,window,1,o.screenX,o.screenY,o.clientX,o.clientY,false,false,false,false,0,null);t.target.dispatchEvent(n)}e._touchStart=function(t){var e=this;if(u||!e._mouseCapture(t.originalEvent.changedTouches[0])){return}u=true;e._startPos=i(t);e._touchMoved=false;this._startedMove=t.timeStamp;c(t,"mouseover");c(t,"mousemove");c(t,"mousedown")};e._touchMove=function(t){if(!u){return}this._touchMoved=true;c(t,"mousemove")};e._touchEnd=function(t){if(!u){return}c(t,"mouseup");c(t,"mouseout");var e=t.timeStamp-this._startedMove;if(!this._touchMoved||e<500){c(t,"click")}else{var o=i(t);if(Math.abs(o.x-this._startPos.x)<10&&Math.abs(o.y-this._startPos.y)<10){if(!this._touchMoved||t.originalEvent.changedTouches[0].touchType==="stylus"){c(t,"click")}}}u=false};e._mouseInit=function(){var e=this;e.element.on({touchstart:t.proxy(e,"_touchStart"),touchmove:t.proxy(e,"_touchMove"),touchend:t.proxy(e,"_touchEnd")});o.call(e)};e._mouseDestroy=function(){var e=this;e.element.off({touchstart:t.proxy(e,"_touchStart"),touchmove:t.proxy(e,"_touchMove"),touchend:t.proxy(e,"_touchEnd")});n.call(e)}})); |