Skip to content

Commit 8181c4f

Browse files
CopilotLukasWallrichricharddushime
authored
Add client-side search/filter to Glossary sidebar term list (#704)
* Initial plan * Add quick search/filter to Glossary pages for faster navigation Co-authored-by: LukasWallrich <60155545+LukasWallrich@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: LukasWallrich <60155545+LukasWallrich@users.noreply.github.com> Co-authored-by: Richard Dushime <45734838+richarddushime@users.noreply.github.com>
1 parent b47e64c commit 8181c4f

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

layouts/glossary/list.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,33 @@
1111
}
1212
</style>
1313

14+
<script>
15+
document.addEventListener("DOMContentLoaded", function() {
16+
const searchInput = document.getElementById('glossary-search');
17+
if (searchInput) {
18+
searchInput.addEventListener('input', function() {
19+
const query = this.value.toLowerCase();
20+
document.querySelectorAll('#TableOfContents .nav-item').forEach(function(item) {
21+
const link = item.querySelector('.nav-link');
22+
const text = link ? link.textContent.toLowerCase() : '';
23+
item.style.display = text.includes(query) ? '' : 'none';
24+
});
25+
});
26+
}
27+
});
28+
</script>
29+
1430
<div class="container-fluid docs">
1531
<div class="row flex-xl-nowrap">
1632
<div class="col-12 col-xl-3 docs-toc glossary-toc">
1733
<ul class="nav toc-top">
1834
<li><a href="#" id="back_to_top" class="docs-toc-title">List of terms</a></li>
1935
</ul>
2036

37+
<input type="text" id="glossary-search" class="form-control form-control-sm mb-2"
38+
placeholder="Filter terms..."
39+
aria-label="Filter terms">
40+
2141
<nav id="TableOfContents" class="nav flex-column">
2242
<ul>
2343
{{ $currentSection := .File.Dir }}

layouts/glossary/single.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{ $dictionary := dict
55
"english" (dict
66
"list_of_terms" "List of terms"
7+
"filter_terms" "Filter terms..."
78
"definition" "Definition"
89
"alt_definition" "Alternative definition"
910
"related_term" "Related term"
@@ -18,6 +19,7 @@
1819
)
1920
"german" (dict
2021
"list_of_terms" "Liste der Begriffe"
22+
"filter_terms" "Begriffe filtern..."
2123
"definition" "Definition"
2224
"alt_definition" "Alternative Definition"
2325
"related_term" "Verwandter Begriff"
@@ -32,6 +34,7 @@
3234
)
3335
"arabic" (dict
3436
"list_of_terms" "قائمة المصطلحات"
37+
"filter_terms" "تصفية المصطلحات..."
3538
"definition" "تعريف"
3639
"alt_definition" "تعريف بديل"
3740
"related_term" "مصطلح ذو صلة"
@@ -46,6 +49,7 @@
4649
)
4750
"turkish" (dict
4851
"list_of_terms" "Terimler listesi"
52+
"filter_terms" "Terimleri filtrele..."
4953
"definition" "Tanım"
5054
"alt_definition" "Alternatif tanım"
5155
"related_term" "İlgili terim"
@@ -117,6 +121,18 @@
117121
}
118122
}
119123
});
124+
125+
const searchInput = document.getElementById('glossary-search');
126+
if (searchInput) {
127+
searchInput.addEventListener('input', function() {
128+
const query = this.value.toLowerCase();
129+
document.querySelectorAll('#TableOfContents .nav-item').forEach(function(item) {
130+
const link = item.querySelector('.nav-link');
131+
const text = link ? link.textContent.toLowerCase() : '';
132+
item.style.display = text.includes(query) ? '' : 'none';
133+
});
134+
});
135+
}
120136
});
121137
</script>
122138

@@ -128,6 +144,10 @@
128144
<li><a href="#" id="back_to_top" class="docs-toc-title">{{ index (index $dictionary $lang) "list_of_terms" }}</a></li>
129145
</ul>
130146

147+
<input type="text" id="glossary-search" class="form-control form-control-sm mb-2"
148+
placeholder="{{ index (index $dictionary $lang) "filter_terms" }}"
149+
aria-label="{{ index (index $dictionary $lang) "filter_terms" }}">
150+
131151
<nav id="TableOfContents" class="nav flex-column">
132152
<ul>
133153
{{ $currentSection := .File.Dir }}

0 commit comments

Comments
 (0)