Skip to content

Commit 4d73c4d

Browse files
committed
Allow openning same image twice, fix multiple images leaked into imageWrapper
1 parent 6f78852 commit 4d73c4d

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

dist/js/chocolat.cjs.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,14 @@ class Chocolat {
267267
}
268268

269269
load(index) {
270-
this.state.visible = true;
270+
if (!this.state.visible) {
271+
this.state.visible = true;
272+
setTimeout(() => {
273+
this.elems.overlay.classList.add('chocolat-visible');
274+
this.elems.wrapper.classList.add('chocolat-visible');
275+
}, 0);
276+
this.elems.container.classList.add('chocolat-open');
277+
}
271278

272279
if (this.settings.fullScreen) {
273280
this.state.fullScreenOpen = openFullScreen(this.elems.wrapper);
@@ -277,11 +284,6 @@ class Chocolat {
277284
return Promise.resolve();
278285
}
279286

280-
setTimeout(() => {
281-
this.elems.overlay.classList.add('chocolat-visible');
282-
this.elems.wrapper.classList.add('chocolat-visible');
283-
}, 0);
284-
this.elems.container.classList.add('chocolat-open');
285287
let loaderTimer = setTimeout(() => {
286288
this.elems.loader.classList.add('chocolat-visible');
287289
}, 1000);
@@ -350,9 +352,8 @@ class Chocolat {
350352
}
351353

352354
appear(image) {
353-
this.elems.img = image; // Not sure if needed to avoid white flickering ?
354-
// this.elems.imageWrapper.innerHTML = ''
355-
355+
this.elems.imageWrapper.removeChild(this.elems.img);
356+
this.elems.img = image;
356357
this.elems.img.setAttribute('class', 'chocolat-img');
357358
this.elems.imageWrapper.appendChild(this.elems.img);
358359
const fadeInPromise = transitionAsPromise(() => {

dist/js/chocolat.esm.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ class Chocolat {
265265
}
266266

267267
load(index) {
268-
this.state.visible = true;
268+
if (!this.state.visible) {
269+
this.state.visible = true;
270+
setTimeout(() => {
271+
this.elems.overlay.classList.add('chocolat-visible');
272+
this.elems.wrapper.classList.add('chocolat-visible');
273+
}, 0);
274+
this.elems.container.classList.add('chocolat-open');
275+
}
269276

270277
if (this.settings.fullScreen) {
271278
this.state.fullScreenOpen = openFullScreen(this.elems.wrapper);
@@ -275,11 +282,6 @@ class Chocolat {
275282
return Promise.resolve();
276283
}
277284

278-
setTimeout(() => {
279-
this.elems.overlay.classList.add('chocolat-visible');
280-
this.elems.wrapper.classList.add('chocolat-visible');
281-
}, 0);
282-
this.elems.container.classList.add('chocolat-open');
283285
let loaderTimer = setTimeout(() => {
284286
this.elems.loader.classList.add('chocolat-visible');
285287
}, 1000);
@@ -348,9 +350,8 @@ class Chocolat {
348350
}
349351

350352
appear(image) {
351-
this.elems.img = image; // Not sure if needed to avoid white flickering ?
352-
// this.elems.imageWrapper.innerHTML = ''
353-
353+
this.elems.imageWrapper.removeChild(this.elems.img);
354+
this.elems.img = image;
354355
this.elems.img.setAttribute('class', 'chocolat-img');
355356
this.elems.imageWrapper.appendChild(this.elems.img);
356357
const fadeInPromise = transitionAsPromise(() => {

dist/js/chocolat.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@
268268
}
269269

270270
load(index) {
271-
this.state.visible = true;
271+
if (!this.state.visible) {
272+
this.state.visible = true;
273+
setTimeout(() => {
274+
this.elems.overlay.classList.add('chocolat-visible');
275+
this.elems.wrapper.classList.add('chocolat-visible');
276+
}, 0);
277+
this.elems.container.classList.add('chocolat-open');
278+
}
272279

273280
if (this.settings.fullScreen) {
274281
this.state.fullScreenOpen = openFullScreen(this.elems.wrapper);
@@ -278,11 +285,6 @@
278285
return Promise.resolve();
279286
}
280287

281-
setTimeout(() => {
282-
this.elems.overlay.classList.add('chocolat-visible');
283-
this.elems.wrapper.classList.add('chocolat-visible');
284-
}, 0);
285-
this.elems.container.classList.add('chocolat-open');
286288
let loaderTimer = setTimeout(() => {
287289
this.elems.loader.classList.add('chocolat-visible');
288290
}, 1000);
@@ -351,9 +353,8 @@
351353
}
352354

353355
appear(image) {
354-
this.elems.img = image; // Not sure if needed to avoid white flickering ?
355-
// this.elems.imageWrapper.innerHTML = ''
356-
356+
this.elems.imageWrapper.removeChild(this.elems.img);
357+
this.elems.img = image;
357358
this.elems.img.setAttribute('class', 'chocolat-img');
358359
this.elems.imageWrapper.appendChild(this.elems.img);
359360
const fadeInPromise = transitionAsPromise(() => {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chocolat",
3-
"version": "1.0.0-beta.6",
3+
"version": "1.0.0-beta.7",
44
"description": "Responsive Lightbox Plugin",
55
"main": "dist/js/chocolat.cjs.js",
66
"module": "dist/js/chocolat.esm.js",

src/js/chocolat.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ export class Chocolat {
161161
}
162162

163163
load(index) {
164-
this.state.visible = true
164+
if (!this.state.visible) {
165+
this.state.visible = true
166+
167+
setTimeout(() => {
168+
this.elems.overlay.classList.add('chocolat-visible')
169+
this.elems.wrapper.classList.add('chocolat-visible')
170+
}, 0)
171+
172+
this.elems.container.classList.add('chocolat-open')
173+
}
165174

166175
if (this.settings.fullScreen) {
167176
this.state.fullScreenOpen = openFullScreen(this.elems.wrapper)
@@ -171,13 +180,6 @@ export class Chocolat {
171180
return Promise.resolve()
172181
}
173182

174-
setTimeout(() => {
175-
this.elems.overlay.classList.add('chocolat-visible')
176-
this.elems.wrapper.classList.add('chocolat-visible')
177-
}, 0)
178-
179-
this.elems.container.classList.add('chocolat-open')
180-
181183
let loaderTimer = setTimeout(() => {
182184
this.elems.loader.classList.add('chocolat-visible')
183185
}, 1000)
@@ -251,9 +253,8 @@ export class Chocolat {
251253
}
252254

253255
appear(image) {
256+
this.elems.imageWrapper.removeChild(this.elems.img)
254257
this.elems.img = image
255-
// Not sure if needed to avoid white flickering ?
256-
// this.elems.imageWrapper.innerHTML = ''
257258
this.elems.img.setAttribute('class', 'chocolat-img')
258259
this.elems.imageWrapper.appendChild(this.elems.img)
259260

0 commit comments

Comments
 (0)