Skip to content

Commit d6a6dad

Browse files
authored
refactor: replace jQuery with DOM utils in caps lock warning (@MoushufAlam) (monkeytypegame#7265)
### Description Replaces jQuery usage with DOM utils for the caps lock warning. Scope intentionally kept small per contributing guidelines. ### Checks - [x] Adding/modifying Typescript code? - [x] I have used `qs`, `qsa` or `qsr` instead of JQuery selectors. - [x] Check if any open issues are related to this PR; if so, be sure to tag them below. - [x] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [x] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. <!-- label(optional scope): pull request title (@your_github_username) --> <!-- I know I know they seem boring but please do them, they help us and you will find out it also helps you.--> Related to monkeytypegame#7186 <!-- the issue(s) your PR resolves if any (delete if that is not the case) --> <!-- please also reference any issues and or PRs related to your pull request --> <!-- Also remove it if you are not following any issues. --> <!-- pro tip: you can mention an issue, PR, or discussion on GitHub by referencing its hash number e.g: [monkeytypegame#1234](monkeytypegame#1234) --> <!-- pro tip: you can press . (dot or period) in the code tab of any GitHub repo to get access to GitHub's VS Code web editor Enjoy! :) -->
1 parent c222098 commit d6a6dad

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import Config from "../config";
22
import * as Misc from "../utils/misc";
3+
import { qsr } from "../utils/dom";
34

4-
const el = document.querySelector("#capsWarning") as HTMLElement;
5+
const el = qsr("#capsWarning");
56

67
export let capsState = false;
78

89
let visible = false;
910

1011
function show(): void {
1112
if (!visible) {
12-
el?.classList.remove("hidden");
13+
el.removeClass("hidden");
1314
visible = true;
1415
}
1516
}
1617

1718
function hide(): void {
1819
if (visible) {
19-
el?.classList.add("hidden");
20+
el.addClass("hidden");
2021
visible = false;
2122
}
2223
}
2324

24-
function update(event: JQuery.KeyDownEvent | JQuery.KeyUpEvent): void {
25-
if (event?.originalEvent?.key === "CapsLock" && capsState !== null) {
25+
function update(event: KeyboardEvent): void {
26+
if (event.key === "CapsLock" && capsState !== null) {
2627
capsState = !capsState;
2728
} else {
28-
const modState = event?.originalEvent?.getModifierState?.("CapsLock");
29+
const modState = event.getModifierState?.("CapsLock");
2930
if (modState !== undefined) {
3031
capsState = modState;
3132
}
@@ -40,8 +41,8 @@ function update(event: JQuery.KeyDownEvent | JQuery.KeyUpEvent): void {
4041
} catch {}
4142
}
4243

43-
$(document).on("keyup", update);
44+
document.addEventListener("keyup", update);
4445

45-
$(document).on("keydown", (event) => {
46+
document.addEventListener("keydown", (event) => {
4647
if (Misc.isMac()) update(event);
4748
});

0 commit comments

Comments
 (0)