@@ -6,6 +6,7 @@ import { TPLightboxPreviousElement } from './tp-lightbox-previous';
66import { TPLightboxNextElement } from './tp-lightbox-next' ;
77import { TPLightboxTriggerElement } from './tp-lightbox-trigger' ;
88import { TPLightboxCountElement } from './tp-lightbox-count' ;
9+ import { TPLightboxNavItemElement } from './tp-lightbox-nav-item' ;
910
1011/**
1112 * TP Lightbox.
@@ -21,6 +22,7 @@ export class TPLightboxElement extends HTMLElement {
2122 protected touchStartY : number = 0 ;
2223 protected swipeThreshold : number = 200 ;
2324 protected dialogElement : HTMLDialogElement | null ;
25+ protected lightboxNavItems : NodeListOf < TPLightboxNavItemElement > | null ;
2426
2527 /**
2628 * Constructor.
@@ -31,6 +33,7 @@ export class TPLightboxElement extends HTMLElement {
3133
3234 // Initialize
3335 this . dialogElement = this . querySelector ( 'dialog' ) ;
36+ this . lightboxNavItems = this . querySelectorAll ( 'tp-lightbox-nav-item' ) ;
3437
3538 // Event listeners.
3639 this . dialogElement ?. addEventListener ( 'click' , this . handleDialogClick . bind ( this ) ) ;
@@ -69,6 +72,11 @@ export class TPLightboxElement extends HTMLElement {
6972 if ( 'index' === name ) {
7073 this . triggerCurrentIndexTarget ( ) ;
7174 }
75+
76+ // Trigger navigation update if open or index has changed.
77+ if ( 'open' === name || 'index' === name ) {
78+ this . updateNavCurrentItem ( ) ;
79+ }
7280 }
7381
7482 /**
@@ -159,6 +167,13 @@ export class TPLightboxElement extends HTMLElement {
159167
160168 // Setting this attributes triggers a re-trigger.
161169 this . setAttribute ( 'index' , index . toString ( ) ) ;
170+
171+ // dispatch slide-set event.
172+ this . dispatchEvent ( new CustomEvent ( 'slide-set' , {
173+ detail : {
174+ slideIndex : index ,
175+ } ,
176+ } ) ) ;
162177 }
163178
164179 /**
@@ -482,4 +497,25 @@ export class TPLightboxElement extends HTMLElement {
482497 }
483498 }
484499 }
500+
501+ /**
502+ * Update current item in navigation.
503+ */
504+ updateNavCurrentItem ( ) : void {
505+ // Bail if we don't have nav items.
506+ if ( ! this . lightboxNavItems ) {
507+ // Exit.
508+ return ;
509+ }
510+
511+ // Update current item.
512+ this . lightboxNavItems . forEach ( ( navItem : TPLightboxNavItemElement , index : number ) : void => {
513+ // Update current attribute.
514+ if ( this . currentIndex - 1 === index ) {
515+ navItem . setAttribute ( 'current' , 'yes' ) ;
516+ } else {
517+ navItem . removeAttribute ( 'current' ) ;
518+ }
519+ } ) ;
520+ }
485521}
0 commit comments