mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-03-26 13:04:10 +01:00
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
|
|
window.addEventListener('DOMContentLoaded', () => {
|
||
|
|
const selector = document.getElementById("version-selector")
|
||
|
|
|
||
|
|
// Get the current version number and check that it or "latest" appears in the URL.
|
||
|
|
let current = selector.querySelector("option[selected]").value
|
||
|
|
let current_segment
|
||
|
|
console.log("current", current)
|
||
|
|
if (window.location.href.includes("/" + current + "/")) {
|
||
|
|
current_segment = "/" + current + "/"
|
||
|
|
} else if (window.location.href.includes("/latest/")) {
|
||
|
|
current_segment = "/latest/"
|
||
|
|
} else {
|
||
|
|
// If not, ditch the selector dropdown.
|
||
|
|
let parent = selector.parentElement
|
||
|
|
let fallback = parent.querySelector("noscript")
|
||
|
|
parent.removeChild(fallback)
|
||
|
|
parent.removeChild(selector)
|
||
|
|
parent.appendChild(document.createTextNode(fallback.innerText))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
selector.addEventListener("change", event => {
|
||
|
|
let chosen = event.target.value
|
||
|
|
if (chosen === "historical") {
|
||
|
|
// Go to the "historical version" in the current spec's revision.
|
||
|
|
let parts = window.location.href.split(current_segment, 2)
|
||
|
|
window.location.href = parts[0] + current_segment + "changelog/#historical-versions"
|
||
|
|
} else {
|
||
|
|
window.location.href = window.location.href.replace(current_segment, "/" + chosen + "/")
|
||
|
|
}
|
||
|
|
})
|
||
|
|
});
|