From 7a8b4f9ae1f8db4173ea2863e9bbf1b5312374f8 Mon Sep 17 00:00:00 2001 From: Manuel Strehl Date: Wed, 28 Feb 2024 21:58:25 +0100 Subject: [PATCH] remove more inline scripts --- codepoints.net/views/search.php | 8 ++++---- src/js/main.js | 7 ++++--- src/js/{_glossary.js => modules/glossary.js} | 4 ++-- src/js/modules/search.js | 12 ++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) rename src/js/{_glossary.js => modules/glossary.js} (92%) create mode 100644 src/js/modules/search.js diff --git a/codepoints.net/views/search.php b/codepoints.net/views/search.php index b3736662..56a1fd9c 100644 --- a/codepoints.net/views/search.php +++ b/codepoints.net/views/search.php @@ -17,12 +17,12 @@ $head_extra = << - var script_age = $script_age; - var region_to_block = $region_to_block; - HEAD_EXTRA; include 'partials/header.php' ?> +
data-count="count())?>">

diff --git a/src/js/main.js b/src/js/main.js index a1a06e31..7b1bfc36 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,7 +1,6 @@ import 'vite/modulepreload-polyfill'; import barba from '@barba/core'; -import { initGlossary } from './_glossary.js'; import { trackByContent } from './_tracker.js'; import './components.js'; @@ -9,8 +8,6 @@ import './components.js'; document.documentElement.classList.add('js'); function init(context) { - initGlossary(context); - /* embedded context? Open the full view in a new tab when * clicking on the image. */ if (window.parent !== window) { @@ -23,6 +20,10 @@ function init(context) { const main = context.querySelector('main'); if (main && main.classList.contains('main--scripts')) { import('./modules/scripts.js').then((mod) => { mod.default(context); }); + } else if (main && main.classList.contains('main--glossary')) { + import('./modules/glossary.js').then((mod) => { mod.default(context); }); + } else if (main && main.classList.contains('main--search')) { + import('./modules/search.js').then((mod) => { mod.default(context); }); } } diff --git a/src/js/_glossary.js b/src/js/modules/glossary.js similarity index 92% rename from src/js/_glossary.js rename to src/js/modules/glossary.js index 22b80e95..9cf9a3e9 100644 --- a/src/js/_glossary.js +++ b/src/js/modules/glossary.js @@ -1,9 +1,9 @@ -import {gettext as _} from './_i18n.ts'; +import {gettext as _} from '../_i18n.ts'; /** * create the A-B-C jump bar at the top of the actual glossary */ -export function initGlossary(context) { +export default function(context) { const glossary = context.querySelector('#glossary'); if (!glossary || glossary.dataset.upgraded) { return; diff --git a/src/js/modules/search.js b/src/js/modules/search.js new file mode 100644 index 00000000..684c91fe --- /dev/null +++ b/src/js/modules/search.js @@ -0,0 +1,12 @@ +export default function(context) { + const data = context.querySelector('#search_metadata'); + if (data) { + const parsedData = JSON.parse(data.textContent); + if ('script_age' in parsedData) { + window.script_age = parsedData.script_age; + } + if ('region_to_block' in parsedData) { + window.region_to_block = parsedData.region_to_block; + } + } +}