clu3 / bootstro.js

Tiny JS library using bootstrap's popovers to help guide your users around your website
http://clu3.github.io/bootstro.js/
MIT License
1.33k stars 235 forks source link

Addressed issue causing the tour to break when a particular step is missing #24

Open tsrivishnu opened 11 years ago

tsrivishnu commented 11 years ago

Hello.,

Here is my suggested solution for issue #5

As I understood the issue is being caused since you were incrementing the index value when the user tries to go to the next popup. So when a particular step is missing, you are shifting to the DOM order which causes the tour popups to jump around without following a order.

What i have done is, I have taken all the steps indexes for the DOM into an array,

indexes = $elements.map(function(){ return parseInt($(this).attr('data-bootstro-step')) })

and if all the DOM elements are not provided with step, make the order default to follow DOM ordering

defaultOrder = $.grep(indexes, function(x){ return !(isNaN(x)) }).length == 0 ? true : false

So when ever the user tries to go for the next popup, I check over the indexes array to find if the index we are trying is existing, if not, trying for the next available index

nextIndex = function(indexToTry){
    closestIndex = null
    // loop and find the next available value less than or equal to the indexToTry
    $.each(indexes, function(){
       if (parseInt(this) >= parseInt(indexToTry)) {
           closestIndex = this;
           return false;
       }
    });
    return closestIndex;
 }

so it always will find the next available popup and go in a order rather than jumping around when a step is missing.

clu3 commented 11 years ago

@tsrivishnu thanks for the pull request, I will merge it once i've had a closer look.

tsrivishnu commented 11 years ago

@clu3 sure.. thanks..

tsrivishnu commented 11 years ago

@clu3 hey, this has been open for quite a long time. Let me know if you found any issues with the changes.

clu3 commented 11 years ago

@tsrivishnu Thanks a lot buddy for reminding. Could you please make it in 1 commit?

tsrivishnu commented 11 years ago

@clu3 hey there., I have squashed my four commits into one. You can check. #ec1e022