From 3abc3a74798a82c28c240a6ec30da7c5bd7b11ff Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sat, 23 Dec 2023 16:08:10 -0500 Subject: [PATCH] Restore the placeholder when search is focused --- subdoc/lib/gen/generate_head.cc | 7 +++++++ subdoc/lib/gen/generate_search.cc | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/subdoc/lib/gen/generate_head.cc b/subdoc/lib/gen/generate_head.cc index e1c1599e..2657b5c2 100644 --- a/subdoc/lib/gen/generate_head.cc +++ b/subdoc/lib/gen/generate_head.cc @@ -120,9 +120,16 @@ void generate_head(HtmlWriter& html, std::string_view title, e.preventDefault(); } }; + var searchPlaceholder; document.querySelector(".search-input").onfocus = (e) => { + searchPlaceholder = e.target.placeholder; + e.target.placeholder = "Type your search here."; navigateToSearch(e.target.value); }; + document.querySelector(".search-input").onblur = (e) => { + e.target.placeholder = searchPlaceholder; + searchPlaceholder = null; + }; }); // Show or hide any DOM element. diff --git a/subdoc/lib/gen/generate_search.cc b/subdoc/lib/gen/generate_search.cc index c8382b7d..b4c21322 100644 --- a/subdoc/lib/gen/generate_search.cc +++ b/subdoc/lib/gen/generate_search.cc @@ -33,9 +33,6 @@ void generate_search_header(HtmlWriter::OpenMain& main) noexcept { search_input.add_autocomplete("off"); search_input.add_spellcheck("false"); search_input.add_placeholder("Click or press 'S' to search..."); - search_input.add_onblur( - "this.placeholder = 'Click or press \\'S\\' to search...'"); - search_input.add_onfocus("this.placeholder = 'Type your search here.'"); } }