From decde989ff7614dc109af1fb42559ff4814ffc7c Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 14 Aug 2022 17:25:43 +0200 Subject: Removed search from the blog --- template/script.js | 97 ------------------------------------------------------ 1 file changed, 97 deletions(-) (limited to 'template/script.js') diff --git a/template/script.js b/template/script.js index 3c58403..796ea4f 100755 --- a/template/script.js +++ b/template/script.js @@ -1,17 +1,4 @@ window.addEventListener('load', async () => { - // dither image on mouse over replace - // document.querySelectorAll('article img').forEach(img => { - // const ditheredImage = img.src; - // const originalImage = img.src.replace('.dith.gif', ''); - - // img.addEventListener('mouseover', evt => { - // evt.target.src = originalImage; - // }); - - // img.addEventListener('mouseout', evt => { - // evt.target.src = ditheredImage; - // }); - // }); // flip CV image on mouse over const cvImage = document.querySelector('.cv-picture img'); @@ -25,88 +12,4 @@ window.addEventListener('load', async () => { }); } - // Search functionality - - window.index = null; - - const response = await fetch('/feed.json'); - const feed = await response.json(); - - window.index = elasticlunr(function () { - this.addField('title'); - this.addField('body'); - this.setRef('id'); - }); - - for (const item of feed.items) { - item.id = item.url; - window.index.addDoc({ - id: item.url, - title: item.title, - body: item.content_html, - url: item.url, - }); - } - - const blur = document.querySelector('.blur'); - const searchForm = document.querySelector('.search-form'); - const searchResultsList = document.querySelector('.search-form ul'); - - function showSearchModal() { - blur.classList.remove('hidden'); - searchForm.classList.remove('hidden'); - - // Clear search input. - searchForm.querySelector('input').value = ''; - - // We need to clear the list before opening modal. - searchResultsList.innerHTML = ''; - - // Focus on search input. - searchForm.querySelector('input').focus(); - } - - document.querySelector('.search-trigger').addEventListener('click', async (evt) => { - showSearchModal(); - }); - - document.onkeydown = function (e) { - // Show search modal on F key. - if (blur.classList.contains('hidden')) { - if (e.key === 'f') { - setTimeout(() => { - showSearchModal(); - }, 100); - } - } - - // Hide search modal on escape key. - if (!blur.classList.contains('hidden')) { - if (e.key === 'Escape') { - blur.classList.add('hidden'); - searchForm.classList.add('hidden'); - } - } - }; - - blur.addEventListener('click', async (evt) => { - evt.target.classList.add('hidden'); - searchForm.classList.add('hidden'); - }); - - document.querySelector('.search-form input').addEventListener('keyup', async (evt) => { - // Perform search. - const searchResults = window.index.search(evt.target.value); - - // We need to clear the list before adding new results. - searchResultsList.innerHTML = ''; - - // Loop through the results and add them to the list. - for (const result of searchResults.slice(0, 9)) { - const listItem = document.createElement('li'); - listItem.innerHTML = `${result.doc.title}`; - searchResultsList.appendChild(listItem); - } - }); - }); -- cgit v1.2.3