gallery.goToPage()
After matching a part of the url with an element in json, I get an index of that particular slide. The problem is calling gallery.goToPage() on that index... It always seems to just load the second slide during normal execution but if I use the console, I can go directly to the slide using that function.
Ex: lets say the index is 31... it goes to slide num:2.
The only clue I have is that upcoming == "311" if my index is 31 which seems like a type error. This variable is set in gallery.onFlip();
All I need to do is call goToPage on load and have it execute properly.
code
// if slide alias is in thePath
var thePath = document.location.pathname
var firstSlideAlias = thePath.substring(thePath.lastIndexOf('/'), thePath.length);
//conforms to a path with an gallery or slide alias appended
if ( (thePath.match(/\//g)||[]).length === 5 ) {
if ( firstSlideAlias.length > 1 ) {
firstSlideAlias = firstSlideAlias.replace('/','');
for (var i in slides) {
if ( firstSlideAlias === slides[i].alias ) {
console.log(firstSlideAlias);
console.log(slides[i].alias);
slideIndex = i;
}
}
console.log(slides[slideIndex]);
console.log(slideIndex);
gallery.goToPage(slideIndex);
}
}
fixed by wrapping in setTimeout()
if ( (thePath.match(/\//g)||[]).length === 5 ) {
if ( firstSlideAlias.length > 1 ) {
firstSlideAlias = firstSlideAlias.replace('/','');
for (var i in slides) {
if ( firstSlideAlias === slides[i].alias ) {
slideIndex = i;
setTimeout(function(){
gallery.goToPage(slideIndex);
}, 100);
}
}
}
}
Had the same issue, and was a mistake from me. Be sure to pass a number to the goToPage() method, or convert your string to Int ( parseInt( (yourIndex) , 10);