| 1 |
/* |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
* jQuery Double Tap |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
* Developer: Sergey Margaritov (sergey@margaritov.net) |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
* Date: 22.10.2013 |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
* Based on jquery documentation http://learn.jquery.com/events/event-extensions/ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
(function($){ |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
$.event.special.doubletap = { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
bindType: 'touchend', |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
delegateType: 'touchend', |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
handle: function(event) { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
var handleObj = event.handleObj, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
targetData = jQuery.data(event.target), |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
now = new Date().getTime(), |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
delta = targetData.lastTouch ? now - targetData.lastTouch : 0, |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
delay = delay == null ? 300 : delay; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
if (delta < delay && delta > 30) { |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
targetData.lastTouch = null; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
event.type = handleObj.origType; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
['clientX', 'clientY', 'pageX', 'pageY'].forEach(function(property) { |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
event[property] = event.originalEvent.changedTouches[0][property]; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
}) |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
// let jQuery handle the triggering of "doubletap" event handlers |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
handleObj.handler.apply(this, arguments); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
} else { |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
targetData.lastTouch = now; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
})(jQuery); |