From 580b9133a872ec6afa524864926a0859271aec77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 17 Jun 2024 11:43:42 +0200 Subject: [PATCH] Add image gallery (Spotlight) --- index.html | 1 + js/package.json | 3 ++- js/ui.js | 72 ++++++++++++++++++++++++++++++++----------------- js/yarn.lock | 5 ++++ 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index b52641e..b0f327a 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ + Carta Archeologica di Capri diff --git a/js/package.json b/js/package.json index 125484c..ad7209f 100644 --- a/js/package.json +++ b/js/package.json @@ -7,7 +7,8 @@ "dependencies": { "bulma": "^1.0.1", "fontawesome-free": "^1.0.4", - "leaflet": "^1.9.4" + "leaflet": "^1.9.4", + "spotlight.js": "^0.7.8" }, "devDependencies": {} } diff --git a/js/ui.js b/js/ui.js index cf66150..1d77500 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1,5 +1,7 @@ 'use strict'; +import Spotlight from './vendor/spotlight.js/src/js/spotlight.js'; + /** * @namespace UI */ @@ -67,6 +69,7 @@ UI.toggleMenu = function (triggerId) { } /** * Open a modal with DB data + * @todo Refactor! Web components?? * @param {object} data The data retrieved from the DB to display as modal content */ UI.openModal = async function (data) { @@ -105,33 +108,32 @@ UI.openModal = async function (data) { } if (data.surveys.length) { table += `Elaborazioni CNR da rilievi`; - for (const img of data.surveys) { - table += ` - - -
- -
${img.didascalia}
-
- - - `; - } + table += ` + + +

Cliccare sull'immagine per aprire la gallery

+ + + + `; } if (data.photos.length) { table += `Fotografie`; - for (const img of data.photos) { - table += ` - - -
- -
${img.didascalia}
-
- - - `; - } + table += ` + + +

Cliccare sull'immagine per aprire la gallery

+ + + + `; + // Open gallery when image is clicked } table += ''; @@ -147,6 +149,9 @@ UI.openModal = async function (data) { modalBg.addEventListener('click', () => { closeModal(); }); + + this.imageGallery('gallery-1', data.surveys); + this.imageGallery('gallery-2', data.photos); } /** * @param {string} menuListSel Menu list selector @@ -170,5 +175,24 @@ UI.sitesMenu = function (menuListSel, map, sites) { } }); } +/** + * Open Spotlight gallery + * @param {string} galleryId The id of the trigger element + * @param {Array} images Array of image objects from DB + */ +UI.imageGallery = function (galleryId, images) { + const element = document.querySelector(`#${galleryId}`); + + if (element) { + let gallery = []; + for (let img of images) { + gallery.push({src: `/img/${img.filename}`, description: img.didascalia}); + } + + document.querySelector(`#${galleryId}`).addEventListener('click', () => { + Spotlight.show(gallery); + }); + } +} export default UI; \ No newline at end of file diff --git a/js/yarn.lock b/js/yarn.lock index 36d4ab0..a463d0c 100644 --- a/js/yarn.lock +++ b/js/yarn.lock @@ -16,3 +16,8 @@ leaflet@^1.9.4: version "1.9.4" resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d" integrity sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA== + +spotlight.js@^0.7.8: + version "0.7.8" + resolved "https://registry.yarnpkg.com/spotlight.js/-/spotlight.js-0.7.8.tgz#0620371701508222d736e0658e8db3fbe9ddc53b" + integrity sha512-zq822gqhjaMHt31oZi4do211NwqBcxZ4u7Xtb+OEsbLrz37dcELhBCoQXFu/0sTiomqD6tm5g6tmqvE7S6h4ng==