-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from Travelopia/feat/lightbox-navigation-bullets
Add Lightbox nav items
- Loading branch information
Showing
6 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Internal dependencies. | ||
*/ | ||
import { TPLightboxElement } from './tp-lightbox'; | ||
import { TPLightboxNavElement } from './tp-lightbox-nav'; | ||
|
||
/** | ||
* TP Lightbox Nav Item. | ||
*/ | ||
export class TPLightboxNavItemElement extends HTMLElement { | ||
/** | ||
* Properties. | ||
*/ | ||
protected lightbox : TPLightboxElement | null; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
constructor() { | ||
// Initialize parent. | ||
super(); | ||
this.lightbox = this.closest( 'tp-lightbox' ); | ||
|
||
// Get the nav-item button. | ||
this.querySelector( 'button' )?.addEventListener( 'click', this.handleClick.bind( this ) ); | ||
} | ||
|
||
/** | ||
* Handle when the button is clicked. | ||
*/ | ||
handleClick(): void { | ||
// Check if lightbox exists. | ||
if ( ! this.lightbox ) { | ||
// No its not! Terminate. | ||
return; | ||
} | ||
|
||
// Set current slide. | ||
this.lightbox.currentIndex = Number( this.getIndex() ) ?? 1; | ||
|
||
// Update navigation current item. | ||
this.lightbox.updateNavCurrentItem(); | ||
} | ||
|
||
/** | ||
* Get index of this item inside the navigation. | ||
* | ||
* @return {number} Index. | ||
*/ | ||
getIndex(): number { | ||
// Bail if no lightbox. | ||
if ( ! this.lightbox ) { | ||
// Exit. | ||
return 0; | ||
} | ||
|
||
// No, find it in the navigation. | ||
const lightboxNav: TPLightboxNavElement | null = this.closest( 'tp-lightbox-nav' ); | ||
|
||
// Return index of this element considering the step value. | ||
return ( Array.from( lightboxNav?.children ?? [] ).indexOf( this ) ) + 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* TP Lightbox Nav. | ||
*/ | ||
export class TPLightboxNavElement extends HTMLElement { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters