From c5136c2df2529e5b681d13f13077d25006fbe693 Mon Sep 17 00:00:00 2001 From: Luke Snowden Date: Wed, 16 Jul 2014 22:08:04 +0100 Subject: [PATCH] cancel if target is anchor tag If an anchor is enclosed within a swipeable area it still needs to act as an anchor --- js/jquery.swipe-events.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/js/jquery.swipe-events.js b/js/jquery.swipe-events.js index cfafadf..d15163b 100644 --- a/js/jquery.swipe-events.js +++ b/js/jquery.swipe-events.js @@ -1,30 +1,32 @@ -(function($) { +(function($) { $.fn.swipeEvents = function() { return this.each(function() { - + var startX, startY, $this = $(this); - + $this.bind('touchstart', touchstart); - + function touchstart(event) { - var touches = event.originalEvent.touches; - if (touches && touches.length) { - startX = touches[0].pageX; - startY = touches[0].pageY; - $this.bind('touchmove', touchmove); - $this.bind('touchend', touchend); + if( event.originalEvent.target.nodeName.toLowerCase() !== 'a' ) { + var touches = event.originalEvent.touches; + if (touches && touches.length) { + startX = touches[0].pageX; + startY = touches[0].pageY; + $this.bind('touchmove', touchmove); + $this.bind('touchend', touchend); + } + event.preventDefault(); } - event.preventDefault(); } - + function touchmove(event) { var touches = event.originalEvent.touches; if (touches && touches.length) { var deltaX = startX - touches[0].pageX; var deltaY = startY - touches[0].pageY; - + if (deltaX >= 50) { $this.trigger("swipeLeft"); } @@ -44,12 +46,12 @@ } event.preventDefault(); } - + function touchend(event) { $this.unbind('touchmove', touchmove); event.preventDefault(); } - + }); }; })(jQuery);