forked from drowl87/hextra_mirror

* feat: add prefix to tailwind css classes * fix: remove unnecessary prefixes * fix: add missing prefix in other places * chore: regenerate hugo_stats.json * chore: run `npm run build:css` * chore: add `hx-` prefix to _index.fa.md * fix: lang switcher display issue * fix: add `hx-` prefix to showcase/index.fa.md * fix: lang switch param mistake
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
(function () {
|
|
const languageSwitchers = document.querySelectorAll('.language-switcher');
|
|
languageSwitchers.forEach((switcher) => {
|
|
switcher.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
switcher.dataset.state = switcher.dataset.state === 'open' ? 'closed' : 'open';
|
|
const optionsElement = switcher.nextElementSibling;
|
|
optionsElement.classList.toggle('hx-hidden');
|
|
|
|
// Calculate position of language options element
|
|
const switcherRect = switcher.getBoundingClientRect();
|
|
const translateY = switcherRect.top - window.innerHeight - 15;
|
|
optionsElement.style.transform = `translate3d(${switcherRect.left}px, ${translateY}px, 0)`;
|
|
optionsElement.style.minWidth = `${Math.max(switcherRect.width, 50)}px`;
|
|
});
|
|
});
|
|
|
|
// Dismiss language switcher when clicking outside
|
|
document.addEventListener('click', (e) => {
|
|
if (e.target.closest('.language-switcher') === null) {
|
|
languageSwitchers.forEach((switcher) => {
|
|
switcher.dataset.state = 'closed';
|
|
const optionsElement = switcher.nextElementSibling;
|
|
optionsElement.classList.add('hx-hidden');
|
|
});
|
|
}
|
|
});
|
|
})();
|