Skip to content

Commit 045ffc2

Browse files
Make toggle button consistent across all subprojects
1 parent bbcc40e commit 045ffc2

File tree

9 files changed

+166
-167
lines changed

9 files changed

+166
-167
lines changed

docs/cbf/assets/js/width-toggle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
// Width toggle functionality
2-
document.addEventListener("DOMContentLoaded", function() {
2+
document.addEventListener("DOMContentLoaded", function () {
33
const toggleButton = document.getElementById("md-width-toggle");
44
const icons = window.__mdWidthIcons;
5-
5+
66
// Width modes cycle: slim -> wide -> full -> slim
77
const modes = ["slim", "wide", "full"];
8-
8+
99
function capitalize(str) {
1010
return str.charAt(0).toUpperCase() + str.slice(1);
1111
}
12-
12+
1313
function updateButton(mode) {
1414
toggleButton.innerHTML = mode === "full" ? icons.minimize : icons.maximize;
1515
const nextMode = modes[(modes.indexOf(mode) + 1) % modes.length];
1616
toggleButton.setAttribute("title", `Current: ${capitalize(mode)} - Click for ${capitalize(nextMode)}`);
1717
}
18-
18+
1919
function applyMode(mode) {
2020
if (mode === "slim") {
2121
document.documentElement.removeAttribute("data-md-width");
2222
} else {
2323
document.documentElement.setAttribute("data-md-width", mode);
2424
}
2525
}
26-
26+
2727
// Initialize button with saved preference
2828
const savedWidth = localStorage.getItem("md-width") || "slim";
2929
updateButton(savedWidth);
30-
30+
3131
// Toggle handler - cycle through modes
32-
toggleButton.addEventListener("click", function() {
32+
toggleButton.addEventListener("click", function () {
3333
const currentMode = localStorage.getItem("md-width") || "slim";
3434
const nextMode = modes[(modes.indexOf(currentMode) + 1) % modes.length];
35-
35+
3636
applyMode(nextMode);
3737
localStorage.setItem("md-width", nextMode);
3838
updateButton(nextMode);

docs/cbf/overrides/main.html

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
{% extends "base.html" %}
2-
{% endblock %}
3-
{{ super() }}
4-
</script>
5-
})();
6-
}
7-
}
8-
header.appendChild(btn);
9-
} else {
10-
searchButton.parentNode.insertBefore(btn, searchButton);
11-
if (searchButton) {
12-
|| header.querySelector("label.md-header__button");
13-
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
14-
if (header) {
15-
const header = document.querySelector(".md-header__inner");
16-
17-
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
18-
btn.setAttribute("aria-label", "Toggle page width");
19-
btn.className = "md-header__button md-width-toggle";
20-
btn.id = "md-width-toggle";
21-
const btn = document.createElement("button");
22-
const mode = window.__mdWidthMode || "slim";
232

24-
};
25-
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
26-
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
27-
window.__mdWidthIcons = {
28-
(function() {
29-
// Inject toggle button immediately when header is available
3+
{% block styles %}
304
<script>
31-
{% block content %}
32-
33-
{% endblock %}
34-
{{ super() }}
5+
(function () {
6+
const savedWidth = localStorage.getItem("md-width") || "slim";
7+
if (savedWidth === "wide" || savedWidth === "full") {
8+
document.documentElement.setAttribute("data-md-width", savedWidth);
9+
}
10+
// Store for width-toggle.js to use
11+
window.__mdWidthMode = savedWidth;
12+
})();
3513
</script>
36-
})();
37-
window.__mdWidthMode = savedWidth;
38-
// Store for width-toggle.js to use
39-
}
40-
document.documentElement.setAttribute("data-md-width", savedWidth);
41-
if (savedWidth === "wide" || savedWidth === "full") {
42-
const savedWidth = localStorage.getItem("md-width") || "slim";
43-
(function() {
14+
{{ super() }}
15+
{% endblock %}
16+
17+
{% block content %}
4418
<script>
45-
{% block styles %}
19+
// Inject toggle button immediately when header is available
20+
(function () {
21+
window.__mdWidthIcons = {
22+
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
23+
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
24+
};
4625

26+
const mode = window.__mdWidthMode || "slim";
27+
const btn = document.createElement("button");
28+
btn.id = "md-width-toggle";
29+
btn.className = "md-header__button md-width-toggle";
30+
btn.setAttribute("aria-label", "Toggle page width");
31+
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
32+
33+
const header = document.querySelector(".md-header__inner");
34+
if (header) {
35+
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
36+
|| header.querySelector("label.md-header__button");
37+
if (searchButton) {
38+
searchButton.parentNode.insertBefore(btn, searchButton);
39+
} else {
40+
header.appendChild(btn);
41+
}
42+
}
43+
})();
44+
</script>
45+
{{ super() }}
46+
{% endblock %}
4747

docs/invui/assets/js/width-toggle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
// Width toggle functionality
2-
document.addEventListener("DOMContentLoaded", function() {
2+
document.addEventListener("DOMContentLoaded", function () {
33
const toggleButton = document.getElementById("md-width-toggle");
44
const icons = window.__mdWidthIcons;
5-
5+
66
// Width modes cycle: slim -> wide -> full -> slim
77
const modes = ["slim", "wide", "full"];
8-
8+
99
function capitalize(str) {
1010
return str.charAt(0).toUpperCase() + str.slice(1);
1111
}
12-
12+
1313
function updateButton(mode) {
1414
toggleButton.innerHTML = mode === "full" ? icons.minimize : icons.maximize;
1515
const nextMode = modes[(modes.indexOf(mode) + 1) % modes.length];
1616
toggleButton.setAttribute("title", `Current: ${capitalize(mode)} - Click for ${capitalize(nextMode)}`);
1717
}
18-
18+
1919
function applyMode(mode) {
2020
if (mode === "slim") {
2121
document.documentElement.removeAttribute("data-md-width");
2222
} else {
2323
document.documentElement.setAttribute("data-md-width", mode);
2424
}
2525
}
26-
26+
2727
// Initialize button with saved preference
2828
const savedWidth = localStorage.getItem("md-width") || "slim";
2929
updateButton(savedWidth);
30-
30+
3131
// Toggle handler - cycle through modes
32-
toggleButton.addEventListener("click", function() {
32+
toggleButton.addEventListener("click", function () {
3333
const currentMode = localStorage.getItem("md-width") || "slim";
3434
const nextMode = modes[(modes.indexOf(currentMode) + 1) % modes.length];
35-
35+
3636
applyMode(nextMode);
3737
localStorage.setItem("md-width", nextMode);
3838
updateButton(nextMode);

docs/invui/assets/stylesheets/extra.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@
6161
display: none;
6262
}
6363
}
64-

docs/invui/overrides/main.html

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,45 @@
22

33
{% block styles %}
44
<script>
5-
(function() {
6-
const savedWidth = localStorage.getItem("md-width") || "slim";
7-
if (savedWidth === "wide" || savedWidth === "full") {
8-
document.documentElement.setAttribute("data-md-width", savedWidth);
9-
}
10-
// Store for width-toggle.js to use
11-
window.__mdWidthMode = savedWidth;
12-
})();
5+
(function () {
6+
const savedWidth = localStorage.getItem("md-width") || "slim";
7+
if (savedWidth === "wide" || savedWidth === "full") {
8+
document.documentElement.setAttribute("data-md-width", savedWidth);
9+
}
10+
// Store for width-toggle.js to use
11+
window.__mdWidthMode = savedWidth;
12+
})();
1313
</script>
1414
{{ super() }}
1515
{% endblock %}
1616

1717
{% block content %}
1818
<script>
19-
// Inject toggle button immediately when header is available
20-
(function() {
21-
window.__mdWidthIcons = {
22-
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
23-
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
24-
};
19+
// Inject toggle button immediately when header is available
20+
(function () {
21+
window.__mdWidthIcons = {
22+
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
23+
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
24+
};
2525

26-
const mode = window.__mdWidthMode || "slim";
27-
const btn = document.createElement("button");
28-
btn.id = "md-width-toggle";
29-
btn.className = "md-header__button md-width-toggle";
30-
btn.setAttribute("aria-label", "Toggle page width");
31-
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
26+
const mode = window.__mdWidthMode || "slim";
27+
const btn = document.createElement("button");
28+
btn.id = "md-width-toggle";
29+
btn.className = "md-header__button md-width-toggle";
30+
btn.setAttribute("aria-label", "Toggle page width");
31+
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
3232

33-
const header = document.querySelector(".md-header__inner");
34-
if (header) {
35-
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
36-
|| header.querySelector("label.md-header__button");
37-
if (searchButton) {
38-
searchButton.parentNode.insertBefore(btn, searchButton);
39-
} else {
40-
header.appendChild(btn);
33+
const header = document.querySelector(".md-header__inner");
34+
if (header) {
35+
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
36+
|| header.querySelector("label.md-header__button");
37+
if (searchButton) {
38+
searchButton.parentNode.insertBefore(btn, searchButton);
39+
} else {
40+
header.appendChild(btn);
41+
}
4142
}
42-
}
43-
})();
43+
})();
4444
</script>
4545
{{ super() }}
4646
{% endblock %}

docs/invui2/assets/js/width-toggle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
// Width toggle functionality
2-
document.addEventListener("DOMContentLoaded", function() {
2+
document.addEventListener("DOMContentLoaded", function () {
33
const toggleButton = document.getElementById("md-width-toggle");
44
const icons = window.__mdWidthIcons;
5-
5+
66
// Width modes cycle: slim -> wide -> full -> slim
77
const modes = ["slim", "wide", "full"];
8-
8+
99
function capitalize(str) {
1010
return str.charAt(0).toUpperCase() + str.slice(1);
1111
}
12-
12+
1313
function updateButton(mode) {
1414
toggleButton.innerHTML = mode === "full" ? icons.minimize : icons.maximize;
1515
const nextMode = modes[(modes.indexOf(mode) + 1) % modes.length];
1616
toggleButton.setAttribute("title", `Current: ${capitalize(mode)} - Click for ${capitalize(nextMode)}`);
1717
}
18-
18+
1919
function applyMode(mode) {
2020
if (mode === "slim") {
2121
document.documentElement.removeAttribute("data-md-width");
2222
} else {
2323
document.documentElement.setAttribute("data-md-width", mode);
2424
}
2525
}
26-
26+
2727
// Initialize button with saved preference
2828
const savedWidth = localStorage.getItem("md-width") || "slim";
2929
updateButton(savedWidth);
30-
30+
3131
// Toggle handler - cycle through modes
32-
toggleButton.addEventListener("click", function() {
32+
toggleButton.addEventListener("click", function () {
3333
const currentMode = localStorage.getItem("md-width") || "slim";
3434
const nextMode = modes[(modes.indexOf(currentMode) + 1) % modes.length];
35-
35+
3636
applyMode(nextMode);
3737
localStorage.setItem("md-width", nextMode);
3838
updateButton(nextMode);

docs/invui2/overrides/main.html

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,45 @@
22

33
{% block styles %}
44
<script>
5-
(function() {
6-
const savedWidth = localStorage.getItem("md-width") || "slim";
7-
if (savedWidth === "wide" || savedWidth === "full") {
8-
document.documentElement.setAttribute("data-md-width", savedWidth);
9-
}
10-
// Store for width-toggle.js to use
11-
window.__mdWidthMode = savedWidth;
12-
})();
5+
(function () {
6+
const savedWidth = localStorage.getItem("md-width") || "slim";
7+
if (savedWidth === "wide" || savedWidth === "full") {
8+
document.documentElement.setAttribute("data-md-width", savedWidth);
9+
}
10+
// Store for width-toggle.js to use
11+
window.__mdWidthMode = savedWidth;
12+
})();
1313
</script>
1414
{{ super() }}
1515
{% endblock %}
1616

1717
{% block content %}
1818
<script>
19-
// Inject toggle button immediately when header is available
20-
(function() {
21-
window.__mdWidthIcons = {
22-
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
23-
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
24-
};
19+
// Inject toggle button immediately when header is available
20+
(function () {
21+
window.__mdWidthIcons = {
22+
maximize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></g></svg>',
23+
minimize: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="-2 -2 28 28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(45 12 12)"><path d="m14 10 7-7"/><path d="M20 10h-6V4"/><path d="m3 21 7-7"/><path d="M4 14h6v6"/></g></svg>'
24+
};
2525

26-
const mode = window.__mdWidthMode || "slim";
27-
const btn = document.createElement("button");
28-
btn.id = "md-width-toggle";
29-
btn.className = "md-header__button md-width-toggle";
30-
btn.setAttribute("aria-label", "Toggle page width");
31-
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
26+
const mode = window.__mdWidthMode || "slim";
27+
const btn = document.createElement("button");
28+
btn.id = "md-width-toggle";
29+
btn.className = "md-header__button md-width-toggle";
30+
btn.setAttribute("aria-label", "Toggle page width");
31+
btn.innerHTML = mode === "full" ? window.__mdWidthIcons.minimize : window.__mdWidthIcons.maximize;
3232

33-
const header = document.querySelector(".md-header__inner");
34-
if (header) {
35-
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
36-
|| header.querySelector("label.md-header__button");
37-
if (searchButton) {
38-
searchButton.parentNode.insertBefore(btn, searchButton);
39-
} else {
40-
header.appendChild(btn);
33+
const header = document.querySelector(".md-header__inner");
34+
if (header) {
35+
const searchButton = header.querySelector(".md-header__button.md-icon[for='__search']")
36+
|| header.querySelector("label.md-header__button");
37+
if (searchButton) {
38+
searchButton.parentNode.insertBefore(btn, searchButton);
39+
} else {
40+
header.appendChild(btn);
41+
}
4142
}
42-
}
43-
})();
43+
})();
4444
</script>
4545
{{ super() }}
4646
{% endblock %}

0 commit comments

Comments
 (0)