Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed coordinates across browsers.

  • Loading branch information...
commit 2aa8e94e2d544bdd92249506accc35e53aff5e93 1 parent 9fdddf8
@ngryman authored
Showing with 26 additions and 7 deletions.
  1. +9 −5 src/jquery.finger.js
  2. +17 −2 test/jquery.finger_test.js
View
14 src/jquery.finger.js
@@ -39,6 +39,10 @@
$.event[action](el, stopEvent, stopHandler, null, handleObj.selector);
}
+ function page(coord, e) {
+ return (hasTouch ? e.originalEvent.touches[0] : e)['page' + coord.toUpperCase()];
+ }
+
function fire(evtName, event, f) {
if (f[evtName] && !f[evtName].canceled) {
$.extend(event, f.move);
@@ -53,7 +57,7 @@
function startHandler(event) {
var f = finger(event.delegateTarget);
- f.move = { x: event.pageX, y: event.pageY };
+ f.move = { x: page('x', event), y: page('y', event) };
f.start = $.extend({ time: event.timeStamp }, f.move);
}
@@ -64,10 +68,10 @@
if (!f.start) return;
// motion data
- f.move.x = event.pageX;
- f.move.y = event.pageY;
- f.move.dx = event.pageX - f.start.x;
- f.move.dy = event.pageY - f.start.y;
+ f.move.x = page('x', event);
+ f.move.y = page('y', event);
+ f.move.dx = f.move.x - f.start.x;
+ f.move.dy = f.move.y - f.start.y;
f.move.adx = Math.abs(f.move.dx);
f.move.ady = Math.abs(f.move.dy);
View
19 test/jquery.finger_test.js
@@ -10,7 +10,16 @@
/** extend Mocha.Context to hence event trigger */
Mocha.Context.prototype.tapStart = function() {
- this.$elems.filter(':first').trigger(new $.Event(startEvent, { pageX: 0, pageY: 0 }));
+ this.$elems.filter(':first').trigger(new $.Event(startEvent, {
+ pageX: 0,
+ pageY: 0,
+ originalEvent: {
+ touches: [{
+ pageX: 0,
+ pageY: 0
+ }]
+ }
+ }));
};
Mocha.Context.prototype.tapEnd = function() {
@@ -35,7 +44,13 @@
self.$elems.filter(':first').trigger($.Event(moveEvent, {
pageX: Math.ceil(t / duration * x),
- pageY: Math.ceil(t / duration * y)
+ pageY: Math.ceil(t / duration * y),
+ originalEvent: {
+ touches: [{
+ pageX: Math.ceil(t / duration * x),
+ pageY: Math.ceil(t / duration * y)
+ }]
+ }
}));
timer = setTimeout(mv, 0);
})();
Please sign in to comment.
Something went wrong with that request. Please try again.