From 5b33675f81a52ad507d3a3f2d4d69f25dac80330 Mon Sep 17 00:00:00 2001 From: Nirav Sherasiya Date: Fri, 29 Nov 2024 12:22:14 +0530 Subject: [PATCH] Refactor function call and remove bubble from custom event --- src/lightbox/tp-lightbox.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/lightbox/tp-lightbox.ts b/src/lightbox/tp-lightbox.ts index 982ad1f..a648946 100644 --- a/src/lightbox/tp-lightbox.ts +++ b/src/lightbox/tp-lightbox.ts @@ -72,6 +72,11 @@ export class TPLightboxElement extends HTMLElement { if ( 'index' === name ) { this.triggerCurrentIndexTarget(); } + + // Trigger navigation update if open or index has changed. + if ( 'open' === name || 'index' === name) { + this.updateNavCurrentItem(); + } } /** @@ -202,9 +207,6 @@ export class TPLightboxElement extends HTMLElement { // Now, show the modal. dialog.showModal(); this.setAttribute( 'open', 'yes' ); - - // Update navigation current item. - this.updateNavCurrentItem(); } /** @@ -243,9 +245,6 @@ export class TPLightboxElement extends HTMLElement { if ( this.currentIndex > 1 ) { this.currentIndex--; } - - // Update navigation current item. - this.updateNavCurrentItem(); } /** @@ -271,9 +270,6 @@ export class TPLightboxElement extends HTMLElement { if ( this.currentIndex < allGroups.length ) { this.currentIndex++; } - - // Update navigation current item. - this.updateNavCurrentItem(); } /** @@ -509,7 +505,6 @@ export class TPLightboxElement extends HTMLElement { // dispatch slide-set event. this.dispatchEvent( new CustomEvent( 'slide-set', { - bubbles: true, detail: { slideIndex: index, },