aboutsummaryrefslogtreecommitdiff
path: root/174bg/handbook/source/search.js
diff options
context:
space:
mode:
authorAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-30 03:35:39 +0100
committerAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-30 03:35:39 +0100
commitaff4bcfe4934ad308f55a9e947e8811019d9af6b (patch)
tree55bec893b29b2825d7022688316929adc1192b63 /174bg/handbook/source/search.js
parentd6b268829c0bf2d5b5b063d668be6ff0deed408a (diff)
downloadunnamed-group-aff4bcfe4934ad308f55a9e947e8811019d9af6b.tar
unnamed-group-aff4bcfe4934ad308f55a9e947e8811019d9af6b.tar.gz
unnamed-group-aff4bcfe4934ad308f55a9e947e8811019d9af6b.tar.bz2
unnamed-group-aff4bcfe4934ad308f55a9e947e8811019d9af6b.tar.xz
unnamed-group-aff4bcfe4934ad308f55a9e947e8811019d9af6b.zip
search! :O
Diffstat (limited to '174bg/handbook/source/search.js')
-rw-r--r--174bg/handbook/source/search.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/174bg/handbook/source/search.js b/174bg/handbook/source/search.js
new file mode 100644
index 0000000..d42337f
--- /dev/null
+++ b/174bg/handbook/source/search.js
@@ -0,0 +1,36 @@
+/**
+ * search.js
+ *
+ * Provides simple client-side filtering of the handbook's articles.
+ *
+ * How it works:
+ * 1. Pressing the "/" key anywhere on the page focuses the search input
+ * (id "search-input"), unless focus is already needed elsewhere.
+ * 2. As the user types, every `<article>` in `<main>` is shown or hidden
+ * based on whether its text content includes the (case-insensitive)
+ * query string.
+ */
+document.addEventListener("keypress", function (event) {
+ if (event.key === "/") {
+ const searchInput = document.getElementById("search-input");
+ if (searchInput) {
+ searchInput.focus();
+ event.preventDefault();
+ }
+ }
+});
+
+document
+ .querySelector("#search-input")
+ .addEventListener("input", function (event) {
+ const query = event.target.value.toLowerCase();
+ const articles = document.querySelectorAll("main article");
+ articles.forEach((article) => {
+ const text = article.textContent.toLowerCase();
+ if (text.includes(query)) {
+ article.style.display = "";
+ } else {
+ article.style.display = "none";
+ }
+ });
+ });