bespokejs / bespoke

DIY Presentation Micro-Framework
http://markdalgleish.com/projects/bespoke.js/
MIT License
4.68k stars 443 forks source link

Events return the previously-active slide instead of the newly-active slide #5

Closed ultimatedelman closed 11 years ago

ultimatedelman commented 11 years ago

This may be intended behavior, although I can't imagine why. If I want to wire up a deck to display which slide is current, I want to do something like this (assume jQuery):

var deck = bespoke.horizontal.from('article');
deck.on('next', onNav);
deck.on('prev', onNav);

function onNav(e) { 
     $('.indexcounter').text(e.index);
}

But instead it shows which one WAS active instead of which one is GOING TO BE active. This severely limits the usefulness of the events.

markdalgleish commented 11 years ago

For your purposes, you should be using the 'activate' event:

var deck = bespoke.horizontal.from('article');
deck.on('activate', onActivate);

function onActivate(e) { 
     $('.indexcounter').text(e.index);
}

The 'next' and 'prev' events are intended for intercepting plugins, like 'bespoke-bullets'. The events are fired whenever the user requests the next or previous slide, even if the user is on the last or first slide.

The current slide index is provided since that is the slide that will dictate whether you prevent the default behaviour in your event handler, if that makes sense. Check out the bespoke-bullets source code if you need a working example of this.

I'm working on an update to the readme to clear up this misunderstanding.