Skip to content

Commit

Permalink
use parent node if touched on text node for touch events, prevents br…
Browse files Browse the repository at this point in the history
…eakage
  • Loading branch information
madrobby committed Oct 12, 2010
1 parent 769dffd commit bbd3220
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/touch.js
@@ -1,9 +1,13 @@
(function($){
var d = document, touch={}, touchTimeout;

function parentIfText(node){
return 'tagName' in node ? node : node.parentNode;
}

d.ontouchstart = function(e) {
var now = Date.now(), delta = now-(touch.last || now);
touch.target = e.touches[0].target;
touch.target = parentIfText(e.touches[0].target);
touchTimeout && clearTimeout(touchTimeout);
touch.x1 = e.touches[0].pageX;
if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
Expand Down Expand Up @@ -33,4 +37,4 @@
['swipe', 'doubleTap', 'tap'].forEach(function(m){
$.fn[m] = function(callback){ return this.bind(m, callback) }
});
})(Zepto);
})(Zepto);

0 comments on commit bbd3220

Please sign in to comment.