vendor: 5,271 bytes, lines 1-181
1 2/*! 3 * jQuery UI Touch Punch 0.2.3 4 * 5 * Copyright 2011â2014, Dave Furfero 6 * Dual licensed under the MIT or GPL Version 2 licenses. 7 * 8 * Depends: 9 * jquery.ui.widget.js 10 * jquery.ui.mouse.js 11 */ 12(function ($) { 13 14 // Detect touch support 15 $.support.touch = 'ontouchend' in document; 16 17 // Ignore browsers without touch support 18 if (!$.support.touch) { 19 return; 20 } 21 22 var mouseProto = $.ui.mouse.prototype, 23 _mouseInit = mouseProto._mouseInit, 24 _mouseDestroy = mouseProto._mouseDestroy, 25 touchHandled; 26 27 /** 28 * Simulate a mouse event based on a corresponding touch event 29 * @param {Object} event A touch event 30 * @param {String} simulatedType The corresponding mouse event 31 */ 32 function simulateMouseEvent (event, simulatedType) { 33 34 // Ignore multi-touch events 35 if (event.originalEvent.touches.length > 1) { 36 return; 37 } 38 39 event.preventDefault(); 40 41 var touch = event.originalEvent.changedTouches[0], 42 simulatedEvent = document.createEvent('MouseEvents'); 43 44 // Initialize the simulated mouse event using the touch event's coordinates 45 simulatedEvent.initMouseEvent( 46 simulatedType, // type 47 true, // bubbles 48 true, // cancelable 49 window, // view 50 1, // detail 51 touch.screenX, // screenX 52 touch.screenY, // screenY 53 touch.clientX, // clientX 54 touch.clientY, // clientY 55 false, // ctrlKey 56 false, // altKey 57 false, // shiftKey 58 false, // metaKey 59 0, // button 60 null // relatedTarget 61 ); 62 63 // Dispatch the simulated event to the target element 64 event.target.dispatchEvent(simulatedEvent); 65 } 66 67 /** 68 * Handle the jQuery UI widget's touchstart events 69 * @param {Object} event The widget element's touchstart event 70 */ 71 mouseProto._touchStart = function (event) { 72 73 var self = this; 74 75 // Ignore the event if another widget is already being handled 76 if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { 77 return; 78 } 79 80 // Set the flag to prevent other widgets from inheriting the touch event 81 touchHandled = true; 82 83 // Track movement to determine if interaction was a click 84 self._touchMoved = false; 85 86 // Simulate the mouseover event 87 simulateMouseEvent(event, 'mouseover'); 88 89 // Simulate the mousemove event 90 simulateMouseEvent(event, 'mousemove'); 91 92 // Simulate the mousedown event 93 simulateMouseEvent(event, 'mousedown'); 94 }; 95 96 /** 97 * Handle the jQuery UI widget's touchmove events 98 * @param {Object} event The document's touchmove event 99 */ 100 mouseProto._touchMove = function (event) { 101 102 // Ignore event if not handled 103 if (!touchHandled) { 104 return; 105 } 106 107 // Interaction was not a click 108 this._touchMoved = true; 109 110 // Simulate the mousemove event 111 simulateMouseEvent(event, 'mousemove'); 112 }; 113 114 /** 115 * Handle the jQuery UI widget's touchend events 116 * @param {Object} event The document's touchend event 117 */ 118 mouseProto._touchEnd = function (event) { 119 120 // Ignore event if not handled 121 if (!touchHandled) { 122 return; 123 } 124 125 // Simulate the mouseup event 126 simulateMouseEvent(event, 'mouseup'); 127 128 // Simulate the mouseout event 129 simulateMouseEvent(event, 'mouseout'); 130 131 // If the touch interaction did not move, it should trigger a click 132 if (!this._touchMoved) { 133 134 // Simulate the click event 135 simulateMouseEvent(event, 'click'); 136 } 137 138 // Unset the flag to allow other widgets to inherit the touch event 139 touchHandled = false; 140 }; 141 142 /** 143 * A duck punch of the $.ui.mouse _mouseInit method to support touch events. 144 * This method extends the widget with bound touch event handlers that 145 * translate touch events to mouse events and pass them to the widget's 146 * original mouse event handling methods. 147 */ 148 mouseProto._mouseInit = function () { 149 150 var self = this; 151 152 // Delegate the touch handlers to the widget's element 153 self.element.bind({ 154 touchstart: $.proxy(self, '_touchStart'), 155 touchmove: $.proxy(self, '_touchMove'), 156 touchend: $.proxy(self, '_touchEnd') 157 }); 158 159 // Call the original $.ui.mouse init method 160 _mouseInit.call(self); 161 }; 162 163 /** 164 * Remove the touch event handlers 165 */ 166 mouseProto._mouseDestroy = function () { 167 168 var self = this; 169 170 // Delegate the touch handlers to the widget's element 171 self.element.unbind({ 172 touchstart: $.proxy(self, '_touchStart'), 173 touchmove: $.proxy(self, '_touchMove'), 174 touchend: $.proxy(self, '_touchEnd') 175 }); 176 177 // Call the original $.ui.mouse destroy method 178 _mouseDestroy.call(self); 179 }; 180 181})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.