From 6ab961d070e364061dd7ea01757d06ad9c33e98f Mon Sep 17 00:00:00 2001 From: Daoud Clarke Date: Sat, 25 Dec 2021 09:50:58 +0000 Subject: [PATCH] Look for onchange events to get it working on mobile --- tinysearchengine/static/index.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tinysearchengine/static/index.js b/tinysearchengine/static/index.js index bba7aef..36d900f 100644 --- a/tinysearchengine/static/index.js +++ b/tinysearchengine/static/index.js @@ -10,26 +10,24 @@ window.onload = (event) => { const length = searchInput.value.length; searchInput.setSelectionRange(length, length); - searchInput.addEventListener('keyup', (e) => { + searchInput.oninput = e => { console.log("Key", e.key); - if (e.key.length == 1 || e.key === 'Backspace') { - console.log(searchInput.value); + console.log(searchInput.value); - const encodedValue = encodeURIComponent(searchInput.value); - fetch('/search?s=' + encodedValue).then(response => { - clearResults(); - console.log(response); - response.json().then(content => { - console.log(content); - for (const [i, element] of content.entries()) { - addResult(element.title, element.extract, element.url, i); - }; - ts.selected = null; - ts.numItems = content.length; - }); + const encodedValue = encodeURIComponent(searchInput.value); + fetch('/search?s=' + encodedValue).then(response => { + clearResults(); + console.log(response); + response.json().then(content => { + console.log(content); + for (const [i, element] of content.entries()) { + addResult(element.title, element.extract, element.url, i); + }; + ts.selected = null; + ts.numItems = content.length; }); - } - }); + }); + }; // Handle moving the selected item up and down document.addEventListener('keydown', (e) => {