From c8ad794b5edb9a99eee9492e82cb2a7991c1c787 Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Sun, 18 Oct 2020 21:05:53 +0200 Subject: [PATCH] refactor and hook up filter control filter content after at least three characters have been typed --- index.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index ed3b167..c203972 100644 --- a/index.html +++ b/index.html @@ -49,14 +49,19 @@ document.addEventListener("DOMContentLoaded", event => { return response.text(); }).then(function(text) { const converter = new Converter(text); - const content = document.getElementById("content"); - content.append(converter.generate()); + const update = filter => { + converter.filter = filter; + const content = document.getElementById("content"); + while (content.firstChild) content.firstChild.remove(); + content.append(converter.generate()); + }; // update content when typing a filter word document.getElementById("filter").addEventListener("input", event => { - // TODO: re-run converter to filter table rows and highlight typed text + update(event.target.value.length >= 3 ? event.target.value : ""); }); // place cursor in filter control document.getElementById("filter").focus(); + update(""); }); });