diff --git a/web-apps/store-front/css/grid.css b/web-apps/store-front/css/grid.css index 3fd2463..dab9eb3 100644 --- a/web-apps/store-front/css/grid.css +++ b/web-apps/store-front/css/grid.css @@ -22,3 +22,4 @@ grid-template-columns: 20% 20% 20% 20% 20%; } } + diff --git a/web-apps/store-front/js/.#grid-of-photos.js b/web-apps/store-front/js/.#grid-of-photos.js deleted file mode 120000 index f112fc5..0000000 --- a/web-apps/store-front/js/.#grid-of-photos.js +++ /dev/null @@ -1 +0,0 @@ -andrea@lv5.321700:1727085997 \ No newline at end of file diff --git a/web-apps/store-front/js/grid-of-photos.js b/web-apps/store-front/js/grid-of-photos.js index 3e0c487..3d362d0 100644 --- a/web-apps/store-front/js/grid-of-photos.js +++ b/web-apps/store-front/js/grid-of-photos.js @@ -8,15 +8,19 @@ class GridOfPhotos extends HTMLElement { constructor () { // Inherit parent class properties super(); - + // LIsten for events this.addEventListener('click', this); + this.addEventListener('keydown', this); } /** * Runs each time the element is appended to or moved in the DOM */ async connectedCallback () { + + // Create the dialog element + this.dialog = document.createElement('dialog'); // Fetch the photos from the API this.photos = await this.fetchPhotos(); @@ -29,7 +33,7 @@ class GridOfPhotos extends HTMLElement { // Render the element this.innerHTML = `
- ${this.photos.map( (image) => { return `${image.description}` } ).join('')} + ${this.photos.map( (image) => { return `${image.description}` } ).join('')}
` } @@ -58,30 +62,26 @@ class GridOfPhotos extends HTMLElement { * @param {Event} event - The event object */ handleEvent (event) { + console.log(event); this[`on${event.type}`](event); } /** - * Handle the click event - * @param {Event} event - The event object + * Open the modal window that shows the photo. */ - onclick (event) { + handleOpenPhoto (event) { if (!event.target.closest('img')) return; - let dialog = document.createElement('dialog'); - dialog.setAttribute('open', ''); - - dialog.innerHTML = ` + let image = this.photos.find( (image) => { return image.id === event.target.getAttribute('id') } ); + + this.dialog.setAttribute('open', ''); + this.dialog.innerHTML = `
-

Confirm Your Membership

+

${image.name}

- Thank you for signing up for a membership! - Please review the membership details below: + ${image.description}

- + ${image.description}
` - this.append(dialog); - } - + this.append(this.dialog); + } + + /** + * Close the modal window that shows the photo. + */ + handleClosePhoto (event) { + if (!event.target.closest('dialog button')) return; + + this.dialog.close(); + this.dialog.remove(); + } + + /** + * Handle the click event + * @param {Event} event - The event object + */ + onclick (event) { + this.handleOpenPhoto(event); + this.handleClosePhoto(event); + } + + onkeydown (event) { + console.log(event); + if (event.key === "Escape") { + this.handleClosePhoto(event); + } + } } // Define the new web component if ('customElements' in window) { - customElements.define('grid-of-photos', GridOfPhotos); + customElements.define('grid-of-photos', GridOfPhotos); }