mirror of
https://github.com/imfing/hextra.git
synced 2025-07-04 22:57:18 -04:00
feat: add multi-language select and fix minor issues
fix: navbar icon should use home relative link fix: copy code for raw <code> element fix: missing breadcrumb hover style fix: tabs typo preventing loading the script
This commit is contained in:
28
assets/js/lang.js
Normal file
28
assets/js/lang.js
Normal file
@ -0,0 +1,28 @@
|
||||
(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('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('hidden');
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
Reference in New Issue
Block a user