From 3f16928bf1057ce48a621ff09174f0e00e855156 Mon Sep 17 00:00:00 2001 From: simeydotme Date: Tue, 26 Jan 2016 01:50:09 +0800 Subject: [PATCH] [ bugfix 2055 ] - error with the handling on slider refresh - happens when going to a breakpoint with more slides to show than actual slides. - fixed bad condition structure. fixes #2055 --- slick/slick.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/slick/slick.js b/slick/slick.js index 3669d65bf..fccc8793e 100644 --- a/slick/slick.js +++ b/slick/slick.js @@ -1635,22 +1635,22 @@ Slick.prototype.refresh = function( initializing ) { - var _ = this, currentSlide, firstVisible; - - firstVisible = _.slideCount - _.options.slidesToShow; - - // check that the new breakpoint can actually accept the - // "current slide" as the current slide, otherwise we need - // to set it to the closest possible value. - if ( !_.options.infinite ) { - if ( _.slideCount <= _.options.slidesToShow ) { - _.currentSlide = 0; - } else if ( _.currentSlide > firstVisible ) { - _.currentSlide = firstVisible; - } + var _ = this, currentSlide, lastVisibleIndex; + + lastVisibleIndex = _.slideCount - _.options.slidesToShow; + + // in non-infinite sliders, we don't want to go past the + // last visible index. + if( !_.options.infinite && ( _.currentSlide > lastVisibleIndex )) { + _.currentSlide = lastVisibleIndex; + } + + // if less slides than to show, go to start. + if ( _.slideCount <= _.options.slidesToShow ) { + _.currentSlide = 0; } - currentSlide = _.currentSlide; + currentSlide = _.currentSlide; _.destroy(true);