From b0ec6720a907f5883a926ce99663bf59d87a3e50 Mon Sep 17 00:00:00 2001 From: Rand Dvorak Date: Tue, 3 Jul 2012 18:36:25 -0400 Subject: [PATCH] fixed bug in supersize.flickr.1.1.2.js where flickr returns less than number of images requested. --- flickr/js/supersized.flickr.1.1.2.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/flickr/js/supersized.flickr.1.1.2.js b/flickr/js/supersized.flickr.1.1.2.js index aa8c2a3..9d47481 100644 --- a/flickr/js/supersized.flickr.1.1.2.js +++ b/flickr/js/supersized.flickr.1.1.2.js @@ -183,24 +183,34 @@ for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); //Fisher-Yates shuffle algorithm (jsfromhell.com/array/shuffle) options.slides = arr; } + + //*** if flickr returns a number of slides less than the total requested + if (currentSlide > options.slides.length - 1){ + options.random ? currentSlide = Math.floor(Math.random()*options.slides.length) : currentSlide = options.slides.length - 1; + } /***Load initial set of images***/ if (options.slides.length > 1){ //Set previous image currentSlide - 1 < 0 ? loadPrev = options.slides.length - 1 : loadPrev = currentSlide - 1; //If slide is 1, load last slide as previous - var imageLink = (options.slides[loadPrev].url) ? "href='" + options.slides[loadPrev].url + "'" : ""; + console.log("loadPrev: " + loadPrev + " currentSlide: " + currentSlide); + console.log(options.slides); + for(var i = 0; i < options.slides.length; i++) { + console.log(options.slides[i]); + } + var imageLink = (options.slides[loadPrev].url) ? "href='" + options.slides[loadPrev].url + "'" : "javascript:void(0)"; $("").attr("src", options.slides[loadPrev].image).appendTo(element).wrap(''); } //Set current image - imageLink = (options.slides[currentSlide].url) ? "href='" + options.slides[currentSlide].url + "'" : ""; + imageLink = (options.slides[currentSlide].url) ? "href='" + options.slides[currentSlide].url + "'" : "javascript:void(0)"; $("").attr("src", options.slides[currentSlide].image).appendTo(element).wrap(''); if (options.slides.length > 1){ //Set next image currentSlide == options.slides.length - 1 ? loadNext = 0 : loadNext = currentSlide + 1; //If slide is last, load first slide as next - imageLink = (options.slides[loadNext].url) ? "href='" + options.slides[loadNext].url + "'" : ""; + imageLink = (options.slides[loadNext].url) ? "href='" + options.slides[loadNext].url + "'" : "javascript:void(0)"; $("").attr("src", options.slides[loadNext].image).appendTo(element).wrap(''); }