|
157 | 157 | return;
|
158 | 158 | }
|
159 | 159 |
|
160 |
| - // Don't do anything if noting to slide to |
161 |
| - if (this.slides.length === 0) { |
| 160 | + const len = this.slides.length; |
| 161 | + |
| 162 | + // Don't do anything if nothing to slide to |
| 163 | + if (len === 0) { |
162 | 164 | return;
|
163 | 165 | }
|
164 | 166 |
|
165 | 167 | // Don't change slide while transitioning, wait until transition is done
|
166 | 168 | if (this.isSliding) {
|
| 169 | + // Schedule slide after sliding complete |
167 | 170 | this.$once('slid', () => this.setSlide(slide));
|
168 | 171 | return;
|
169 | 172 | }
|
170 | 173 |
|
171 |
| - // Wrap around if necessary |
172 |
| - this.index = Math.max(0, Math.min(Math.floor(slide), this.slides.length - 1)); |
| 174 | + // Make sure we have an integer (you never know!) |
| 175 | + slide = Math.floor(slide); |
| 176 | +
|
| 177 | + // Set new slide index. Wrap around if necessary |
| 178 | + this.index = slide >= len ? 0 : (slide >= 0 ? slide : len - 1); |
173 | 179 | },
|
174 | 180 |
|
175 | 181 | // Previous slide
|
|
223 | 229 |
|
224 | 230 | const id = this.id;
|
225 | 231 | const numSlides = this.slides.length;
|
| 232 | +
|
226 | 233 | // Keep slide number in range
|
227 | 234 | const index = Math.max(0, Math.min(Math.floor(this.index), numSlides - 1));
|
228 |
| - |
| 235 | +
|
229 | 236 | this.slides.forEach((slide, idx) => {
|
230 | 237 | const n = idx + 1;
|
231 |
| - if (idx === index) { |
232 |
| - slide.classList.add('active'); |
233 |
| - } else { |
234 |
| - slide.classList.remove('active'); |
235 |
| - } |
| 238 | +
|
| 239 | + slide.classList[idx === index ? 'add' : 'remove']('active'); |
236 | 240 | slide.setAttribute('aria-current', idx === index ? 'true' : 'false');
|
237 | 241 | slide.setAttribute('aria-posinset', String(n));
|
238 | 242 | slide.setAttribute('aria-setsize', String(numSlides));
|
|
271 | 275 | return;
|
272 | 276 | }
|
273 | 277 | if (!Boolean(newVal)) {
|
274 |
| - // Pausing slide show |
| 278 | + // Pausing slide show |
275 | 279 | this.pause();
|
276 | 280 | } else {
|
277 | 281 | // Restarting or Changing interval
|
|
0 commit comments