Skip to content

Commit 81faff1

Browse files
committed
Add inline links to global and per-site exception sections.
1 parent 372e6cb commit 81faff1

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/app.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,29 @@ export class App extends LitElement {
227227
return new Set(this.records.flatMap((record) => record.bugIds || [])).size;
228228
}
229229

230+
/**
231+
* Handle anchor navigation. We need to do this via JS because native navigation
232+
* does not traverse shadow DOM.
233+
* @param event The event object.
234+
*/
235+
private handleAnchorNavigation(event: Event) {
236+
event.preventDefault();
237+
if (!(event.target instanceof HTMLAnchorElement)) {
238+
return;
239+
}
240+
241+
let target = event.target as HTMLAnchorElement;
242+
243+
if (!target.hash.startsWith("#")) {
244+
return;
245+
}
246+
247+
const element = this.shadowRoot?.querySelector(target.hash);
248+
if (element) {
249+
element.scrollIntoView({ behavior: "smooth" });
250+
}
251+
}
252+
230253
/**
231254
* Renders the main content of the app which is dependent on the fetched records.
232255
* @returns The main content.
@@ -246,9 +269,11 @@ export class App extends LitElement {
246269
return html`
247270
<p>
248271
There are currently a total of ${this.records.length} exceptions on record.
249-
${this.records.filter((e) => !e.topLevelUrlPattern?.length).length} global exceptions and
250-
${this.records.filter((e) => e.topLevelUrlPattern?.length).length} per-site exceptions.
251-
${this.records.filter((e) => e.category === "baseline").length} of them are baseline
272+
${this.records.filter((e) => !e.topLevelUrlPattern?.length).length}
273+
<a href="#global-exceptions" @click=${this.handleAnchorNavigation}>global exceptions</a> and
274+
${this.records.filter((e) => e.topLevelUrlPattern?.length).length}
275+
<a href="#per-site-exceptions" @click=${this.handleAnchorNavigation}>per-site exceptions</a
276+
>. ${this.records.filter((e) => e.category === "baseline").length} of them are baseline
252277
exceptions and ${this.records.filter((e) => e.category === "convenience").length}
253278
convenience exceptions.
254279
</p>
@@ -258,7 +283,7 @@ export class App extends LitElement {
258283
</p>
259284
260285
<section style="z-index: 10;">
261-
<h2 style="z-index: 20;">Global Exceptions</h2>
286+
<h2 id="global-exceptions" style="z-index: 20;">Global Exceptions</h2>
262287
<p>
263288
Global exceptions are applied for sub-resources across all top level sites. They are
264289
applied when blocking a resource breaks many sites.
@@ -284,7 +309,7 @@ export class App extends LitElement {
284309
</section>
285310
286311
<section style="z-index: 50;">
287-
<h2 style="z-index: 60;">Per-Site Exceptions</h2>
312+
<h2 id="per-site-exceptions" style="z-index: 60;">Per-Site Exceptions</h2>
288313
<p>
289314
Per-site exceptions are applied for sub-resources on a specific top level site. They are
290315
applied for site specific breakage.

0 commit comments

Comments
 (0)