Skip to content

Commit f69783a

Browse files
committed
Update gensurvpy Sphinx documentation
1 parent a1cd27c commit f69783a

25 files changed

+220
-72
lines changed
42 Bytes
Binary file not shown.
Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,101 @@
1-
var sd_labels_by_text = {};
1+
// @ts-check
22

3+
// Extra JS capability for selected tabs to be synced
4+
// The selection is stored in local storage so that it persists across page loads.
5+
6+
/**
7+
* @type {Record<string, HTMLElement[]>}
8+
*/
9+
let sd_id_to_elements = {};
10+
const storageKeyPrefix = "sphinx-design-tab-id-";
11+
12+
/**
13+
* Create a key for a tab element.
14+
* @param {HTMLElement} el - The tab element.
15+
* @returns {[string, string, string] | null} - The key.
16+
*
17+
*/
18+
function create_key(el) {
19+
let syncId = el.getAttribute("data-sync-id");
20+
let syncGroup = el.getAttribute("data-sync-group");
21+
if (!syncId || !syncGroup) return null;
22+
return [syncGroup, syncId, syncGroup + "--" + syncId];
23+
}
24+
25+
/**
26+
* Initialize the tab selection.
27+
*
28+
*/
329
function ready() {
4-
const li = document.getElementsByClassName("sd-tab-label");
5-
for (const label of li) {
6-
syncId = label.getAttribute("data-sync-id");
7-
if (syncId) {
8-
label.onclick = onLabelClick;
9-
if (!sd_labels_by_text[syncId]) {
10-
sd_labels_by_text[syncId] = [];
30+
// Find all tabs with sync data
31+
32+
/** @type {string[]} */
33+
let groups = [];
34+
35+
document.querySelectorAll(".sd-tab-label").forEach((label) => {
36+
if (label instanceof HTMLElement) {
37+
let data = create_key(label);
38+
if (data) {
39+
let [group, id, key] = data;
40+
41+
// add click event listener
42+
// @ts-ignore
43+
label.onclick = onSDLabelClick;
44+
45+
// store map of key to elements
46+
if (!sd_id_to_elements[key]) {
47+
sd_id_to_elements[key] = [];
48+
}
49+
sd_id_to_elements[key].push(label);
50+
51+
if (groups.indexOf(group) === -1) {
52+
groups.push(group);
53+
// Check if a specific tab has been selected via URL parameter
54+
const tabParam = new URLSearchParams(window.location.search).get(
55+
group
56+
);
57+
if (tabParam) {
58+
console.log(
59+
"sphinx-design: Selecting tab id for group '" +
60+
group +
61+
"' from URL parameter: " +
62+
tabParam
63+
);
64+
window.sessionStorage.setItem(storageKeyPrefix + group, tabParam);
65+
}
66+
}
67+
68+
// Check is a specific tab has been selected previously
69+
let previousId = window.sessionStorage.getItem(
70+
storageKeyPrefix + group
71+
);
72+
if (previousId === id) {
73+
// console.log(
74+
// "sphinx-design: Selecting tab from session storage: " + id
75+
// );
76+
// @ts-ignore
77+
label.previousElementSibling.checked = true;
78+
}
1179
}
12-
sd_labels_by_text[syncId].push(label);
1380
}
14-
}
81+
});
1582
}
1683

17-
function onLabelClick() {
18-
// Activate other inputs with the same sync id.
19-
syncId = this.getAttribute("data-sync-id");
20-
for (label of sd_labels_by_text[syncId]) {
84+
/**
85+
* Activate other tabs with the same sync id.
86+
*
87+
* @this {HTMLElement} - The element that was clicked.
88+
*/
89+
function onSDLabelClick() {
90+
let data = create_key(this);
91+
if (!data) return;
92+
let [group, id, key] = data;
93+
for (const label of sd_id_to_elements[key]) {
2194
if (label === this) continue;
95+
// @ts-ignore
2296
label.previousElementSibling.checked = true;
2397
}
24-
window.localStorage.setItem("sphinx-design-last-tab", syncId);
98+
window.sessionStorage.setItem(storageKeyPrefix + group, id);
2599
}
26100

27101
document.addEventListener("DOMContentLoaded", ready, false);
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,101 @@
1-
var sd_labels_by_text = {};
1+
// @ts-check
22

3+
// Extra JS capability for selected tabs to be synced
4+
// The selection is stored in local storage so that it persists across page loads.
5+
6+
/**
7+
* @type {Record<string, HTMLElement[]>}
8+
*/
9+
let sd_id_to_elements = {};
10+
const storageKeyPrefix = "sphinx-design-tab-id-";
11+
12+
/**
13+
* Create a key for a tab element.
14+
* @param {HTMLElement} el - The tab element.
15+
* @returns {[string, string, string] | null} - The key.
16+
*
17+
*/
18+
function create_key(el) {
19+
let syncId = el.getAttribute("data-sync-id");
20+
let syncGroup = el.getAttribute("data-sync-group");
21+
if (!syncId || !syncGroup) return null;
22+
return [syncGroup, syncId, syncGroup + "--" + syncId];
23+
}
24+
25+
/**
26+
* Initialize the tab selection.
27+
*
28+
*/
329
function ready() {
4-
const li = document.getElementsByClassName("sd-tab-label");
5-
for (const label of li) {
6-
syncId = label.getAttribute("data-sync-id");
7-
if (syncId) {
8-
label.onclick = onLabelClick;
9-
if (!sd_labels_by_text[syncId]) {
10-
sd_labels_by_text[syncId] = [];
30+
// Find all tabs with sync data
31+
32+
/** @type {string[]} */
33+
let groups = [];
34+
35+
document.querySelectorAll(".sd-tab-label").forEach((label) => {
36+
if (label instanceof HTMLElement) {
37+
let data = create_key(label);
38+
if (data) {
39+
let [group, id, key] = data;
40+
41+
// add click event listener
42+
// @ts-ignore
43+
label.onclick = onSDLabelClick;
44+
45+
// store map of key to elements
46+
if (!sd_id_to_elements[key]) {
47+
sd_id_to_elements[key] = [];
48+
}
49+
sd_id_to_elements[key].push(label);
50+
51+
if (groups.indexOf(group) === -1) {
52+
groups.push(group);
53+
// Check if a specific tab has been selected via URL parameter
54+
const tabParam = new URLSearchParams(window.location.search).get(
55+
group
56+
);
57+
if (tabParam) {
58+
console.log(
59+
"sphinx-design: Selecting tab id for group '" +
60+
group +
61+
"' from URL parameter: " +
62+
tabParam
63+
);
64+
window.sessionStorage.setItem(storageKeyPrefix + group, tabParam);
65+
}
66+
}
67+
68+
// Check is a specific tab has been selected previously
69+
let previousId = window.sessionStorage.getItem(
70+
storageKeyPrefix + group
71+
);
72+
if (previousId === id) {
73+
// console.log(
74+
// "sphinx-design: Selecting tab from session storage: " + id
75+
// );
76+
// @ts-ignore
77+
label.previousElementSibling.checked = true;
78+
}
1179
}
12-
sd_labels_by_text[syncId].push(label);
1380
}
14-
}
81+
});
1582
}
1683

17-
function onLabelClick() {
18-
// Activate other inputs with the same sync id.
19-
syncId = this.getAttribute("data-sync-id");
20-
for (label of sd_labels_by_text[syncId]) {
84+
/**
85+
* Activate other tabs with the same sync id.
86+
*
87+
* @this {HTMLElement} - The element that was clicked.
88+
*/
89+
function onSDLabelClick() {
90+
let data = create_key(this);
91+
if (!data) return;
92+
let [group, id, key] = data;
93+
for (const label of sd_id_to_elements[key]) {
2194
if (label === this) continue;
95+
// @ts-ignore
2296
label.previousElementSibling.checked = true;
2397
}
24-
window.localStorage.setItem("sphinx-design-last-tab", syncId);
98+
window.sessionStorage.setItem(storageKeyPrefix + group, id);
2599
}
26100

27101
document.addEventListener("DOMContentLoaded", ready, false);
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/gensurvpy/algorithms.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
99
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
1010
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
11-
<link rel="stylesheet" href="_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" type="text/css" />
11+
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
1212
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
1313
<link rel="canonical" href="https://diogoribeiro7.github.io/packages/gensurvpy/algorithms.html" />
1414
<!--[if lt IE 9]>
@@ -22,7 +22,7 @@
2222
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
2323
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
2424
<script src="_static/copybutton.js?v=30646c52"></script>
25-
<script src="_static/design-tabs.js?v=36754332"></script>
25+
<script src="_static/design-tabs.js?v=f930bc37"></script>
2626
<script src="_static/js/theme.js"></script>
2727
<link rel="index" title="Index" href="genindex.html" />
2828
<link rel="search" title="Search" href="search.html" />

packages/gensurvpy/api/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
99
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
1010
<link rel="stylesheet" href="../_static/copybutton.css" type="text/css" />
11-
<link rel="stylesheet" href="../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" type="text/css" />
11+
<link rel="stylesheet" href="../_static/sphinx-design.min.css" type="text/css" />
1212
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
1313
<link rel="canonical" href="https://diogoribeiro7.github.io/packages/gensurvpy/api/index.html" />
1414
<!--[if lt IE 9]>
@@ -22,7 +22,7 @@
2222
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
2323
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
2424
<script src="../_static/copybutton.js?v=30646c52"></script>
25-
<script src="../_static/design-tabs.js?v=36754332"></script>
25+
<script src="../_static/design-tabs.js?v=f930bc37"></script>
2626
<script src="../_static/js/theme.js"></script>
2727
<link rel="index" title="Index" href="../genindex.html" />
2828
<link rel="search" title="Search" href="../search.html" />

packages/gensurvpy/bibliography.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
99
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
1010
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
11-
<link rel="stylesheet" href="_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" type="text/css" />
11+
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
1212
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
1313
<link rel="canonical" href="https://diogoribeiro7.github.io/packages/gensurvpy/bibliography.html" />
1414
<!--[if lt IE 9]>
@@ -22,7 +22,7 @@
2222
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
2323
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
2424
<script src="_static/copybutton.js?v=30646c52"></script>
25-
<script src="_static/design-tabs.js?v=36754332"></script>
25+
<script src="_static/design-tabs.js?v=f930bc37"></script>
2626
<script src="_static/js/theme.js"></script>
2727
<link rel="index" title="Index" href="genindex.html" />
2828
<link rel="search" title="Search" href="search.html" />

packages/gensurvpy/changelog.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
99
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
1010
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
11-
<link rel="stylesheet" href="_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" type="text/css" />
11+
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
1212
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
1313
<link rel="canonical" href="https://diogoribeiro7.github.io/packages/gensurvpy/changelog.html" />
1414
<!--[if lt IE 9]>
@@ -22,7 +22,7 @@
2222
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
2323
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
2424
<script src="_static/copybutton.js?v=30646c52"></script>
25-
<script src="_static/design-tabs.js?v=36754332"></script>
25+
<script src="_static/design-tabs.js?v=f930bc37"></script>
2626
<script src="_static/js/theme.js"></script>
2727
<link rel="index" title="Index" href="genindex.html" />
2828
<link rel="search" title="Search" href="search.html" />

packages/gensurvpy/contributing.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
99
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
1010
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
11-
<link rel="stylesheet" href="_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" type="text/css" />
11+
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
1212
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
1313
<link rel="canonical" href="https://diogoribeiro7.github.io/packages/gensurvpy/contributing.html" />
1414
<!--[if lt IE 9]>
@@ -22,7 +22,7 @@
2222
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
2323
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
2424
<script src="_static/copybutton.js?v=30646c52"></script>
25-
<script src="_static/design-tabs.js?v=36754332"></script>
25+
<script src="_static/design-tabs.js?v=f930bc37"></script>
2626
<script src="_static/js/theme.js"></script>
2727
<link rel="index" title="Index" href="genindex.html" />
2828
<link rel="search" title="Search" href="search.html" />

0 commit comments

Comments
 (0)