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

onComplete never gets called #36

Open brianjessup opened 10 years ago

brianjessup commented 10 years ago

I'm not sure if this is a bug or I'm wrong about the intended functionality of the onComplete function.

But when bootstro.next is called, the activeIndex is always 2 less than the count. activeIndex being incremented from 0, and count being the total count. E.g. when I am on step 7 of 8 on your demo page, and click next, the activeIndex = 6 and the count is = 8.

Therefore the onComplete call in the below code is never called.

bootstro.next = function() { if (activeIndex + 1 == count) { if (typeof settings.onComplete == 'function') settings.onComplete.call(this, {idx : activeIndex});// } else { bootstro.go_to(activeIndex + 1); if (typeof settings.onStep == 'function') settings.onStep.call(this, {idx : activeIndex, direction : 'next'});// } };

What confuses me is the "else" statement. Are you intending for the onComplete here to be accesses with a next button located on the last step of the tour? Shouldn't that be an onExit?

What we are trying to use the onComplete for is to flag in our db that the tour has been taken. In that case, the code should read like:

bootstro.next = function() { if (activeIndex + 2 == count) { //call onComplete callback function if needed if (this.onCompleteFunc != undefined) { this.onCompleteFunc.call(this, { idx : activeIndex }); } } bootstro.go_to(activeIndex + 1); if (typeof settings.onStep == 'function') settings.onStep.call(this, {idx : activeIndex, direction : 'next'});// };

ericpeters0n commented 10 years ago

Also seeing onComplete be completely ignored.

ericpeters0n commented 10 years ago

@brianjessup For my purposes, I simply transposed the call to onComplete to the event handler for .bootstro-finish-btn... ln390:


            //end of show
            $("html").on('click.bootstro', ".bootstro-finish-btn", function(e){
                e.preventDefault();

                //
                if (typeof settings.onComplete == 'function')
                    settings.onComplete.call(this, {idx : activeIndex});//
                //

                bootstro.stop();
            });        
brianjessup commented 10 years ago

@ericpeters0n nice! Thanks.