diff --git a/express/blocks/template-list/template-list.js b/express/blocks/template-list/template-list.js index feeef9c1..1c82beaa 100644 --- a/express/blocks/template-list/template-list.js +++ b/express/blocks/template-list/template-list.js @@ -10,7 +10,8 @@ import { addAnimationToggle, createOptimizedPicture, linkImage } from '../../scr import { fetchRelevantRows } from '../../scripts/utils/relevant.js'; import { fixIcons, getIconElement } from '../../scripts/utils/icons.js'; -import { addTempWrapperDeprecated, decorateButtonsDeprecated, fetchBlockFragDecorated, decorateSocialIcons } from '../../scripts/utils/decorate.js'; +import { addTempWrapperDeprecated, decorateButtonsDeprecated, decorateSocialIcons } from '../../scripts/utils/decorate.js'; +import { fetchBlockFragDeprecated } from '../../scripts/utils/loadBlock.js'; import { Masonry } from '../../scripts/widgets/masonry.js'; @@ -1843,7 +1844,7 @@ async function replaceRRTemplateList(block, props) { props.viewAllLink = relevantRowsData.viewAllLink || null; if (relevantRowsData.manualTemplates === 'Y') { - const sectionFromFragment = await fetchBlockFragDecorated(`/express/fragments/relevant-rows/${relevantRowsData.templateFragment}`, 'template-list'); + const sectionFromFragment = await fetchBlockFragDeprecated(`/express/fragments/relevant-rows/${relevantRowsData.templateFragment}`, 'template-list'); const newBlock = sectionFromFragment.querySelector('.template-list'); if (newBlock) { diff --git a/express/scripts/utils/decorate.js b/express/scripts/utils/decorate.js index 355da165..d527067c 100644 --- a/express/scripts/utils/decorate.js +++ b/express/scripts/utils/decorate.js @@ -1,8 +1,5 @@ -import { getLibs } from '../utils.js'; import { getIconElement } from './icons.js'; -const { createTag, getConfig } = await import(`${getLibs()}/utils/utils.js`); - // This was only added for the blocks premigration. It is not to be used for new blocks. export function decorateButtonsDeprecated(el) { el.querySelectorAll(':scope a').forEach(($a) => { @@ -85,32 +82,6 @@ export function normalizeHeadings(block, allowedHeadings) { }); } -export async function fetchBlockFragDecorated(url, blockName) { - const location = new URL(window.location); - const { prefix } = getConfig().locale; - const fragmentUrl = `${location.origin}${prefix}${url}`; - - const path = new URL(fragmentUrl).pathname.split('.')[0]; - const resp = await fetch(`${path}.plain.html`); - if (resp.status === 404) { - return null; - } - - const html = await resp.text(); - const section = createTag('div'); - section.innerHTML = html; - section.className = `section section-wrapper ${blockName}-container`; - const block = section.querySelector(`.${blockName}`); - block.dataset.blockName = blockName; - block.parentElement.className = `${blockName}-wrapper`; - block.classList.add('block'); - const img = section.querySelector('img'); - if (img) { - img.setAttribute('loading', 'lazy'); - } - return section; -} - export function decorateSocialIcons($main) { $main.querySelectorAll(':scope a').forEach(($a) => { const urlObject = new URL($a.href); diff --git a/express/scripts/utils/loadBlock.js b/express/scripts/utils/loadBlock.js new file mode 100644 index 00000000..c7cdbe74 --- /dev/null +++ b/express/scripts/utils/loadBlock.js @@ -0,0 +1,30 @@ +import { getLibs } from '../utils.js'; + +const { createTag, getConfig } = await import(`${getLibs()}/utils/utils.js`); + +// eslint-disable-next-line import/prefer-default-export +export async function fetchBlockFragDeprecated(url, blockName) { + const location = new URL(window.location); + const { prefix } = getConfig().locale; + const fragmentUrl = `${location.origin}${prefix}${url}`; + + const path = new URL(fragmentUrl).pathname.split('.')[0]; + const resp = await fetch(`${path}.plain.html`); + if (resp.status === 404) { + return null; + } + + const html = await resp.text(); + const section = createTag('div'); + section.innerHTML = html; + section.className = `section section-wrapper ${blockName}-container`; + const block = section.querySelector(`.${blockName}`); + block.dataset.blockName = blockName; + block.parentElement.className = `${blockName}-wrapper`; + block.classList.add('block'); + const img = section.querySelector('img'); + if (img) { + img.setAttribute('loading', 'lazy'); + } + return section; +}