Permalink
Browse files

bump version to 0.0.8.

  • Loading branch information...
1 parent 82cf1f0 commit 8302e802bc169d7d154239b268b34c57308f40b6 @ngryman committed Mar 16, 2013
Showing with 71 additions and 109 deletions.
  1. +6 −1 README.md
  2. +61 −104 dist/jquery.finger.js
  3. +2 −2 dist/jquery.finger.min.js
  4. +1 −1 finger.jquery.json
  5. +1 −1 package.json
View
@@ -1,4 +1,4 @@
-# jQuery Finger
+# jQuery Finger <sup>0.0.8</sup>
jQuery tap & gestures, fingers in the nose.
@@ -53,6 +53,11 @@ When running tests in the browser, your mouse / finger must not interact with th
## Release History
+### v0.0.8
+ - fixed bugs on delegated events.
+ - better cross-browser support (still needs some work/tests).
+ - internal refactoring for consistency and performance.
+
### v0.0.7
- various cross browsers fixes.
View
@@ -1,4 +1,4 @@
-/*! jquery.finger - v0.0.7 - 2013-03-12
+/*! jquery.finger - v0.0.8 - 2013-03-15
* https://github.com/ngryman/jquery.finger
* Copyright (c) 2013 Nicolas Gryman; Licensed MIT */
@@ -16,150 +16,107 @@
motionThreshold: 5
};
- function finger(el) {
- return $._data(el, 'events').finger;
- }
-
- function flag(evt, p, value) {
- if (3 == arguments.length) {
- evt && (evt[p] = value);
- }
- else {
- return evt ? evt[p] : undefined;
- }
- }
-
- function $event(action, el, handleObj) {
- $.event[action](el, startEvent, startHandler, null, handleObj.selector);
- $.event[action](el, moveEvent, moveHandler, null, handleObj.selector);
- $.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);
- var handlers = f[evtName].handlers;
- for (var handler in handlers) {
- if ($.isFunction(handlers[handler])) {
- handlers[handler].call(event.currentTarget, event);
- }
- }
- }
- }
-
function startHandler(event) {
- var f = finger(event.delegateTarget);
- f.move = { x: page('x', event), y: page('y', event) };
- f.start = $.extend({ time: event.timeStamp }, f.move);
+ var data = {};
+ data.move = { x: page('x', event), y: page('y', event) };
+ data.start = $.extend({ time: event.timeStamp, target: event.target }, data.move);
+
+ $.event.add(this, moveEvent + '.finger', moveHandler, data);
+ $.event.add(this, stopEvent + '.finger', stopHandler, data);
}
function moveHandler(event) {
- var f = finger(event.delegateTarget);
-
- // no start event fired, do nothing
- if (!f.start) return;
+ var data = event.data;
// motion data
- 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);
+ data.move.x = page('x', event);
+ data.move.y = page('y', event);
+ data.move.dx = data.move.x - data.start.x;
+ data.move.dy = data.move.y - data.start.y;
+ data.move.adx = Math.abs(data.move.dx);
+ data.move.ady = Math.abs(data.move.dy);
// security
- if (f.move.adx < $.Finger.motionThreshold && f.move.ady < $.Finger.motionThreshold) return;
+ data.motion = data.move.adx > $.Finger.motionThreshold || data.move.ady > $.Finger.motionThreshold;
+ if (!data.motion) return;
// orientation
- if (!f.move.orientation) {
- if (f.move.adx > f.move.ady) {
- f.move.orientation = 'horizontal';
- f.move.direction = f.move.dx > 0 ? +1 : -1;
+ if (!data.move.orientation) {
+ if (data.move.adx > data.move.ady) {
+ data.move.orientation = 'horizontal';
+ data.move.direction = data.move.dx > 0 ? +1 : -1;
}
else {
- f.move.orientation = 'vertical';
- f.move.direction = f.move.dy > 0 ? +1 : -1;
+ data.move.orientation = 'vertical';
+ data.move.direction = data.move.dy > 0 ? +1 : -1;
}
}
- // fire drag event
- fire('drag', event, f);
+ // for delegated events, the target may change over time
+ // this ensures we notify the right target and simulates the mouseleave behavior
+ if (event.target !== data.start.target) {
+ event.target = data.start.target;
+ stopHandler.call(this, $.Event(stopEvent + '.finger', event));
+ return;
+ }
- flag(f.tap, 'canceled', true);
- flag(f.press, 'canceled', true);
+ // fire drag event
+ $.event.trigger($.Event('drag' + $.expando, data.move), null, event.target);
}
function stopHandler(event) {
- var f = finger(event.delegateTarget),
+ var data = event.data,
now = event.timeStamp,
+ f = $.data(this, 'finger'),
evtName;
- // no start event fired, do nothing
- if (!f.start) return;
+ // ensures start target and end target are the same
+ if (event.target !== data.start.target) return;
// tap-like events
- evtName = now - f.start.time < $.Finger.pressDuration ? 'tap' : 'press';
- // is it a double tap ?
- if ('tap' == evtName && f.doubletap) {
- if (now - f.doubletap.prev < $.Finger.doubleTapInterval) {
- evtName = 'doubletap';
- }
- else {
- f.doubletap.prev = now;
- }
+ if (!data.motion) {
+ evtName = now - data.start.time < $.Finger.pressDuration ?
+ !f.prev || f.prev && now - f.prev > $.Finger.doubleTapInterval ? 'tap' : 'doubletap' :
+ 'press';
+ f.prev = now;
+ $.event.trigger($.Event(evtName + $.expando, data.move), null, event.target);
}
- fire(evtName, event, f);
-
// motion events
- evtName = now - f.start.time < $.Finger.flickDuration ? 'flick' : 'drag';
- fire(evtName, event, f);
+ else {
+ evtName = now - data.start.time < $.Finger.flickDuration ? 'flick' : 'drag';
+ data.move.end = true;
+ $.event.trigger($.Event(evtName + $.expando, data.move), null, event.target);
+ }
- // start over
- f.start = null;
- flag(f.tap, 'canceled', false);
- flag(f.press, 'canceled', false);
+ $.event.remove(this, moveEvent + '.finger', moveHandler);
+ $.event.remove(this, stopEvent + '.finger', stopHandler);
}
var fingerCustom = {
- add: function(handleObj) {
- var events = $._data(this, 'events');
- events.finger = events.finger || {};
- var f = events.finger;
-
- // creates under the hood events?
- if (!f.refCount) {
- $event('add', this, handleObj);
- f.refCount = 0; // ensures this is an number
+ setup: function() {
+ if (!$.data(this, 'finger')) {
+ $.event.add(this, startEvent + '.finger', startHandler);
+ $.data(this, 'finger', {});
}
+ },
- // increments ref count
- f.refCount++;
-
- // handler
- f[handleObj.type] = f[handleObj.type] || { handlers: [] };
- f[handleObj.type].handlers[handleObj.handler.guid] = handleObj.handler;
+ add: function(handleObj) {
+ $.event.add(this, handleObj.type + $.expando, handleObj.handler, null, handleObj.selector);
},
remove: function(handleObj) {
- var events = $._data(this, 'events');
- var f = events.finger;
-
- // decrements ref count
- f.refCount--;
+ $.event.add(this, handleObj.type + $.expando, handleObj.handler, null, handleObj.selector);
+ },
- // cleanup?
- if (0 === f.refCount) {
- $event('remove', this, handleObj);
- events.finger = null;
- return;
+ teardown: function() {
+ if ($.data(this, 'finger')) {
+ $.event.remove(this, startEvent + '.finger', startHandler);
+ $.data(this, 'finger', null);
}
-
- // handler
- f[handleObj.type].handlers[handleObj.handler.guid] = null;
}
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -2,7 +2,7 @@
"name": "finger",
"title": "jQuery Finger",
"description": "jQuery Finger unifies click and touch events by removing the 300ms delay on touch devices. It also provide a common set of events to handle basic gestures such as drag and pinch. Small (< 1kb gzipped), it is focused on performance, is well tested and ... also supports jQuery delegated events.",
- "version": "0.0.7",
+ "version": "0.0.8",
"homepage": "https://github.com/ngryman/jquery.finger",
"bugs": "https://github.com/ngryman/jquery.finger/issues",
"author": {
View
@@ -1,6 +1,6 @@
{
"name": "jquery.finger",
- "version": "0.0.7",
+ "version": "0.0.8",
"author": {
"name": "Nicolas Gryman",
"email": "ngryman@gmail.com"

0 comments on commit 8302e80

Please sign in to comment.