From 60dfe449dd63d87d8b90c4898a4024b7065fd9fa Mon Sep 17 00:00:00 2001 From: Wallysson Nunes Date: Thu, 27 Aug 2015 17:02:03 -0300 Subject: [PATCH] Fixed call of stop() method which was causing too many calls into events API, like next() and prev making too many unnecessary calls --- swipe.js | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/swipe.js b/swipe.js index 8b29717..73d20d9 100644 --- a/swipe.js +++ b/swipe.js @@ -217,18 +217,19 @@ function Swipe(container, options) { var interval; function begin() { - interval = setTimeout(next, delay); - } function stop() { - delay = 0; - clearTimeout(interval); - + stopSliderInterval(); } + function stopSliderInterval() { + clearTimeout(interval); + } + + // setup initial vars var start = {}; @@ -309,7 +310,7 @@ function Swipe(container, options) { event.preventDefault(); // stop slideshow - stop(); + stopSliderInterval(); // increase resistance if first or last slide if (options.continuous) { // we don't add resistance at the end @@ -468,45 +469,27 @@ function Swipe(container, options) { // expose the Swipe API return { setup: function() { - setup(); - }, slide: function(to, speed) { - - // cancel slideshow - stop(); - + stopSliderInterval(); slide(to, speed); - }, prev: function() { - - // cancel slideshow - stop(); - + stopSliderInterval(); prev(); - }, next: function() { - - // cancel slideshow - stop(); - + stopSliderInterval(); next(); - }, stop: function() { - // cancel slideshow stop(); - }, getPos: function() { - // return current index position return index; - }, getNumSlides: function() {