/*! * jQuery UI Touch Punch 0.2.3 * * Copyright 20112014, Dave Furfero * Dual licensed under the MIT or GPL Version 2 licenses. * * Depends: * jquery.ui.widget.js * jquery.ui.mouse.js */ $(document).ready(function() { (function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return}var d=b.ui.mouse.prototype,f=d._mouseInit,c=d._mouseDestroy,a;function e(h,i){if(h.originalEvent.touches.length>1){return}h.preventDefault();var j=h.originalEvent.changedTouches[0],g=document.createEvent("MouseEvents");g.initMouseEvent(i,true,true,window,1,j.screenX,j.screenY,j.clientX,j.clientY,false,false,false,false,0,null);h.target.dispatchEvent(g)}d._touchStart=function(h){var g=this;if(a||!g._mouseCapture(h.originalEvent.changedTouches[0])){return}a=true;g._touchMoved=false;this._startedMove=h.timeStamp;e(h,"mouseover");e(h,"mousemove");e(h,"mousedown")};d._touchMove=function(g){if(!a){return}this._touchMoved=true;e(g,"mousemove")};d._touchEnd=function(h){if(!a){return}e(h,"mouseup");e(h,"mouseout");var g=h.timeStamp-this._startedMove;if(!this._touchMoved||g<500){e(h,"click")}a=false};d._mouseInit=function(){var g=this;g.element.bind({touchstart:b.proxy(g,"_touchStart"),touchmove:b.proxy(g,"_touchMove"),touchend:b.proxy(g,"_touchEnd")});f.call(g)};d._mouseDestroy=function(){var g=this;g.element.unbind({touchstart:b.proxy(g,"_touchStart"),touchmove:b.proxy(g,"_touchMove"),touchend:b.proxy(g,"_touchEnd")});c.call(g)}})(jQuery); }); /*! * jQuery UI Touch Punch 0.2.3 * * Copyright 20112014, Dave Furfero * Dual licensed under the MIT or GPL Version 2 licenses. * * Depends: * jquery.ui.widget.js * jquery.ui.mouse.js */ (function ($) { // Detect touch support $.support.touch = "ontouchend" in document; // Ignore browsers without touch support if (!$.support.touch) { return; } var mouseProto = $.ui.mouse.prototype, _mouseInit = mouseProto._mouseInit, _mouseDestroy = mouseProto._mouseDestroy, touchHandled; /** * Simulate a mouse event based on a corresponding touch event * @param {Object} event A touch event * @param {String} simulatedType The corresponding mouse event */ function simulateMouseEvent (event, simulatedType) { // Ignore multi-touch events if (event.originalEvent.touches.length > 1) { return; } event.preventDefault(); var touch = event.originalEvent.changedTouches[0], simulatedEvent = document.createEvent("MouseEvents"); // Initialize the simulated mouse event using the touch event"s coordinates simulatedEvent.initMouseEvent( simulatedType, // type true, // bubbles true, // cancelable window, // view 1, // detail touch.screenX, // screenX touch.screenY, // screenY touch.clientX, // clientX touch.clientY, // clientY false, // ctrlKey false, // altKey false, // shiftKey false, // metaKey 0, // button null // relatedTarget ); // Dispatch the simulated event to the target element event.target.dispatchEvent(simulatedEvent); } /** * Handle the jQuery UI widget"s touchstart events * @param {Object} event The widget element"s touchstart event */ mouseProto._touchStart = function (event) { var self = this; // Ignore the event if another widget is already being handled if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { return; } // Set the flag to prevent other widgets from inheriting the touch event touchHandled = true; // Track movement to determine if interaction was a click self._touchMoved = false; // Interaction time this._startedMove = event.timeStamp; // Simulate the mouseover event simulateMouseEvent(event, "mouseover"); // Simulate the mousemove event simulateMouseEvent(event, "mousemove"); // Simulate the mousedown event simulateMouseEvent(event, "mousedown"); }; /** * Handle the jQuery UI widget"s touchmove events * @param {Object} event The document"s touchmove event */ mouseProto._touchMove = function (event) { // Ignore event if not handled if (!touchHandled) { return; } // Interaction was moved this._touchMoved = true; // Simulate the mousemove event simulateMouseEvent(event, "mousemove"); }; /** * Handle the jQuery UI widget"s touchend events * @param {Object} event The document"s touchend event */ mouseProto._touchEnd = function (event) { // Ignore event if not handled if (!touchHandled) { return; } // Simulate the mouseup event simulateMouseEvent(event, "mouseup"); // Simulate the mouseout event simulateMouseEvent(event, "mouseout"); // If the touch interaction did not move or was a fast click, it should trigger a click var timeMoving = event.timeStamp - this._startedMove; if (!this._touchMoved || timeMoving < 500) { // Simulate the click event simulateMouseEvent(event, "click"); } // Unset the flag to allow other widgets to inherit the touch event touchHandled = false; }; /** * A duck punch of the $.ui.mouse _mouseInit method to support touch events. * This method extends the widget with bound touch event handlers that * translate touch events to mouse events and pass them to the widget"s * original mouse event handling methods. */ mouseProto._mouseInit = function () { var self = this; // Delegate the touch handlers to the widget"s element self.element.bind({ touchstart: $.proxy(self, "_touchStart"), touchmove: $.proxy(self, "_touchMove"), touchend: $.proxy(self, "_touchEnd") }); // Call the original $.ui.mouse init method _mouseInit.call(self); }; /** * Remove the touch event handlers */ mouseProto._mouseDestroy = function () { var self = this; // Delegate the touch handlers to the widget"s element self.element.unbind({ touchstart: $.proxy(self, "_touchStart"), touchmove: $.proxy(self, "_touchMove"), touchend: $.proxy(self, "_touchEnd") }); // Call the original $.ui.mouse destroy method _mouseDestroy.call(self); }; })(jQuery);