Skip to content

Commit

Permalink
Update document title (WebKit#354)
Browse files Browse the repository at this point in the history
Use a "data-title" attribute for each section to update document.title.
  • Loading branch information
camillobruni authored Jan 25, 2024
1 parent b0a465d commit 638a968
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</div>
</section>

<section id="summary">
<section id="summary" data-title="Results Summary">
<a href="#home" class="logo">
<img srcset="resources/logo@2x.png 2x" src="resources/logo.png" alt="Speedometer" />
<div class="version">3.0</div>
Expand All @@ -69,7 +69,7 @@ <h1>Score</h1>
</div>
</section>

<section id="details">
<section id="details" data-title="Results Details">
<a href="#home" class="logo">
<img srcset="resources/logo@2x.png 2x" src="resources/logo.png" alt="Speedometer" />
<div class="version">3.0</div>
Expand Down Expand Up @@ -103,7 +103,7 @@ <h2>Detailed Metrics</h2>
</div>
</section>

<section id="about">
<section id="about" data-title="About">
<a href="#home" class="logo">
<img srcset="resources/logo@2x.png 2x" src="resources/logo.png" alt="Speedometer" />
<div class="version">3.0</div>
Expand Down
8 changes: 8 additions & 0 deletions resources/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,18 @@ class MainBenchmarkClient {
if (hash === "#home" || hash === "") {
if (window.location.hash !== hash)
window.location.hash = "#home";
hash = "#home";
this._removeLocationHash();
} else {
window.location.hash = hash;
}
this._updateDocumentTitle(hash);
}

_updateDocumentTitle(hash) {
const maybeSection = document.querySelector(hash);
const sectionTitle = maybeSection?.getAttribute("data-title") ?? "";
document.title = `Speedometer 3 ${sectionTitle}`.trimEnd();
}

_removeLocationHash() {
Expand Down

0 comments on commit 638a968

Please sign in to comment.