Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/home/UseElixirFor.astro
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,9 @@ const starConfig = JSON.stringify(
const activeStar = stars[catId] ?? "#746284";

tabs.forEach((t) => {
const match = t.getAttribute("data-tab") === catId;
const match = t.dataset.tab === catId;
if (match) {
t.setAttribute("data-active", "");
t.dataset.active = "";
t.setAttribute("aria-pressed", "true");
} else {
t.removeAttribute("data-active");
Expand All @@ -743,7 +743,7 @@ const starConfig = JSON.stringify(
});

cards.forEach((c, i) => {
if (i === activeRow) c.setAttribute("data-active", "");
if (i === activeRow) c.dataset.active = "";
else c.removeAttribute("data-active");
const starPaths = c.querySelectorAll("[data-star] path");
starPaths.forEach((path) => {
Expand All @@ -754,7 +754,7 @@ const starConfig = JSON.stringify(
panels.forEach((p) => {
const panel = p.querySelector("[data-panel-cat]");
if (!panel) return;
const match = panel.getAttribute("data-panel-cat") === catId;
const match = panel.dataset.panelCat === catId;
panel.toggleAttribute("data-active", match);
panel.setAttribute("aria-hidden", match ? "false" : "true");
});
Expand All @@ -774,7 +774,7 @@ const starConfig = JSON.stringify(

tabs.forEach((t) => {
t.addEventListener("click", () => {
const cat = t.getAttribute("data-tab");
const cat = t.dataset.tab;
if (!cat) return;
suppressSpyUntil = performance.now() + 1000;
setActive(cat);
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/FilteredListing.astro
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const config = JSON.stringify({
};

connectedCallback() {
const raw = this.getAttribute("data-config");
const raw = this.dataset.config;
if (!raw) return;
this.config = JSON.parse(raw) as Config;
this.activeTab = this.config.defaultTab;
Expand Down Expand Up @@ -176,14 +176,14 @@ const config = JSON.stringify({

private refreshChildren() {
if (this.tabFilter) {
this.tabFilter.setAttribute("data-active", this.activeTab);
this.tabFilter.dataset.active = this.activeTab;
}
if (this.pagination) {
this.pagination.setAttribute(
"data-total",
String(this.totalPages(this.activeTab)),
);
this.pagination.setAttribute("data-page", String(this.activePage));
this.pagination.dataset.page = String(this.activePage);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/ui/Pagination.astro
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ const {
}

private getTotalPages(): number {
const n = Number(this.getAttribute("data-total") ?? 1);
return Number.isFinite(n) && n > 0 ? n : 1;
const n = Number(this.dataset.total ?? 1);
return Number.isInteger(n) && n > 0 ? n : 1;
}

private getActivePage(): number {
const n = Number(this.getAttribute("data-page") ?? 1);
return Number.isFinite(n) && n > 0 ? n : 1;
const n = Number(this.dataset.page ?? 1);
return Number.isInteger(n) && n > 0 ? n : 1;
}

private dispatchPageChange(page: number) {
Expand Down
13 changes: 6 additions & 7 deletions src/components/ui/TabFilter.astro
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ const {
this.querySelectorAll<HTMLButtonElement>("button[data-id]").forEach(
(btn) => {
btn.addEventListener("click", () => {
const id = btn.getAttribute("data-id");
if (!id || id === this.getAttribute("data-active")) return;
this.setAttribute("data-active", id);
const id = btn.dataset.id;
if (!id || id === this.dataset.active) return;
this.dataset.active = id;
this.dispatchEvent(
new CustomEvent("change", {
detail: { id },
Expand All @@ -121,12 +121,11 @@ const {
}

private syncActiveStyling() {
const active = this.getAttribute("data-active");
const active = this.dataset.active;
this.querySelectorAll<HTMLButtonElement>("button[data-id]").forEach(
(btn) => {
const match = btn.getAttribute("data-id") === active;
if (match) btn.setAttribute("data-active", "");
else btn.removeAttribute("data-active");
const match = btn.dataset.id === active;
btn.toggleAttribute("data-active", match);
btn.setAttribute("aria-selected", match ? "true" : "false");
},
);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/blog/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const seo = {

const posts = root.querySelectorAll("[data-post]");
const emptyState = root.querySelector("[data-empty-state]");
const config = JSON.parse(root.getAttribute("data-config") || "{}");
const config = JSON.parse(root.dataset.config || "{}");
const pageSize = config.pageSize || 5;
const counts = config.counts || {};

Expand All @@ -153,7 +153,7 @@ const seo = {
const end = start + pageSize;
let matchIdx = 0;
posts.forEach((el) => {
const cat = el.getAttribute("data-category");
const cat = el.dataset.category;
const match = activeTab === "All" || cat === activeTab;
if (!match) {
el.classList.add("hidden");
Expand All @@ -162,7 +162,7 @@ const seo = {
const visible = matchIdx >= start && matchIdx < end;
el.classList.toggle("hidden", !visible);
if (!firstRender && visible && !el.hasAttribute("data-revealed")) {
el.setAttribute("data-revealed", "true");
el.dataset.revealed = "true";
}
matchIdx++;
});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/cases/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ const seo = {
if (!root) return;

const caseLists = root.querySelectorAll("[data-case-list]");
const config = JSON.parse(root.getAttribute("data-config") || "{}");
const config = JSON.parse(root.dataset.config || "{}");

function renderCases(activeTab) {
caseLists.forEach((list) => {
const match = list.getAttribute("data-category") === activeTab;
const match = list.dataset.category === activeTab;
list.classList.toggle("hidden", !match);
list.classList.toggle("grid", match);
});
Expand Down
6 changes: 3 additions & 3 deletions src/pages/install/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ const seo = {

function setActive(id) {
tabs.forEach((t) => {
const match = t.getAttribute("data-tab") === id;
const match = t.dataset.tab === id;
if (match) {
t.setAttribute("data-active", "");
t.dataset.active = "";
t.setAttribute("aria-pressed", "true");
} else {
t.removeAttribute("data-active");
Expand All @@ -298,7 +298,7 @@ const seo = {
let suppressSpyUntil = 0;
tabs.forEach((t) => {
t.addEventListener("click", () => {
const id = t.getAttribute("data-tab");
const id = t.dataset.tab;
if (!id) return;
suppressSpyUntil = performance.now() + 1000;
setActive(id);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/learning/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const seo = {
const resources = root.querySelectorAll("[data-resource]");
const bookHeadings = root.querySelectorAll("[data-book-heading]");
const emptyState = root.querySelector("[data-empty-state]");
const config = JSON.parse(root.getAttribute("data-config") || "{}");
const config = JSON.parse(root.dataset.config || "{}");
const counts = config.counts || {};

let firstRender = true;
Expand All @@ -266,7 +266,7 @@ const seo = {
heading.classList.toggle("hidden", activeTab !== "books");
});
resources.forEach((el) => {
const category = el.getAttribute("data-category");
const category = el.dataset.category;
const match =
category === activeTab ||
(activeTab === "books" && category === "in-depth-books");
Expand All @@ -277,7 +277,7 @@ const seo = {
}
el.classList.remove("hidden");
if (!firstRender && !el.hasAttribute("data-revealed")) {
el.setAttribute("data-revealed", "true");
el.dataset.revealed = "true";
}
el.classList.toggle("xl:flex-row-reverse", matchIdx % 2 === 1);
matchIdx++;
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/reveal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (document.readyState === "loading") {
}

document.addEventListener("astro:before-swap", () => {
document.documentElement.setAttribute("data-spa-nav", "");
document.documentElement.dataset.spaNav = "";
});

document.addEventListener("astro:page-load", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function visiblePosts(page: Page) {
/** Assert every visible post belongs to `category`. */
async function expectAllVisibleInCategory(page: Page, category: string) {
const cats = await visiblePosts(page).evaluateAll((els) =>
els.map((e) => e.getAttribute("data-category")),
els.map((e) => e.dataset.category),
);
expect(cats.length).toBeGreaterThan(0);
for (const c of cats) expect(c).toBe(category);
Expand Down Expand Up @@ -137,7 +137,7 @@ test.describe("Learning filtering", () => {
).toBeVisible();
const cats = await page
.locator("[data-resource]:not(.hidden)")
.evaluateAll((els) => els.map((e) => e.getAttribute("data-category")));
.evaluateAll((els) => els.map((e) => e.dataset.category));
expect(cats.length).toBeGreaterThan(0);
for (const c of cats) expect(c).toBe("courses");
});
Expand Down
Loading