matrix-spec/static/js/version_selector.js

33 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-06-16 01:51:37 +02:00
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 + "/")
}
})
});