forked from textX/textX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mike-docs' into mike-docs-1.7
- Loading branch information
Showing
3 changed files
with
98 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#version-selector { | ||
display: block; | ||
margin: -10px auto 0.809em; | ||
padding: 2px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
window.addEventListener("DOMContentLoaded", function() { | ||
function normalizePath(path) { | ||
var normalized = []; | ||
path.split("/").forEach(function(bit, i) { | ||
if (bit === "." || (bit === "" && i !== 0)) { | ||
return; | ||
} else if (bit === "..") { | ||
if (normalized.length === 1 && normalized[0] === "") { | ||
// We must be trying to .. past the root! | ||
throw new Error("invalid path"); | ||
} else if (normalized.length === 0 || | ||
normalized[normalized.length - 1] === "..") { | ||
normalized.push(".."); | ||
} else { | ||
normalized.pop(); | ||
} | ||
} else { | ||
normalized.push(bit); | ||
} | ||
}); | ||
return normalized.join("/"); | ||
} | ||
|
||
// `base_url` comes from the base.html template for this theme. | ||
var REL_BASE_URL = base_url; | ||
var ABS_BASE_URL = normalizePath(window.location.pathname + "/" + | ||
REL_BASE_URL); | ||
var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); | ||
|
||
function makeSelect(options, selected) { | ||
var select = document.createElement("select"); | ||
|
||
options.forEach(function(i) { | ||
var option = new Option(i.text, i.value, undefined, | ||
i.value === selected); | ||
select.add(option); | ||
}); | ||
|
||
return select; | ||
} | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", REL_BASE_URL + "/../versions.json"); | ||
xhr.onload = function() { | ||
var versions = JSON.parse(this.responseText); | ||
|
||
var realVersion = versions.find(function(i) { | ||
return i.version === CURRENT_VERSION || | ||
i.aliases.includes(CURRENT_VERSION); | ||
}).version; | ||
|
||
var select = makeSelect(versions.map(function(i) { | ||
return {text: i.title, value: i.version}; | ||
}), realVersion); | ||
select.id = "version-selector"; | ||
select.addEventListener("change", function(event) { | ||
window.location.href = REL_BASE_URL + "/../" + this.value; | ||
}); | ||
|
||
var title = document.querySelector("div.wy-side-nav-search"); | ||
title.insertBefore(select, title.querySelector(".icon-home").nextSibling); | ||
}; | ||
xhr.send(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters