-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation version selector (#204)
- Loading branch information
1 parent
4a8c2fb
commit 9d1f3ee
Showing
6 changed files
with
89 additions
and
18 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
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
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 @@ | ||
@media only screen and (max-width:76.1875em) { | ||
#version-selector { | ||
padding: .6rem .8rem; | ||
} | ||
} |
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,54 @@ | ||
window.addEventListener("DOMContentLoaded", function() { | ||
// This is a bit hacky. Figure out the base URL from a known CSS file the | ||
// template refers to... | ||
var ex = new RegExp("/?css/version-select.css$"); | ||
var sheet = document.querySelector('link[href$="version-select.css"]'); | ||
|
||
var ABS_BASE_URL = sheet.href.replace(ex, ""); | ||
var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); | ||
|
||
function makeSelect(options, selected) { | ||
var select = document.createElement("select"); | ||
select.classList.add("form-control"); | ||
|
||
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", ABS_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) { | ||
if (i.aliases.length > 0) { | ||
var aliasString = " [" + i.aliases.join(", ") + "]"; | ||
} else { | ||
var aliasString = ""; | ||
} | ||
return {text: i.title + aliasString, value: i.version}; | ||
}), realVersion); | ||
select.addEventListener("change", function(event) { | ||
window.location.href = ABS_BASE_URL + "/../" + this.value; | ||
}); | ||
|
||
var container = document.createElement("div"); | ||
container.id = "version-selector"; | ||
// container.className = "md-nav__item"; | ||
container.appendChild(select); | ||
|
||
var sidebar = document.querySelector(".md-nav--primary > .md-nav__list"); | ||
sidebar.parentNode.insertBefore(container, sidebar.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
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