From fd7b367e9e86414e1187a26fa93f8218df5d24b5 Mon Sep 17 00:00:00 2001 From: Mosa Al-Husseini Date: Fri, 26 Apr 2024 13:47:44 +0200 Subject: [PATCH] [TASK] change language menu --- theme/js/custom.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/theme/js/custom.js b/theme/js/custom.js index dfa460b..9c0bb42 100644 --- a/theme/js/custom.js +++ b/theme/js/custom.js @@ -1 +1,23 @@ // global custom JS +document.addEventListener('DOMContentLoaded', (event) => { + // Select the button text + const buttonText = document.querySelector('.header-language-btn-text') + if (buttonText.textContent === 'SV-SE') { + buttonText.textContent = 'SV' + } + if (buttonText.textContent === 'DA-DK') { + buttonText.textContent = 'DK' + } + + // Select the list items + const listItems = document.querySelectorAll('.header-language__list-item-link') + listItems.forEach(item => { + if (item.getAttribute('lang') === 'sv-se') { + item.setAttribute('lang', 'SV') + item.textContent = 'Svenska' + } else if (item.getAttribute('lang') === 'da-dk') { + item.setAttribute('lang', 'DK') + item.textContent = 'Dansk' + } + }) +})