--- --- console.log(document.querySelectorAll('*').length); if ("{{ site.removeBootstrapJs }}" === "true") { const languagesModal = document.querySelector("#staticBackdrop"); const intModalBtn = document.querySelector("#int-modal-btn"); const closeBtn = document.querySelector("#close-modal"); if (intModalBtn) { intModalBtn.addEventListener("click", () => { languagesModal.style.display = "block"; languagesModal.classList.add("show"); let modal = document.createElement("div"); modal.classList.add("modal-backdrop", "show"); document.body.appendChild(modal); }); closeBtn.addEventListener("click", () => { languagesModal.style.display = "none"; languagesModal.classList.remove("show"); let modal = document.querySelector(".modal-backdrop"); document.body.removeChild(modal); }); } var mediaQuery = window.matchMedia("(max-width: 768px)") const wordGamesToolbarListItems = document.querySelectorAll( ".wordgames-toolbar-list-item-span" ); if (mediaQuery.matches) { Array.from(wordGamesToolbarListItems).map((item) => { item.addEventListener("click", (e) => { e.preventDefault(); var style = window.getComputedStyle(item.nextElementSibling); var maxHeight = style.getPropertyValue("max-height"); if (maxHeight && maxHeight !== "0px") { // If the item is expanded, collapse it item.nextElementSibling.style.maxHeight = "0"; item.nextElementSibling.style.opacity = "0"; item.nextElementSibling.style.height = "0"; } else { // If the item is collapsed, expand it item.nextElementSibling.style.maxHeight = item.nextElementSibling.scrollHeight + "px"; item.nextElementSibling.style.opacity = "1"; item.nextElementSibling.style.height = "auto"; } }); }); } const navbarToggler = document.querySelector('.navbar-toggler'); const navBar = document.querySelector('#navbarSupportedContent'); const menuIcon = '/assets/images/hamburger-menu.svg'; const closeIcon = '/assets/images/close-menu.svg'; const imgElement = navbarToggler.querySelector('img'); navbarToggler.addEventListener('click', () => { if (navBar.classList.contains('show')) { navBar.classList.remove('show'); navBar.style.display = 'none'; imgElement.src = menuIcon; // Change to hamburger menu icon when closing } else { navBar.classList.add('show'); navBar.style.display = 'block'; imgElement.src = closeIcon; // Change to close icon when opening } }); } const searchWorker = new Worker('/assets/js/search-worker.js'); function fetchData() { return new Promise((resolve, reject) => { searchWorker.postMessage({ type: "api", endpoint: `/alllinks.json` }); searchWorker.onmessage = (event) => { resolve(event.data.data.featuredLinks); }; searchWorker.onerror = (error) => { reject(error); }; }); } function filterData(data, query) { return data.filter(item => item.name.toLowerCase().includes(query.toLowerCase())); } function displayResults(results) { const resultsContainer = document.getElementById('results'); resultsContainer.style.display = results.length ? 'block' : 'none'; resultsContainer.innerHTML = results.length ? results.map(result => `
${result.name}
`).join('') : '

No results found

'; } const searchInput = document.querySelector('.searchBar input'); let data; searchInput.addEventListener('input', async (event) => { if (searchInput.value !== '') { searchInput.classList.add('blinkBoxShadow'); } else { searchInput.classList.remove('blinkBoxShadow'); } const query = event.target.value; if (!data) { // Fetch the data only if it hasn't been fetched before data = await fetchData(); } const filteredResults = filterData(data, query); displayResults(filteredResults); gtag('event', 'search', { 'event_category': 'engagement', 'event_label': 'Search Box', 'value': query }); }); searchInput.addEventListener('blur', () => { searchInput.classList.remove('blinkBoxShadow'); }); document.addEventListener('click', (event) => { const resultsContainer = document.getElementById('results'); if (!searchInput.contains(event.target) && !resultsContainer.contains(event.target)) { resultsContainer.style.display = 'none'; } });