Skip to content

Commit 20bffbb

Browse files
authored
chore: Address TiCS coding standards warnings for public JS (#5106)
1 parent 5573f80 commit 20bffbb

3 files changed

Lines changed: 28 additions & 20 deletions

File tree

static/js/base/ga.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if (typeof window.dataLayer !== "undefined") {
5858
return;
5959
}
6060

61-
target = eventTarget.closest("a")!;
61+
target = eventTarget.closest("a") as HTMLAnchorElement;
6262

6363
if (!target) {
6464
target = eventTarget.closest("button")!;

static/js/public/scroll-to.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export function animateScrollTo(to: string | number | HTMLElement, offset = 0) {
2-
const element = (document.scrollingElement as HTMLElement) || window;
1+
export function animateScrollTo(
2+
to: HTMLElement | number | string,
3+
offset = 0,
4+
): void {
5+
const element = document.scrollingElement!;
36

47
if (typeof to === "string") {
58
to = document.querySelector(to) as HTMLElement;
@@ -12,14 +15,13 @@ export function animateScrollTo(to: string | number | HTMLElement, offset = 0) {
1215
}
1316
to = to - offset;
1417

15-
if (element.scrollTo) {
16-
element.scrollTo({ top: to, left: 0, behavior: "smooth" });
17-
} else {
18-
element.scrollTop = to;
19-
}
18+
element.scrollTo({ top: to, left: 0, behavior: "smooth" });
2019
}
2120

22-
export function initLinkScroll(link: HTMLLinkElement, { offset = 0 }) {
21+
export function initLinkScroll(
22+
link: HTMLLinkElement,
23+
{ offset = 0 }: { offset: number },
24+
): void {
2325
if (link && (link.dataset.scrollTo || link.href)) {
2426
const href =
2527
(link.dataset.scrollTo as string) ||
@@ -29,7 +31,9 @@ export function initLinkScroll(link: HTMLLinkElement, { offset = 0 }) {
2931
link.addEventListener("click", (event) => {
3032
event.preventDefault();
3133
animateScrollTo(target, offset);
32-
setTimeout(() => window.history.pushState({}, "", href), 100);
34+
setTimeout(() => {
35+
window.history.pushState({}, "", href);
36+
}, 100);
3337
});
3438
}
3539
}

static/js/public/snap-details/embeddedCard.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { initEmbeddedCardPicker } from "./publicise";
22

3-
const showEl = (el: { classList: { remove: (arg0: string) => void } }) =>
3+
const showEl = (el: {
4+
classList: { remove: (arg0: string) => void };
5+
}): void => {
46
el.classList.remove("u-hide");
5-
const hideEl = (el: { classList: { add: (arg0: string) => void } }) =>
7+
};
8+
const hideEl = (el: { classList: { add: (arg0: string) => void } }): void => {
69
el.classList.add("u-hide");
10+
};
711

812
function toggleModal(
913
modal: HTMLElement,
10-
show?: boolean | undefined,
11-
initCallback?: { (): void; (): void } | undefined,
12-
) {
14+
show?: boolean,
15+
initCallback?: { (): void; (): void },
16+
): void {
1317
if (typeof show === "undefined") {
1418
show = modal.classList.contains("u-hide");
1519
}
@@ -39,7 +43,7 @@ export default function initEmbeddedCardModal(snapName: string): void {
3943
const buttonRadios = modal.querySelectorAll("input[name=store-button]");
4044
const optionButtons = modal.querySelectorAll("input[type=checkbox]");
4145

42-
function updateHeightCallback() {
46+
function updateHeightCallback(): void {
4347
// adjust the height of the modal to size of the frame
4448
dialog.style.minHeight = "";
4549

@@ -48,10 +52,6 @@ export default function initEmbeddedCardModal(snapName: string): void {
4852
}, 1);
4953
}
5054

51-
function initFrame() {
52-
renderCard();
53-
}
54-
5555
const renderCard = initEmbeddedCardPicker({
5656
snapName,
5757
previewFrame,
@@ -61,6 +61,10 @@ export default function initEmbeddedCardModal(snapName: string): void {
6161
updateHeightCallback,
6262
});
6363

64+
function initFrame(): void {
65+
renderCard();
66+
}
67+
6468
toggle.addEventListener("click", (event) => {
6569
event.preventDefault();
6670
toggleModal(modal, true, initFrame);

0 commit comments

Comments
 (0)