Skip to content

Commit 6b5850a

Browse files
committed
Fix issue with duplicate slides
1 parent 5ada1f6 commit 6b5850a

File tree

5 files changed

+67
-73
lines changed

5 files changed

+67
-73
lines changed

dist/js/parvus.esm.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -352,26 +352,28 @@ function Parvus(userOptions) {
352352

353353

354354
const createSlide = function createSlide(el, index) {
355-
const SLIDER_ELEMENT = document.createElement('div');
356-
const SLIDER_ELEMENT_CONTENT = document.createElement('div');
357-
SLIDER_ELEMENT.className = 'parvus__slide';
358-
SLIDER_ELEMENT.style.position = 'absolute';
359-
SLIDER_ELEMENT.style.left = `${index * 100}%`; // Hide slide
355+
if (groups[activeGroup].sliderElements[index] !== undefined) ; else {
356+
const SLIDER_ELEMENT = document.createElement('div');
357+
const SLIDER_ELEMENT_CONTENT = document.createElement('div');
358+
SLIDER_ELEMENT.className = 'parvus__slide';
359+
SLIDER_ELEMENT.style.position = 'absolute';
360+
SLIDER_ELEMENT.style.left = `${index * 100}%`; // Hide slide
360361

361-
SLIDER_ELEMENT.setAttribute('aria-hidden', 'true');
362-
createImage(index, el, SLIDER_ELEMENT_CONTENT); // Add slide content container to slider element
362+
SLIDER_ELEMENT.setAttribute('aria-hidden', 'true');
363+
createImage(index, el, SLIDER_ELEMENT_CONTENT); // Add slide content container to slider element
363364

364-
SLIDER_ELEMENT.appendChild(SLIDER_ELEMENT_CONTENT);
365-
groups[activeGroup].sliderElements[index] = SLIDER_ELEMENT; // Add slider element to slider
365+
SLIDER_ELEMENT.appendChild(SLIDER_ELEMENT_CONTENT);
366+
groups[activeGroup].sliderElements[index] = SLIDER_ELEMENT; // Add slider element to slider
366367

367-
if (index === currentIndex) {
368-
groups[activeGroup].slider.appendChild(SLIDER_ELEMENT);
369-
}
368+
if (index === currentIndex) {
369+
groups[activeGroup].slider.appendChild(SLIDER_ELEMENT);
370+
}
370371

371-
if (index > currentIndex) {
372-
groups[activeGroup].sliderElements[currentIndex].after(SLIDER_ELEMENT);
373-
} else {
374-
groups[activeGroup].sliderElements[currentIndex].before(SLIDER_ELEMENT);
372+
if (index > currentIndex) {
373+
groups[activeGroup].sliderElements[currentIndex].after(SLIDER_ELEMENT);
374+
} else {
375+
groups[activeGroup].sliderElements[currentIndex].before(SLIDER_ELEMENT);
376+
}
375377
}
376378
};
377379
/**
@@ -499,14 +501,9 @@ function Parvus(userOptions) {
499501
lightbox.classList.remove('parvus--is-closing');
500502
lightbox.classList.remove('parvus--is-vertical-closing'); // Reset groups
501503

502-
/* TODO: Mach's halt richtig :-/
503-
groups[activeGroup].gallery = []
504-
groups[activeGroup].slider = null
505-
groups[activeGroup].sliderElements = []
506-
groups[activeGroup].images = []
507-
*/
508-
509504
groups[activeGroup].slider.remove();
505+
groups[activeGroup].slider = null;
506+
groups[activeGroup].sliderElements = [];
510507
IMAGE.style.transform = '';
511508
}, {
512509
once: true

dist/js/parvus.esm.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/parvus.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,28 @@
358358

359359

360360
const createSlide = function createSlide(el, index) {
361-
const SLIDER_ELEMENT = document.createElement('div');
362-
const SLIDER_ELEMENT_CONTENT = document.createElement('div');
363-
SLIDER_ELEMENT.className = 'parvus__slide';
364-
SLIDER_ELEMENT.style.position = 'absolute';
365-
SLIDER_ELEMENT.style.left = `${index * 100}%`; // Hide slide
361+
if (groups[activeGroup].sliderElements[index] !== undefined) ; else {
362+
const SLIDER_ELEMENT = document.createElement('div');
363+
const SLIDER_ELEMENT_CONTENT = document.createElement('div');
364+
SLIDER_ELEMENT.className = 'parvus__slide';
365+
SLIDER_ELEMENT.style.position = 'absolute';
366+
SLIDER_ELEMENT.style.left = `${index * 100}%`; // Hide slide
366367

367-
SLIDER_ELEMENT.setAttribute('aria-hidden', 'true');
368-
createImage(index, el, SLIDER_ELEMENT_CONTENT); // Add slide content container to slider element
368+
SLIDER_ELEMENT.setAttribute('aria-hidden', 'true');
369+
createImage(index, el, SLIDER_ELEMENT_CONTENT); // Add slide content container to slider element
369370

370-
SLIDER_ELEMENT.appendChild(SLIDER_ELEMENT_CONTENT);
371-
groups[activeGroup].sliderElements[index] = SLIDER_ELEMENT; // Add slider element to slider
371+
SLIDER_ELEMENT.appendChild(SLIDER_ELEMENT_CONTENT);
372+
groups[activeGroup].sliderElements[index] = SLIDER_ELEMENT; // Add slider element to slider
372373

373-
if (index === currentIndex) {
374-
groups[activeGroup].slider.appendChild(SLIDER_ELEMENT);
375-
}
374+
if (index === currentIndex) {
375+
groups[activeGroup].slider.appendChild(SLIDER_ELEMENT);
376+
}
376377

377-
if (index > currentIndex) {
378-
groups[activeGroup].sliderElements[currentIndex].after(SLIDER_ELEMENT);
379-
} else {
380-
groups[activeGroup].sliderElements[currentIndex].before(SLIDER_ELEMENT);
378+
if (index > currentIndex) {
379+
groups[activeGroup].sliderElements[currentIndex].after(SLIDER_ELEMENT);
380+
} else {
381+
groups[activeGroup].sliderElements[currentIndex].before(SLIDER_ELEMENT);
382+
}
381383
}
382384
};
383385
/**
@@ -505,14 +507,9 @@
505507
lightbox.classList.remove('parvus--is-closing');
506508
lightbox.classList.remove('parvus--is-vertical-closing'); // Reset groups
507509

508-
/* TODO: Mach's halt richtig :-/
509-
groups[activeGroup].gallery = []
510-
groups[activeGroup].slider = null
511-
groups[activeGroup].sliderElements = []
512-
groups[activeGroup].images = []
513-
*/
514-
515510
groups[activeGroup].slider.remove();
511+
groups[activeGroup].slider = null;
512+
groups[activeGroup].sliderElements = [];
516513
IMAGE.style.transform = '';
517514
}, {
518515
once: true

0 commit comments

Comments
 (0)