From bfda0bebf480ed0796f49e785115c2a18a29b7f0 Mon Sep 17 00:00:00 2001 From: JarredMack Date: Mon, 8 Sep 2014 10:09:38 +1000 Subject: [PATCH 1/2] Ensure slide diff calculation is a number Updating the slide method to recalculate the "to" target as a number. Existing method had unexpected behavior when "to" was passed in as a string, as the + operator would concatenate, instead of adding. --- swipe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swipe.js b/swipe.js index 8b29717..54d1b22 100644 --- a/swipe.js +++ b/swipe.js @@ -123,7 +123,7 @@ function Swipe(container, options) { // if going forward but to < index, use to = slides.length + to // if going backward but to > index, use to = -slides.length + to - if (direction !== natural_direction) to = -direction * slides.length + to; + if (direction !== natural_direction) to = -direction * slides.length + Number(to); } From 34b380bb28a5adf91fe46246bb25c01fe130c8c1 Mon Sep 17 00:00:00 2001 From: JarredMack Date: Mon, 8 Sep 2014 16:16:04 +1000 Subject: [PATCH 2/2] Moving length init outside of setup Moved the length init outside of the setup() method, as it was recalculating on window resize and causing getNumSlides() to return an incorrect value --- swipe.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swipe.js b/swipe.js index 54d1b22..1cc3b3d 100644 --- a/swipe.js +++ b/swipe.js @@ -28,7 +28,8 @@ function Swipe(container, options) { // quit if no root element if (!container) return; var element = container.children[0]; - var slides, slidePos, width, length; + var slides, slidePos, width; + var length = element.children.length; options = options || {}; var index = parseInt(options.startSlide, 10) || 0; var speed = options.speed || 300; @@ -38,7 +39,6 @@ function Swipe(container, options) { // cache slides slides = element.children; - length = slides.length; // set continuous to false if only one slide if (slides.length < 2) options.continuous = false;