Skip to content

Commit 24c60ba

Browse files
committed
chore: Add window for addEventListener
1 parent 749e9dc commit 24c60ba

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/assets/js/search.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
$(() => {
2-
const searchForm = document.getElementById("search-form")
3-
const searchValue = (new URLSearchParams(location.search)).get("q")
2+
const searchForm = document.getElementById("search-form");
3+
const searchValue = new URLSearchParams(location.search).get("q");
44

55
if (searchValue) {
6-
searchForm.value = searchValue
6+
searchForm.value = searchValue;
77
}
88

9-
addEventListener("keydown", (e) => {
9+
window.addEventListener("keydown", (e) => {
1010
switch (e.key) {
11-
case '/':
12-
if (document.activeElement === searchForm) break
11+
case "/":
12+
if (document.activeElement === searchForm) break;
1313

14-
e.preventDefault()
15-
searchForm.focus()
16-
break
17-
case 'Escape':
14+
e.preventDefault();
15+
searchForm.focus();
16+
break;
17+
case "Escape":
1818
if (document.activeElement === searchForm) {
19-
searchForm.blur()
19+
searchForm.blur();
2020
}
21-
break
21+
break;
2222
}
23-
})
23+
});
2424
});

0 commit comments

Comments
 (0)