Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deck.slide(-1) should go to last slide #59

Open
mojavelinux opened this issue Sep 18, 2015 · 5 comments
Open

deck.slide(-1) should go to last slide #59

mojavelinux opened this issue Sep 18, 2015 · 5 comments

Comments

@mojavelinux
Copy link
Contributor

To make life for plugin authors simpler, it would be nice if deck.slide(-1) went to the last slide to avoid having to constantly type:

deck.slide(deck.slides.length - 1);

If this isn't acceptable, a reasonable compromise might be to add a deck.end() method to advance to the last slide.

@mojavelinux
Copy link
Contributor Author

wdyt @markdalgleish? Should we add this convenience or is this just something plugin authors need to live with? I don't want to add unnecessary bloat to bespoke.js core, so if you think we can live without this API, I'm willing to accept that.

@hsablonniere
Copy link
Member

I agree with you @mojavelinux, I think this could be helpful. This helper was present is DZslides 😉
I also think that it's not that we can live without it, the alternative is not that big/complex 😛

⚠️ If we add this to core, we should not bind a fixed length. Authoring tools could inject slides and change the slide deck length at runtime.

@mojavelinux
Copy link
Contributor Author

I'm pretty sure I got the idea from DZSlides (or, perhaps I should say, DZSlides had spoiled me).

One of the key arguments for this change is that it really starts to add up across a collection of plugins. The property "length" doesn't get minimized, and it takes two steps to get to it. And many plugins have this somewhere in the code. (That may even be a strong case for "first" and "last" methods, though those are harder to work with in dynamic code).

@hsablonniere
Copy link
Member

We would need something like this then :

deck = {
  on: on,
  off: off,
  fire: fire,
  slide: slide,
  next: step.bind(null, 1),
  prev: step.bind(null, -1),

  // new helpers here :
  first: slide.bind(null, 0),
  last: function () {
    deck.slide(deck.slides.length - 1);
  },
  // new helpers !

  slides: slides
};

I think that this way, it would be truly dynamic.

@hsablonniere
Copy link
Member

Or as you proposed, we do not add new helpers and we just use 0 and -1. This would require to update activate like this :

We would need something like this then :

activate = function(index, customData) {
  if (index === -1) {
    index = deck.slides.length - 1;
  }
  else if (!slides[index]) {
    return;
  }

  fire('deactivate', createEventData(activeSlide, customData));
  activeSlide = slides[index];
  fire('activate', createEventData(activeSlide, customData));
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants