Base: Support opening a specific settings tab via anchors

For example, about:settings#privacy will now open the settings page to
the Privacy tab.
This commit is contained in:
Timothy Flynn
2026-03-04 12:06:59 -05:00
committed by Tim Flynn
parent 57f7f22e91
commit 746448f8e0
Notes: github-actions[bot] 2026-03-05 15:02:48 +00:00

View File

@@ -696,16 +696,32 @@
<script src="resource://ladybird/about-pages/settings/search.js" type="module"></script>
<script type="module">
function switchTab(name) {
const button = document.querySelector(`.tab-button[data-tab="${name}"]`);
const panel = document.getElementById(`tab-${name}`);
if (!button || !panel) {
return;
}
document.querySelectorAll(".tab-button").forEach(b => b.classList.remove("active"));
document.querySelectorAll(".tab-panel").forEach(p => p.classList.remove("active"));
button.classList.add("active");
panel.classList.add("active");
}
document.querySelectorAll(".tab-button").forEach(button => {
button.addEventListener("click", () => {
document.querySelectorAll(".tab-button").forEach(b => b.classList.remove("active"));
document.querySelectorAll(".tab-panel").forEach(p => p.classList.remove("active"));
button.classList.add("active");
document.getElementById(`tab-${button.dataset.tab}`).classList.add("active");
switchTab(button.dataset.tab);
history.replaceState(null, "", `#${button.dataset.tab}`);
});
});
const hash = location.hash.slice(1);
if (hash) {
switchTab(hash);
}
document.querySelectorAll("dialog").forEach(dialog => {
dialog.addEventListener("click", event => {
const rect = dialog.getBoundingClientRect();