Skip to content

Commit c641fcd

Browse files
committed
feat: basic command search
1 parent 28e63d2 commit c641fcd

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

generate.py

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def generate_nav(sections):
6868

6969
def generate_command_table():
7070
out = """
71+
<input type="text" id="command-search" onkeyup="searchCommands()" placeholder="Search commands...">
7172
<table class="commands">
7273
<tr>
7374
<th>Command</th>

out/command-table.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function searchCommands() {
2+
let query = document.getElementById("command-search").value.toLowerCase();
3+
let commands = document.querySelectorAll(".commands tr:not(:first-child)");
4+
let anyMatch = false;
5+
commands.forEach(command => {
6+
let commandName = command.children[0].textContent.toLowerCase();
7+
let commandType = command.children[1].textContent.toLowerCase();
8+
let commandDescription = command.children[2].textContent.toLowerCase();
9+
if (commandName.includes(query) || commandType.includes(query) || commandDescription.includes(query)) {
10+
anyMatch = true;
11+
command.classList.remove('hidden');
12+
} else {
13+
command.classList.add('hidden');
14+
}
15+
});
16+
// if no matches, display all
17+
if (!anyMatch) {
18+
commands.forEach(command => command.classList.remove('hidden'));
19+
}
20+
}
21+
22+
window.addEventListener('load', () => {
23+
searchCommands();
24+
});

out/style.css

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ td, th {
9898
text-align: left;
9999
}
100100

101-
tr:nth-child(odd) {
101+
tr.hidden {
102+
display: none;
103+
}
104+
105+
:nth-child(odd of tr:not(.hidden)) {
102106
background: #383838;
103107
}
104-
tr:nth-child(even) {
108+
:nth-child(even of tr:not(.hidden)) {
105109
background: #2a2a2a;
106110
}
107111

template.html

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ <h1>Portal 2 Rules</h1>
2323

2424
<script src="scroll.js"></script>
2525
<script src="mobile-menu.js"></script>
26+
<script src="command-table.js"></script>
2627
</html>

0 commit comments

Comments
 (0)