Skip to content

Commit 97b9085

Browse files
authored
refactor: replace jquery with dom utils in scroll-to-top button (@MoushufAlam) (monkeytypegame#7257)
### Description Replaces jQuery usage with dom utils in the scroll-to-top button. 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 96169a1 commit 97b9085

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

frontend/src/ts/elements/scroll-to-top.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import * as ActivePage from "../states/active-page";
22
import { prefersReducedMotion } from "../utils/misc";
3+
import { qsr } from "../utils/dom";
34

45
let visible = false;
56

7+
const button = qsr(".scrollToTopButton");
8+
69
export function hide(): void {
7-
$(".scrollToTopButton").addClass("invisible");
10+
button.addClass("invisible");
811
visible = false;
912
}
1013

1114
function show(): void {
12-
$(".scrollToTopButton").removeClass("invisible");
15+
button.removeClass("invisible");
1316
visible = true;
1417
}
1518

16-
$(document).on("click", ".scrollToTopButton", () => {
17-
$(".scrollToTopButton").addClass("invisible");
19+
button.on("click", () => {
20+
button.addClass("invisible");
1821
window.scrollTo({
1922
top: 0,
2023
behavior: prefersReducedMotion() ? "instant" : "smooth",
2124
});
2225
});
2326

24-
$(window).on("scroll", () => {
27+
window.addEventListener("scroll", () => {
2528
const page = ActivePage.get();
2629
if (page === "test") return;
2730

0 commit comments

Comments
 (0)