Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lightbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
<tp-lightbox-content></tp-lightbox-content>
<tp-lightbox-count format="$current / $total"></tp-lightbox-count>
<tp-lightbox-nav>
<tp-lightbox-nav-item><button>1</button></tp-lightbox-nav-item>
<tp-lightbox-nav-item><button>2</button></tp-lightbox-nav-item>
<tp-lightbox-nav-item><button>3</button></tp-lightbox-nav-item>
<tp-lightbox-nav-item><button>4</button></tp-lightbox-nav-item>
<template>
<tp-lightbox-nav-item>
<button>
</button>
</tp-lightbox-nav-item>
</template>
</tp-lightbox-nav>
</dialog>
</tp-lightbox>
Expand Down
51 changes: 51 additions & 0 deletions src/lightbox/tp-lightbox-nav.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
/**
* Internal dependencies.
*/
import { TPLightboxElement } from './tp-lightbox';

/**
* TP Lightbox Nav.
*/
export class TPLightboxNavElement extends HTMLElement {
/**
* Properties.
*/
protected template: HTMLTemplateElement | null = null;
protected lightbox : TPLightboxElement | null;

/**
* Constructor.
*/
constructor() {
// Initialize parent.
super();

// Initialize properties.
this.template = this.querySelector( 'template' );
this.lightbox = this.closest( 'tp-lightbox' );

// Add event listener.
this.lightbox?.addEventListener( 'template-set', this.setTemplate.bind( this ) );
}

/**
* Set the template.
*/
setTemplate(): void {
// Bail if no template.
if ( ! this.template ) {
// Exit.
return;
}

// Total slides.
const totalSlides = Number( this.lightbox?.getAttribute( 'total' ) ?? 0 );

// Clear the navigation.
this.innerHTML = '';

// Append the navigation items.
for ( let i = 0; i < totalSlides; i++ ) {
// Clone the template.
const navItem = this.template.content.cloneNode( true );

// Append the clone.
this.appendChild( navItem );
}
}
}
Loading