From 0eec05289b0a7205b4513974d187bbf41fb76455 Mon Sep 17 00:00:00 2001 From: "Whitney, Christopher" Date: Thu, 22 Oct 2015 10:02:09 -0700 Subject: [PATCH 1/2] update enent listerner to handle querySelectorAll and return event --- simple-swipe.js | 56 +++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/simple-swipe.js b/simple-swipe.js index bdeec17..bfbfa2f 100644 --- a/simple-swipe.js +++ b/simple-swipe.js @@ -60,6 +60,7 @@ this.y = event.touches[0].pageY; if (this.callbackMove) { this.callbackMove({ + event: event, direction: this.getDirection(), directionLast: this.getDirection(this.getAngle(this.prevX, this.prevY)), length: this.getLength(), @@ -74,6 +75,7 @@ event.preventDefault(); if (this.callbackEnd) { this.callbackEnd({ + event: event, direction: this.getDirection(), length: this.getLength(), }, this.el); @@ -90,36 +92,40 @@ }, handleEvent: function (event) { switch (event.type) { - case 'touchmove': - this.touchMove(event); - break; - case 'touchstart': - this.touchStart(event); - break; - case 'touchend': - this.touchEnd(event); - break; - case 'touchcancel': - this.touchCancel(); - break; - case 'touchleave': - this.touchCancel(); - break; + case 'touchmove': + this.touchMove(event); + break; + case 'touchstart': + this.touchStart(event); + break; + case 'touchend': + this.touchEnd(event); + break; + case 'touchcancel': + this.touchCancel(); + break; + case 'touchleave': + this.touchCancel(); + break; } }, addListeners: function () { - this.el.addEventListener('touchcancel', this); - this.el.addEventListener('touchend', this); - this.el.addEventListener('touchleave', this); - this.el.addEventListener('touchmove', this); - this.el.addEventListener('touchstart', this); + for(var i = 0; i < this.el.length; i++) { + this.el[i].addEventListener('touchcancel', this); + this.el[i].addEventListener('touchend', this); + this.el[i].addEventListener('touchleave', this); + this.el[i].addEventListener('touchmove', this); + this.el[i].addEventListener('touchstart', this); + } }, removeListeners: function () { - this.el.removeEventListener('touchcancel', this); - this.el.removeEventListener('touchend', this); - this.el.removeEventListener('touchleave', this); - this.el.removeEventListener('touchmove', this); - this.el.removeEventListener('touchstart', this); + for(var i = 0; i < this.el.length; i++) { + this.el[i].removeEventListener('touchcancel', this); + this.el[i].removeEventListener('touchend', this); + this.el[i].removeEventListener('touchleave', this); + this.el[i].removeEventListener('touchmove', this); + this.el[i].removeEventListener('touchstart', this); + } }, }; From 44556871e30ea7ee5e55b998b1c8c37f6ac3408f Mon Sep 17 00:00:00 2001 From: Chris Whitney Date: Thu, 21 Jan 2016 09:00:24 -0800 Subject: [PATCH 2/2] Fix bug when not using querySelectorAll --- simple-swipe.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simple-swipe.js b/simple-swipe.js index bfbfa2f..c5d8177 100644 --- a/simple-swipe.js +++ b/simple-swipe.js @@ -110,6 +110,9 @@ } }, addListeners: function () { + if(this.el.length === undefined) { + this.el = [this.el]; + } for(var i = 0; i < this.el.length; i++) { this.el[i].addEventListener('touchcancel', this); this.el[i].addEventListener('touchend', this); @@ -119,6 +122,9 @@ } }, removeListeners: function () { + if(this.el.length === undefined) { + this.el = [this.el]; + } for(var i = 0; i < this.el.length; i++) { this.el[i].removeEventListener('touchcancel', this); this.el[i].removeEventListener('touchend', this);