I am using a set of functions pull an image from the URL. For example if the URL is example.com/image/8/ the 8th image will be loaded.
The problem is that when the URL is less than 10 it doesn't work (and my function sets the varNumber to 1, but when its 10 or more the fuction works fine. Here is the code..
var totalCount = '<?php echo $total; ?>';
HREF = '<?php echo get_permalink($post->ID); ?>';
var url = window.location.pathname;
var urlsplit = url.split("/");
var imgNumber = urlsplit[5];
if (typeof imgNumber === 'undefined') {
imgNumber = 1;
} else if (imgNumber < 1) {
imgNumber = 1;
history.pushState('', '', HREF);
} else if (imgNumber > totalCount) {
alert("else if ( " + imgNumber + " > " + totalCount + ")");
imgNumber = 1;
history.pushState('', '', HREF);
} else {
$("#slider-"+imgNumber).removeClass("img-inactive");
$("#slider-"+imgNumber).addClass("img-active");
$("#slider-1").removeClass("img-active");
$("#slider-1").addClass("img-inactive");
}
As you can see the code above first checks to see if the varNumber is defined then checks if its less than 1. After that it checks if it's greater than the totalCount. This is where it gets messed up. Ive checked my browser console and ran the alerts to to verify the totalCount and imgNumber have variables.
To get a better example see the following links:
imgNumber > totalCount Does not work... http://badsentinel.com/2014/09/18/daily-giftastic-take-away-these-three-fingers-and-what-are-we-left-with-13-gifs/3/
imgNumber > totalCount works fine... http://badsentinel.com/2014/09/18/daily-giftastic-take-away-these-three-fingers-and-what-are-we-left-with-13-gifs/10/
Thanks in advance