|
48 | 48 |
|
49 | 49 | if (IS_TOUCH_DEVICE) {
|
50 | 50 |
|
51 |
| - //iOS, Android |
| 51 | + // iOS, Android |
52 | 52 | HAS_TOUCH_EVENTS = 'ontouchstart' in document.documentElement;
|
53 |
| - //IE 11 |
| 53 | + // IE 11 |
54 | 54 | HAS_POINTER_EVENTS = window.navigator.pointerEnabled;
|
55 |
| - //IE 10 |
| 55 | + // IE 10 |
56 | 56 | HAS_MS_POINTER_EVENTS = window.navigator.msPointerEnabled;
|
57 |
| - //has any "touch" events |
| 57 | + // has any "touch" events |
58 | 58 | HAS_TOUCH = HAS_TOUCH_EVENTS || HAS_POINTER_EVENTS || HAS_MS_POINTER_EVENTS;
|
59 | 59 |
|
60 | 60 | if (HAS_POINTER_EVENTS) {
|
|
75 | 75 | }
|
76 | 76 |
|
77 | 77 | } else {
|
78 |
| - //fallback to click |
| 78 | + // fallback to click |
79 | 79 | END_EVENT_NAME = CLICK_EVENT_NAME;
|
80 | 80 | }
|
81 | 81 |
|
82 |
| - //Cache jQuery body object |
| 82 | + // Cache jQuery body object |
83 | 83 | $BODY = jQuery(document.body);
|
84 | 84 |
|
85 | 85 | if (HAS_TOUCH) {
|
86 | 86 | $BODY.on(MOVE_EVENT_NAME, function (e) {
|
| 87 | + var origEvent = e.originalEvent, |
| 88 | + // https://connect.microsoft.com/IE/feedback/details/810635/ie-11-clientx-and-clienty-not-working |
| 89 | + // We just want to know is page position changed |
| 90 | + x = origEvent.clientX || document.body.scrollLeft + document.documentElement.scrollLeft, |
| 91 | + y = origEvent.clientY || document.body.scrollTop + document.documentElement.scrollTop; |
| 92 | + |
87 | 93 | if (msStartCoords) {
|
88 |
| - //Pointer move event can fire without coords changing |
89 |
| - //http://www.w3.org/TR/2014/WD-pointerevents-20141113/#the-pointermove-event |
90 |
| - msMoveCoords = [ |
91 |
| - e.originalEvent.clientX.toFixed(0), |
92 |
| - e.originalEvent.clientY.toFixed(0) |
93 |
| - ]; |
| 94 | + // Pointer move event can fire without coords changing |
| 95 | + // http://www.w3.org/TR/2014/WD-pointerevents-20141113/#the-pointermove-event |
| 96 | + msMoveCoords = [x.toFixed(0), y.toFixed(0)]; |
94 | 97 | wasMoved = (
|
95 | 98 | Math.abs(msMoveCoords[0] - msStartCoords[0]) > MS_TOUCH_DELTA &&
|
96 | 99 | Math.abs(msMoveCoords[1] - msStartCoords[1]) > MS_TOUCH_DELTA
|
|
99 | 102 | wasMoved = true;
|
100 | 103 | }
|
101 | 104 | }).on(START_EVENT_NAME, function (e) {
|
| 105 | + var origEvent = e.originalEvent, |
| 106 | + // https://connect.microsoft.com/IE/feedback/details/810635/ie-11-clientx-and-clienty-not-working |
| 107 | + // We just want to know is page position changed |
| 108 | + x = origEvent.clientX || document.body.scrollLeft + document.documentElement.scrollLeft, |
| 109 | + y = origEvent.clientY || document.body.scrollTop + document.documentElement.scrollTop; |
| 110 | + |
102 | 111 | if (HAS_POINTER_EVENTS || HAS_MS_POINTER_EVENTS) {
|
103 |
| - msStartCoords = [ |
104 |
| - e.originalEvent.clientX.toFixed(0), |
105 |
| - e.originalEvent.clientY.toFixed(0) |
106 |
| - ]; |
| 112 | + msMoveCoords = [x.toFixed(0), y.toFixed(0)]; |
107 | 113 | }
|
108 | 114 | wasMoved = false;
|
109 | 115 | });
|
|
126 | 132 |
|
127 | 133 | if (!wasMoved) {
|
128 | 134 |
|
129 |
| - //set event type as event name |
| 135 | + // set event type as event name |
130 | 136 | event.type = JQUERY_SPECIAL_EVENT_NAME;
|
131 |
| - //call handler |
| 137 | + // call handler |
132 | 138 | result = handleObj.handler.call(this, event);
|
133 |
| - //set back origin event type |
| 139 | + // set back origin event type |
134 | 140 | event.type = type;
|
135 | 141 |
|
136 | 142 | targetNode = event.target;
|
|
150 | 156 |
|
151 | 157 | }
|
152 | 158 |
|
153 |
| - //prevent memory leaks |
| 159 | + // prevent memory leaks |
154 | 160 | data = handleObj = null;
|
155 | 161 |
|
156 | 162 | return result;
|
|
0 commit comments