version switch: turn into a custom element #104778
@ -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" class="close">
|
||||
<version-switch type="version" class="closed">
|
||||
<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" class="close">
|
||||
<version-switch type="lang" class="closed">
|
||||
<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 %}
|
||||
|
@ -75,7 +75,7 @@ init() {
|
||||
|
||||
const version = this.getNamed(release);
|
||||
this.buildList(version, lang);
|
||||
this.className = "close";
|
||||
this.className = "closed";
|
||||
});
|
||||
}
|
||||
warnOld(release, all_versions) {
|
||||
@ -104,7 +104,7 @@ warnOld(release, all_versions) {
|
||||
}
|
||||
}
|
||||
buildList(version, lang) {
|
||||
const type = this.id === "version-popover";
|
||||
const type = this.getAttribute("type") === "version";
|
||||
const list = this.querySelector("ul");
|
||||
list.firstElementChild.remove();
|
||||
const url = new URL(window.location.href);
|
||||
@ -160,7 +160,7 @@ getNamed(version) {
|
||||
return version;
|
||||
}
|
||||
open() {
|
||||
if(this.className === "close") {
|
||||
if(this.className === "closed") {
|
||||
this.init()
|
||||
.then(() => {
|
||||
this.className = "open";
|
||||
@ -182,7 +182,7 @@ open() {
|
||||
}
|
||||
close() {
|
||||
if(this.className === "open") {
|
||||
this.className = "close";
|
||||
this.className = "closed";
|
||||
const button = this.firstElementChild;
|
||||
button.setAttribute("aria-pressed", false);
|
||||
this.lastElementChild.setAttribute("aria-hidden", true);
|
||||
@ -198,7 +198,7 @@ close() {
|
||||
}
|
||||
}
|
||||
toggle() {
|
||||
if(this.className === "close") {
|
||||
if(this.className === "closed") {
|
||||
this.open();
|
||||
} else {
|
||||
this.close();
|
||||
@ -285,6 +285,6 @@ customElements.define("version-switch", VersionSwitch);
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
let lang = DOCUMENTATION_OPTIONS.LANGUAGE;
|
||||
if(!lang || lang === "None") {lang = "en";}
|
||||
if(all_langs.hasOwnProperty(lang)) {document.querySelector("#lang-popover button").innerHTML = all_langs[lang];}
|
||||
if(all_langs.hasOwnProperty(lang)) {document.querySelector("version-switch[type=lang] button").innerHTML = all_langs[lang];}
|
||||
});
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user