/*!
 * jQuery UI Touch Punch 1.1.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(factory){if(typeof define==="function"&&define.amd){define(["jquery","jquery-ui"],factory)}else{factory(jQuery)}}(function($){$.mspointer=window.navigator.msPointerEnabled;$.touch=('ontouchstart' in document||'ontouchstart' in window||window.TouchEvent||(window.DocumentTouch&&document instanceof DocumentTouch)||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0);if((!$.touch&&!$.mspointer)||!$.ui.mouse){return}
let mouseProto=$.ui.mouse.prototype,_mouseInit=mouseProto._mouseInit,_mouseDestroy=mouseProto._mouseDestroy,touchHandled,lastClickTime=0;function getTouchCoords(event){return{x:event.originalEvent.changedTouches[0].pageX,y:event.originalEvent.changedTouches[0].pageY}}
function simulateMouseEvent(event,simulatedType){if(event.originalEvent.touches.length>1){return}
if($(event.target).is("input")||$(event.target).is("textarea")){return}
if(event.cancelable){event.preventDefault()}
let touch=event.originalEvent.changedTouches[0],simulatedEvent=new MouseEvent(simulatedType,{bubbles:!0,cancelable:!0,view:window,screenX:touch.screenX,screenY:touch.screenY,clientX:touch.clientX,clientY:touch.clientY});event.target.dispatchEvent(simulatedEvent)}
mouseProto._touchStart=function(event){let self=this;this._startedMove=event.timeStamp;self._startPos=getTouchCoords(event);if(touchHandled||!self._mouseCapture(event.originalEvent.changedTouches[0])){return}
touchHandled=!0;self._touchMoved=!1;simulateMouseEvent(event,'mouseover');simulateMouseEvent(event,'mousemove');simulateMouseEvent(event,'mousedown')};mouseProto._touchMove=function(event){if(!touchHandled){return}
this._touchMoved=!0;simulateMouseEvent(event,'mousemove')};mouseProto._touchEnd=function(event){if(!touchHandled){return}
simulateMouseEvent(event,'mouseup');simulateMouseEvent(event,'mouseout');let timeMoving=event.timeStamp-this._startedMove;if(!this._touchMoved||timeMoving<500){if(event.timeStamp-lastClickTime<400)
simulateMouseEvent(event,'dblclick');else simulateMouseEvent(event,'click');lastClickTime=event.timeStamp}else{let endPos=getTouchCoords(event);if((Math.abs(endPos.x-this._startPos.x)<10)&&(Math.abs(endPos.y-this._startPos.y)<10)){if(!this._touchMoved||event.originalEvent.changedTouches[0].touchType==='stylus'){simulateMouseEvent(event,'click')}}}
this._touchMoved=!1;touchHandled=!1};let _touchStartBound;let _touchMoveBound;let _touchEndBound
mouseProto._mouseInit=function(){let self=this;if($.support.mspointer){self.element[0].style.msTouchAction='none'}
_touchStartBound=mouseProto._touchStart.bind(self);_touchMoveBound=mouseProto._touchMove.bind(self);_touchEndBound=mouseProto._touchEnd.bind(self);self.element.on({touchstart:_touchStartBound,touchmove:_touchMoveBound,touchend:_touchEndBound});_mouseInit.call(self)};mouseProto._mouseDestroy=function(){let self=this;self.element.off({touchstart:_touchStartBound,touchmove:_touchMoveBound,touchend:_touchEndBound});_mouseDestroy.call(self)}}))