version switch: turn into a custom element #104778

Open
Tobias Heinke wants to merge 3 commits from Tobias/blender-manual:switcher-two into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 15 additions and 15 deletions
Showing only changes of commit 7409670ef6 - Show all commits

View File

@ -1,7 +1,7 @@
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="Document versions">
<ul id="version-menus" role="presentation">
<li role="presentation">
<version-switch id="version-popover" data-state="close">
<version-switch id="version-popover" class="close">
<button tabindex="0" type="button" aria-label="Versions selector"
aria-haspopup="true" aria-owns="version-dialog-version">
{{ release }}
@ -15,7 +15,7 @@
</version-switch>
</li>
<li role="presentation">
<version-switch id="lang-popover" data-state="close">
<version-switch id="lang-popover" class="close">
<button tabindex="0" type="button" aria-label="Language selector"
aria-haspopup="true" aria-owns="version-dialog-lang">
{% if language is not none %} {{ language }} {% else %} en {% endif %}

View File

@ -34,7 +34,7 @@ version-switch button {
z-index: 400;
}
version-switch[data-state="open"] button::after {
version-switch.open button::after {
color: gray;
}
@ -43,16 +43,16 @@ version-switch button:focus {
border-color: #525252;
}
version-switch[data-state="open"] button {
version-switch.open button {
color: gray;
border: solid 1px var(--color-sidebar-background-border);
}
version-switch[data-state="wait"] button {
version-switch.wait button {
cursor: wait;
}
version-switch[data-state="disabled"] button {
version-switch.disabled button {
cursor: not-allowed;
color: dimgray;
}
@ -74,7 +74,7 @@ version-switch .version-dialog {
cursor: default;
}
version-switch[data-state="open"] .version-dialog {
version-switch.open .version-dialog {
visibility: visible;
opacity: 1;
transition: visibility 0s linear 0s, opacity 200ms;

View File

@ -45,7 +45,7 @@ connectedCallback() {
init() {
return new Promise((resolve) => {
if(all_versions === undefined) {
this.setAttribute("data-state", "wait");
this.className = "wait";
fetch(versionsFileUrl)
.then((response) => response.json())
.then((data) => {
@ -53,7 +53,7 @@ init() {
resolve();
})
.catch((err) => {
this.setAttribute("data-state", "disabled");
this.className = "disabled";
console.error(err);
});
} else {
@ -75,7 +75,7 @@ init() {
const version = this.getNamed(release);
this.buildList(version, lang);
this.setAttribute("data-state", "close");
this.className = "close";
});
}
warnOld(release, all_versions) {
@ -160,10 +160,10 @@ getNamed(version) {
return version;
}
open() {
if(this.getAttribute("data-state") === "close") {
if(this.className === "close") {
this.init()
.then(() => {
this.setAttribute("data-state", "open");
this.className = "open";
this.firstElementChild.setAttribute("aria-pressed", true);
this.lastElementChild.setAttribute("aria-hidden", false);
const s = this.querySelector(".selected");
@ -181,8 +181,8 @@ open() {
}
}
close() {
if(this.getAttribute("data-state") === "open") {
this.setAttribute("data-state", "close");
if(this.className === "open") {
this.className = "close";
const button = this.firstElementChild;
button.setAttribute("aria-pressed", false);
this.lastElementChild.setAttribute("aria-hidden", true);
@ -198,7 +198,7 @@ close() {
}
}
toggle() {
if(this.getAttribute("data-state") === "close") {
if(this.className === "close") {
this.open();
} else {
this.close();