From b6d00d3984c1b8a6db61376778b97c029c466139 Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Thu, 30 Jan 2025 11:05:19 -0500 Subject: [PATCH 1/2] Do not repeat processing of icon if it exists. --- src/decorate.js | 1 + test/decorate/decorateIcon.test.html | 89 ++++++++++++++++++---------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/decorate.js b/src/decorate.js index b4a951f..1df5b15 100644 --- a/src/decorate.js +++ b/src/decorate.js @@ -50,6 +50,7 @@ export function decorateButtons(element) { * @param {string} [alt] alt text to be added to icon */ export function decorateIcon(span, prefix = '', alt = '') { + if (span.querySelector('img')) return; const iconName = Array.from(span.classList).find((c) => c.startsWith('icon-')).substring(5); const img = document.createElement('img'); img.dataset.iconName = iconName; diff --git a/test/decorate/decorateIcon.test.html b/test/decorate/decorateIcon.test.html index fbd356e..02c22ac 100644 --- a/test/decorate/decorateIcon.test.html +++ b/test/decorate/decorateIcon.test.html @@ -1,39 +1,64 @@ - + }); + From 67323fc3c1ba1fb41d254933acdbd7adaf01c33d Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Mon, 3 Feb 2025 14:09:37 -0500 Subject: [PATCH 2/2] Possible other decoration creates Icon ref. --- src/decorate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decorate.js b/src/decorate.js index 1df5b15..1b34304 100644 --- a/src/decorate.js +++ b/src/decorate.js @@ -50,7 +50,7 @@ export function decorateButtons(element) { * @param {string} [alt] alt text to be added to icon */ export function decorateIcon(span, prefix = '', alt = '') { - if (span.querySelector('img')) return; + if (span.hasChildNodes()) return; // Any children we assume the icon is already decorated const iconName = Array.from(span.classList).find((c) => c.startsWith('icon-')).substring(5); const img = document.createElement('img'); img.dataset.iconName = iconName;