Add code to auto select tabs

This commit is contained in:
2025-01-11 13:03:27 -05:00
parent a8cd90c349
commit b5e0061247
4 changed files with 52 additions and 1 deletions

View File

@@ -2,6 +2,13 @@
<html>
<head>
<title>Pattern</title>
<script>
let u = document.location.href.substring(0, document.location.href.search(/patterns/i));
let p = document.location.pathname.substring(document.location.pathname.search(/patterns/i));
p = p.replace(/\/$|\/index\.html/i, "").substring(9);
window.location = u + "?p=" + p;
</script>
</head>
<body data-prismjs-copy-timeout="1500">
<h2>What is it</h2>
@@ -170,6 +177,7 @@ const click = new MouseEvent('click', {
});
export function init(p = document, s = true) {
p.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (tabGroup.querySelector("[role=tablist]") === null) {
@@ -222,6 +230,10 @@ export function init(p = document, s = true) {
})
});
}
if (document.location.hash != "" && document.location.hash.substring(0,5) == "#tab-") {
document.querySelector(document.location.hash).dispatchEvent(click);
}
});
}
</pre>