Skip to content

Commit

Permalink
fix: remove unnecessary DOMContentLoaded listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherry committed Sep 14, 2024
1 parent 8ccb6d7 commit 95df3c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/components/overrides/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ if (Astro.props.entry.data.external_link) {
<script>
import littlefoot from "littlefoot";

document.addEventListener("DOMContentLoaded", () => {
littlefoot();
document
.querySelectorAll("span.littlefoot")
.forEach((x) => x.classList.add("not-content"));
});
littlefoot();
document
.querySelectorAll("span.littlefoot")
.forEach((x) => x.classList.add("not-content"));
</script>
<script>
import mermaid from "mermaid";
Expand Down
18 changes: 8 additions & 10 deletions src/pages/changelog/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,15 @@ const { products, productAreas, changelogs } = await getChangelogs();
<script>
import StickyHeader from "@codingheads/sticky-header";

document.addEventListener("DOMContentLoaded", () => {
const navHeightRem = getComputedStyle(document.body).getPropertyValue(
"--sl-nav-height",
);
const navHeightPx = Number(navHeightRem.split("rem")[0]) * 16 + 16;
const navHeightRem = getComputedStyle(document.body).getPropertyValue(
"--sl-nav-height",
);
const navHeightPx = Number(navHeightRem.split("rem")[0]) * 16 + 16;

const headers = document.querySelectorAll<HTMLElement>("[data-date] > h2");
headers.forEach(
(header) => new StickyHeader(header, { offset: 0 - navHeightPx }),
);
});
const headers = document.querySelectorAll<HTMLElement>("[data-date] > h2");
headers.forEach(
(header) => new StickyHeader(header, { offset: 0 - navHeightPx }),
);

const productFilter = document.querySelector<HTMLSelectElement>("#products");
productFilter?.addEventListener("change", filterEntries);
Expand Down
7 changes: 3 additions & 4 deletions src/pages/products.astro
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const groups = productGroups(products);
input.addEventListener("change", filterProducts);
});

document.addEventListener("DOMContentLoaded", () => {
function initProducts() {
const params = new URLSearchParams(window.location.search);

const groups = params.get("product-group");
Expand All @@ -170,13 +170,12 @@ const groups = productGroups(products);
if (!filters) return;

for (const filter of filters) {
console.log(groups);
console.log(filter.id);
if (groups.includes(filter.id)) {
filter.checked = true;
}
}

filterProducts();
});
}
initProducts();
</script>

0 comments on commit 95df3c4

Please sign in to comment.