1 /*!2 * jQuery UI Touch Punch 0.2.23 *4 * Copyright 2011, Dave Furfero5 * Dual licensed under the MIT or GPL Version 2 licenses.6 *7 * Depends:8 * jquery.ui.widget.js9 * jquery.ui.mouse.js10 */11 (function ($) {1213 // Detect touch support14 $.support.touch = 'ontouchend' in document;1516 // Ignore browsers without touch support17 if (!$.support.touch) {18 return;19 }2021 var mouseProto = $.ui.mouse.prototype,22 _mouseInit = mouseProto._mouseInit,23 touchHandled;2425 /**26 * Simulate a mouse event based on a corresponding touch event27 * @param {Object} event A touch event28 * @param {String} simulatedType The corresponding mouse event29 */30 function simulateMouseEvent (event, simulatedType) {3132 // Ignore multi-touch events33 if (event.originalEvent.touches.length > 1) {34 return;35 }3637 event.preventDefault();3839 var touch = event.originalEvent.changedTouches[0],40 simulatedEvent = document.createEvent('MouseEvents');4142 // Initialize the simulated mouse event using the touch event's coordinates43 simulatedEvent.initMouseEvent(44 simulatedType, // type45 true, // bubbles46 true, // cancelable47 window, // view48 1, // detail49 touch.screenX, // screenX50 touch.screenY, // screenY51 touch.clientX, // clientX52 touch.clientY, // clientY53 false, // ctrlKey54 false, // altKey55 false, // shiftKey56 false, // metaKey57 0, // button58 null // relatedTarget59 );6061 // Dispatch the simulated event to the target element62 event.target.dispatchEvent(simulatedEvent);63 }6465 /**66 * Handle the jQuery UI widget's touchstart events67 * @param {Object} event The widget element's touchstart event68 */69 mouseProto._touchStart = function (event) {7071 var self = this;7273 // Ignore the event if another widget is already being handled74 if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {75 return;76 }7778 // Set the flag to prevent other widgets from inheriting the touch event79 touchHandled = true;8081 // Track movement to determine if interaction was a click82 self._touchMoved = false;8384 // Simulate the mouseover event85 simulateMouseEvent(event, 'mouseover');8687 // Simulate the mousemove event88 simulateMouseEvent(event, 'mousemove');8990 // Simulate the mousedown event91 simulateMouseEvent(event, 'mousedown');92 };9394 /**95 * Handle the jQuery UI widget's touchmove events96 * @param {Object} event The document's touchmove event97 */98 mouseProto._touchMove = function (event) {99100 // Ignore event if not handled101 if (!touchHandled) {102 return;103 }104105 // Interaction was not a click106 this._touchMoved = true;107108 // Simulate the mousemove event109 simulateMouseEvent(event, 'mousemove');110 };111112 /**113 * Handle the jQuery UI widget's touchend events114 * @param {Object} event The document's touchend event115 */116 mouseProto._touchEnd = function (event) {117118 // Ignore event if not handled119 if (!touchHandled) {120 return;121 }122123 // Simulate the mouseup event124 simulateMouseEvent(event, 'mouseup');125126 // Simulate the mouseout event127 simulateMouseEvent(event, 'mouseout');128129 // If the touch interaction did not move, it should trigger a click130 if (!this._touchMoved) {131132 // Simulate the click event133 simulateMouseEvent(event, 'click');134 }135136 // Unset the flag to allow other widgets to inherit the touch event137 touchHandled = false;138 };139140 /**141 * A duck punch of the $.ui.mouse _mouseInit method to support touch events.142 * This method extends the widget with bound touch event handlers that143 * translate touch events to mouse events and pass them to the widget's144 * original mouse event handling methods.145 */146 mouseProto._mouseInit = function () {147148 var self = this;149150 // Delegate the touch handlers to the widget's element151 self.element152 .bind('touchstart', $.proxy(self, '_touchStart'))153 .bind('touchmove', $.proxy(self, '_touchMove'))154 .bind('touchend', $.proxy(self, '_touchEnd'));155156 // Call the original $.ui.mouse init method157 _mouseInit.call(self);158 };159160 })(jQuery);1 /*! 2 * jQuery UI Touch Punch 0.2.2 3 * 4 * Copyright 2011, Dave Furfero 5 * Dual licensed under the MIT or GPL Version 2 licenses. 6 * 7 * Depends: 8 * jquery.ui.widget.js 9 * jquery.ui.mouse.js 10 */ 11 (function ($) { 12 13 // Detect touch support 14 $.support.touch = 'ontouchend' in document; 15 16 // Ignore browsers without touch support 17 if (!$.support.touch) { 18 return; 19 } 20 21 var mouseProto = $.ui.mouse.prototype, 22 _mouseInit = mouseProto._mouseInit, 23 touchHandled; 24 25 /** 26 * Simulate a mouse event based on a corresponding touch event 27 * @param {Object} event A touch event 28 * @param {String} simulatedType The corresponding mouse event 29 */ 30 function simulateMouseEvent (event, simulatedType) { 31 32 // Ignore multi-touch events 33 if (event.originalEvent.touches.length > 1) { 34 return; 35 } 36 37 event.preventDefault(); 38 39 var touch = event.originalEvent.changedTouches[0], 40 simulatedEvent = document.createEvent('MouseEvents'); 41 42 // Initialize the simulated mouse event using the touch event's coordinates 43 simulatedEvent.initMouseEvent( 44 simulatedType, // type 45 true, // bubbles 46 true, // cancelable 47 window, // view 48 1, // detail 49 touch.screenX, // screenX 50 touch.screenY, // screenY 51 touch.clientX, // clientX 52 touch.clientY, // clientY 53 false, // ctrlKey 54 false, // altKey 55 false, // shiftKey 56 false, // metaKey 57 0, // button 58 null // relatedTarget 59 ); 60 61 // Dispatch the simulated event to the target element 62 event.target.dispatchEvent(simulatedEvent); 63 } 64 65 /** 66 * Handle the jQuery UI widget's touchstart events 67 * @param {Object} event The widget element's touchstart event 68 */ 69 mouseProto._touchStart = function (event) { 70 71 var self = this; 72 73 // Ignore the event if another widget is already being handled 74 if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { 75 return; 76 } 77 78 // Set the flag to prevent other widgets from inheriting the touch event 79 touchHandled = true; 80 81 // Track movement to determine if interaction was a click 82 self._touchMoved = false; 83 84 // Simulate the mouseover event 85 simulateMouseEvent(event, 'mouseover'); 86 87 // Simulate the mousemove event 88 simulateMouseEvent(event, 'mousemove'); 89 90 // Simulate the mousedown event 91 simulateMouseEvent(event, 'mousedown'); 92 }; 93 94 /** 95 * Handle the jQuery UI widget's touchmove events 96 * @param {Object} event The document's touchmove event 97 */ 98 mouseProto._touchMove = function (event) { 99 100 // Ignore event if not handled 101 if (!touchHandled) { 102 return; 103 } 104 105 // Interaction was not a click 106 this._touchMoved = true; 107 108 // Simulate the mousemove event 109 simulateMouseEvent(event, 'mousemove'); 110 }; 111 112 /** 113 * Handle the jQuery UI widget's touchend events 114 * @param {Object} event The document's touchend event 115 */ 116 mouseProto._touchEnd = function (event) { 117 118 // Ignore event if not handled 119 if (!touchHandled) { 120 return; 121 } 122 123 // Simulate the mouseup event 124 simulateMouseEvent(event, 'mouseup'); 125 126 // Simulate the mouseout event 127 simulateMouseEvent(event, 'mouseout'); 128 129 // If the touch interaction did not move, it should trigger a click 130 if (!this._touchMoved) { 131 132 // Simulate the click event 133 simulateMouseEvent(event, 'click'); 134 } 135 136 // Unset the flag to allow other widgets to inherit the touch event 137 touchHandled = false; 138 }; 139 140 /** 141 * A duck punch of the $.ui.mouse _mouseInit method to support touch events. 142 * This method extends the widget with bound touch event handlers that 143 * translate touch events to mouse events and pass them to the widget's 144 * original mouse event handling methods. 145 */ 146 mouseProto._mouseInit = function () { 147 148 var self = this; 149 150 // Delegate the touch handlers to the widget's element 151 self.element 152 .bind('touchstart', $.proxy(self, '_touchStart')) 153 .bind('touchmove', $.proxy(self, '_touchMove')) 154 .bind('touchend', $.proxy(self, '_touchEnd')); 155 156 // Call the original $.ui.mouse init method 157 _mouseInit.call(self); 158 }; 159 160 })(jQuery);1 /*! 2 * jQuery UI Touch Punch 0.2.2 3 * 4 * Copyright 2011, Dave Furfero 5 * Dual licensed under the MIT or GPL Version 2 licenses. 6 * 7 * Depends: 8 * jquery.ui.widget.js 9 * jquery.ui.mouse.js 10 */ 11 (function ($) { 12 13 // Detect touch support 14 $.support.touch = 'ontouchend' in document; 15 16 // Ignore browsers without touch support 17 if (!$.support.touch) { 18 return; 19 } 20 21 var mouseProto = $.ui.mouse.prototype, 22 _mouseInit = mouseProto._mouseInit, 23 touchHandled; 24 25 /** 26 * Simulate a mouse event based on a corresponding touch event 27 * @param {Object} event A touch event 28 * @param {String} simulatedType The corresponding mouse event 29 */ 30 function simulateMouseEvent (event, simulatedType) { 31 32 // Ignore multi-touch events 33 if (event.originalEvent.touches.length > 1) { 34 return; 35 } 36 37 event.preventDefault(); 38 39 var touch = event.originalEvent.changedTouches[0], 40 simulatedEvent = document.createEvent('MouseEvents'); 41 42 // Initialize the simulated mouse event using the touch event's coordinates 43 simulatedEvent.initMouseEvent( 44 simulatedType, // type 45 true, // bubbles 46 true, // cancelable 47 window, // view 48 1, // detail 49 touch.screenX, // screenX 50 touch.screenY, // screenY 51 touch.clientX, // clientX 52 touch.clientY, // clientY 53 false, // ctrlKey 54 false, // altKey 55 false, // shiftKey 56 false, // metaKey 57 0, // button 58 null // relatedTarget 59 ); 60 61 // Dispatch the simulated event to the target element 62 event.target.dispatchEvent(simulatedEvent); 63 } 64 65 /** 66 * Handle the jQuery UI widget's touchstart events 67 * @param {Object} event The widget element's touchstart event 68 */ 69 mouseProto._touchStart = function (event) { 70 71 var self = this; 72 73 // Ignore the event if another widget is already being handled 74 if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { 75 return; 76 } 77 78 // Set the flag to prevent other widgets from inheriting the touch event 79 touchHandled = true; 80 81 // Track movement to determine if interaction was a click 82 self._touchMoved = false; 83 84 // Simulate the mouseover event 85 simulateMouseEvent(event, 'mouseover'); 86 87 // Simulate the mousemove event 88 simulateMouseEvent(event, 'mousemove'); 89 90 // Simulate the mousedown event 91 simulateMouseEvent(event, 'mousedown'); 92 }; 93 94 /** 95 * Handle the jQuery UI widget's touchmove events 96 * @param {Object} event The document's touchmove event 97 */ 98 mouseProto._touchMove = function (event) { 99 100 // Ignore event if not handled 101 if (!touchHandled) { 102 return; 103 } 104 105 // Interaction was not a click 106 this._touchMoved = true; 107 108 // Simulate the mousemove event 109 simulateMouseEvent(event, 'mousemove'); 110 }; 111 112 /** 113 * Handle the jQuery UI widget's touchend events 114 * @param {Object} event The document's touchend event 115 */ 116 mouseProto._touchEnd = function (event) { 117 118 // Ignore event if not handled 119 if (!touchHandled) { 120 return; 121 } 122 123 // Simulate the mouseup event 124 simulateMouseEvent(event, 'mouseup'); 125 126 // Simulate the mouseout event 127 simulateMouseEvent(event, 'mouseout'); 128 129 // If the touch interaction did not move, it should trigger a click 130 if (!this._touchMoved) { 131 132 // Simulate the click event 133 simulateMouseEvent(event, 'click'); 134 } 135 136 // Unset the flag to allow other widgets to inherit the touch event 137 touchHandled = false; 138 }; 139 140 /** 141 * A duck punch of the $.ui.mouse _mouseInit method to support touch events. 142 * This method extends the widget with bound touch event handlers that 143 * translate touch events to mouse events and pass them to the widget's 144 * original mouse event handling methods. 145 */ 146 mouseProto._mouseInit = function () { 147 148 var self = this; 149 150 // Delegate the touch handlers to the widget's element 151 self.element 152 .bind('touchstart', $.proxy(self, '_touchStart')) 153 .bind('touchmove', $.proxy(self, '_touchMove')) 154 .bind('touchend', $.proxy(self, '_touchEnd')); 155 156 // Call the original $.ui.mouse init method 157 _mouseInit.call(self); 158 }; 159 160 })(jQuery);
联系我们 |
---|
文章看不懂?联系我们为您免费解答!免费助力个人,小企站点! |
① 电话:020-2206-9892 |
② QQ咨询:1025174874 |
③ 邮件:info@361sale.com |
④ 工作时间:周一至周五,9:30-18:30,节假日休息 |
THE END
暂无评论内容