forked from furf/jquery-ui-touch-punch
-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.touch-punch.min.js
19 lines (17 loc) · 1.51 KB
/
jquery.touch-punch.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*!
* jQuery Touch Punch 0.1
*
* extended from jQuery UI Touch Punch 0.2.2 Copyright 2011, Dave Furfero
* Copyright 2013, Michael Angstadt
- modified eliminate the requirement of jQuery UI usage
- extended into jQuery plugin to be used on specific elements
- usage is for elements that you've defined mouse event handlers for
and want to extend touch interface events to simulate these events properly
on touch interface devices
- ex. $('.draggableObject').touchDraggable();
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.js
*/
(function(e){e.fn.touchDraggable=function(){function t(e,t){if(e.touches.length>1){return}e.preventDefault();var n=e.changedTouches[0],r=document.createEvent("MouseEvents");r.initMouseEvent(t,true,true,window,1,n.screenX,n.screenY,n.clientX,n.clientY,false,false,false,false,0,null);e.target.dispatchEvent(r)}e.support.touch="ontouchend"in document;if(!e.support.touch){return}this._touchHandled=false;this._touchMoved=false;var n=this;for(var r=0;r<n.length;r++){n[r].addEventListener("touchstart",function(e){var n=this;if(n._touchHandled){return}n._touchHandled=true;n._touchMoved=false;t(e,"mouseover");t(e,"mousemove");t(e,"mousedown")});n[r].addEventListener("touchmove",function(e){if(!this._touchHandled){return}this._touchMoved=true;t(e,"mousemove")});n[r].addEventListener("touchend",function(e){if(!this._touchHandled){return}t(e,"mouseup");t(e,"mouseout");if(!this._touchMoved){t(e,"click")}this._touchHandled=false})}}})(jQuery)