Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6b8aed

Browse files
Fix #5
Fix IE Mobile problem with undefined clientX/Y
1 parent ca53251 commit c6b8aed

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

jquery.tap.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848

4949
if (IS_TOUCH_DEVICE) {
5050

51-
//iOS, Android
51+
// iOS, Android
5252
HAS_TOUCH_EVENTS = 'ontouchstart' in document.documentElement;
53-
//IE 11
53+
// IE 11
5454
HAS_POINTER_EVENTS = window.navigator.pointerEnabled;
55-
//IE 10
55+
// IE 10
5656
HAS_MS_POINTER_EVENTS = window.navigator.msPointerEnabled;
57-
//has any "touch" events
57+
// has any "touch" events
5858
HAS_TOUCH = HAS_TOUCH_EVENTS || HAS_POINTER_EVENTS || HAS_MS_POINTER_EVENTS;
5959

6060
if (HAS_POINTER_EVENTS) {
@@ -75,22 +75,25 @@
7575
}
7676

7777
} else {
78-
//fallback to click
78+
// fallback to click
7979
END_EVENT_NAME = CLICK_EVENT_NAME;
8080
}
8181

82-
//Cache jQuery body object
82+
// Cache jQuery body object
8383
$BODY = jQuery(document.body);
8484

8585
if (HAS_TOUCH) {
8686
$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+
8793
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)];
9497
wasMoved = (
9598
Math.abs(msMoveCoords[0] - msStartCoords[0]) > MS_TOUCH_DELTA &&
9699
Math.abs(msMoveCoords[1] - msStartCoords[1]) > MS_TOUCH_DELTA
@@ -99,11 +102,14 @@
99102
wasMoved = true;
100103
}
101104
}).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+
102111
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)];
107113
}
108114
wasMoved = false;
109115
});
@@ -126,11 +132,11 @@
126132

127133
if (!wasMoved) {
128134

129-
//set event type as event name
135+
// set event type as event name
130136
event.type = JQUERY_SPECIAL_EVENT_NAME;
131-
//call handler
137+
// call handler
132138
result = handleObj.handler.call(this, event);
133-
//set back origin event type
139+
// set back origin event type
134140
event.type = type;
135141

136142
targetNode = event.target;
@@ -150,7 +156,7 @@
150156

151157
}
152158

153-
//prevent memory leaks
159+
// prevent memory leaks
154160
data = handleObj = null;
155161

156162
return result;

0 commit comments

Comments
 (0)