From f750d2451cf2bc60feb71b406972c0da416791bc Mon Sep 17 00:00:00 2001 From: Doxa Life Date: Fri, 2 Oct 2026 08:28:00 +0000 Subject: [PATCH] Regions: a Country Posters toggle under each region Each region on /regions gets a small Country Posters dropdown. On first opening it embeds DX Maps' poster section for that region () from this site's /dx-maps/ copy, in the site's language; the posters' script loads once, only when a toggle is opened. --- app/pages/regions/index.vue | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/app/pages/regions/index.vue b/app/pages/regions/index.vue index 0dcf7ef4..a248f36c 100644 --- a/app/pages/regions/index.vue +++ b/app/pages/regions/index.vue @@ -41,6 +41,64 @@ useSeoMeta({ }) useTextHighlight() + +// COUNTRY POSTERS, per region: a small toggle under each region that, when first opened, embeds DX Maps' poster +// section for that region (, from this site's own /dx-maps/ copy). Nothing poster-specific lives +// here: the element draws the posters, and the page loads its script once and hands it the region and the language. +// The label is DX Maps' own name for its Country Posters, in each language the site has (English for any other). +const POSTERS_LABEL: Record = { + en: 'Country Posters', + ar: 'ملصقات الدول', + de: 'Länderposter', + es: 'Carteles por país', + fr: 'Affiches par pays', + hi: 'देश पोस्टर', + it: 'Poster per paese', + pt: 'Cartazes por país', + ro: 'Afișe pe țări', + ru: 'Плакаты по странам', + zh: '国家海报' +} +const postersLabel = computed(() => POSTERS_LABEL[locale.value] || POSTERS_LABEL.en) +const POSTERS_TAG = 'dxm-poster-section' +const POSTERS_SCRIPT = '/dx-maps/country-posters/country-posters.js' +const runtimeConfig = useRuntimeConfig() +let postersLoad: Promise | null = null +function loadPosters(): Promise { + if (customElements.get(POSTERS_TAG)) return Promise.resolve() + postersLoad ??= new Promise((resolve, reject) => { + // the prayer API the posters read is set before the script runs + if (runtimeConfig.public.prayBaseUrl) window.MAP_APP_API_URL = runtimeConfig.public.prayBaseUrl as string + const script = document.createElement('script') + script.src = POSTERS_SCRIPT + script.onload = () => customElements.get(POSTERS_TAG) ? resolve() : reject(new Error('the posters bundle did not register')) + script.onerror = () => reject(new Error('the posters bundle failed to load')) + document.head.appendChild(script) + }).catch((err) => { + postersLoad = null // a later opening tries again + throw err + }) + return postersLoad +} +async function onPostersToggle(event: Event, slug: string) { + const details = event.currentTarget as HTMLDetailsElement + const body = details.querySelector('.region-posters__body') + if (!details.open || !body || body.firstElementChild) return + try { + await loadPosters() + } catch (err) { + console.error('[regions posters]', err) + return + } + const section = document.createElement(POSTERS_TAG) + section.setAttribute('type', 'country') + section.setAttribute('scope', slug) + section.setAttribute('locale', locale.value) + section.setAttribute('collapsible', 'false') + section.setAttribute('assets-base', '/dx-maps/assets') + if (runtimeConfig.public.prayBaseUrl) section.setAttribute('api-base-url', runtimeConfig.public.prayBaseUrl as string) + body.appendChild(section) +}