Skip to content

Commit

Permalink
fix(carousel): Ensure slideshow restarts when reaching the end
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorehouse committed Aug 11, 2017
1 parent 4e5a4cc commit e175c36
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/components/carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,25 @@
return;
}
// Don't do anything if noting to slide to
if (this.slides.length === 0) {
const len = this.slides.length;
// Don't do anything if nothing to slide to
if (len === 0) {
return;
}
// Don't change slide while transitioning, wait until transition is done
if (this.isSliding) {
// Schedule slide after sliding complete
this.$once('slid', () => this.setSlide(slide));
return;
}
// Wrap around if necessary
this.index = Math.max(0, Math.min(Math.floor(slide), this.slides.length - 1));
// Make sure we have an integer (you never know!)
slide = Math.floor(slide);
// Set new slide index. Wrap around if necessary
this.index = slide >= len ? 0 : (slide >= 0 ? slide : len - 1);
},
// Previous slide
Expand Down Expand Up @@ -223,16 +229,14 @@
const id = this.id;
const numSlides = this.slides.length;
// Keep slide number in range
const index = Math.max(0, Math.min(Math.floor(this.index), numSlides - 1));
this.slides.forEach((slide, idx) => {
const n = idx + 1;
if (idx === index) {
slide.classList.add('active');
} else {
slide.classList.remove('active');
}
slide.classList[idx === index ? 'add' : 'remove']('active');
slide.setAttribute('aria-current', idx === index ? 'true' : 'false');
slide.setAttribute('aria-posinset', String(n));
slide.setAttribute('aria-setsize', String(numSlides));
Expand Down Expand Up @@ -271,7 +275,7 @@
return;
}
if (!Boolean(newVal)) {
// Pausing slide show
// Pausing slide show
this.pause();
} else {
// Restarting or Changing interval
Expand Down

0 comments on commit e175c36

Please sign in to comment.