From 72a4f49240c737f027bd3cfba69fd3ad5ae1df31 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 1 Jun 2022 10:17:35 +0300 Subject: [PATCH 1/3] fix: Correctly scroll to URL fragment after augmenting tables --- ietf/static/js/list.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ietf/static/js/list.js b/ietf/static/js/list.js index ffc52d2aa7b..a75574d3ac8 100644 --- a/ietf/static/js/list.js +++ b/ietf/static/js/list.js @@ -279,4 +279,10 @@ $(document) $(table)[0] .dispatchEvent(new Event("tablesorter:done")); }); + + // if the URL contains a #, scroll to it again, since we modified the DOM + const id = window.location.hash; + if (id) { + $(id)[0].scrollIntoView(); + } }); From a8e8b42529ca08898617adc8e5eefea29d156d05 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 1 Jun 2022 10:18:04 +0300 Subject: [PATCH 2/3] feat: Only add search field to longer tables --- ietf/static/js/list.js | 85 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/ietf/static/js/list.js b/ietf/static/js/list.js index a75574d3ac8..85575653974 100644 --- a/ietf/static/js/list.js +++ b/ietf/static/js/list.js @@ -83,31 +83,36 @@ $(document) header_row.addClass("d-none"); } - // HTML for the search widget - var searcher = $.parseHTML(` -
- - -
`); - - $(table) - .before(searcher); - - var search_field = $(searcher) - .children("input.search"); + // only add a search box if the table length warrants it + var enable_search = $(table).find("tr").length > 5; + if (enable_search) { + // HTML for the search widget + var searcher = $.parseHTML(` +
+ + +
`); + + $(table) + .before(searcher); + + var search_field = $(searcher) + .children("input.search"); + + var reset_search = $(searcher) + .children("button.search-reset"); + } - var reset_search = $(searcher) - .children("button.search-reset"); + // TODO: The pager functionality is not working yet + // var pager = $.parseHTML(` + // `); - var pager = $.parseHTML(` - `); - - $(table) - .before(pager); + // $(table) + // .before(pager); var list_instance = []; var internal_table = []; @@ -194,23 +199,25 @@ $(document) })); }); - reset_search.on("click", function () { - search_field.val(""); - $.each(list_instance, (i, e) => { - e.search(); - }); - }); - - search_field.on("keyup", function (event) { - if (event.key == "Escape") { - reset_search.trigger("click"); - } else { + if (enable_search) { + reset_search.on("click", function () { + search_field.val(""); $.each(list_instance, (i, e) => { - e.search($(this) - .val()); + e.search(); }); - } - }); + }); + + search_field.on("keyup", function (event) { + if (event.key == "Escape") { + reset_search.trigger("click"); + } else { + $.each(list_instance, (i, e) => { + e.search($(this) + .val()); + }); + } + }); + } $(table) .find(".sort") @@ -281,7 +288,7 @@ $(document) }); // if the URL contains a #, scroll to it again, since we modified the DOM - const id = window.location.hash; + var id = window.location.hash; if (id) { $(id)[0].scrollIntoView(); } From 6a3d5df34e1de11fa1d7ffbaa672f8d1ace5aa9e Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 1 Jun 2022 10:58:48 +0300 Subject: [PATCH 3/3] Tweak vertical whitespace around search field --- ietf/static/js/list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ietf/static/js/list.js b/ietf/static/js/list.js index 85575653974..73f57fee17f 100644 --- a/ietf/static/js/list.js +++ b/ietf/static/js/list.js @@ -88,7 +88,7 @@ $(document) if (enable_search) { // HTML for the search widget var searcher = $.parseHTML(` -
+