Skip to content

Commit 8c5ba34

Browse files
authored
Refresh page when switching specification versions
PR-URL: #628 Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Ralf Gommers <[email protected]>
2 parents 258cafb + 44b35f6 commit 8c5ba34

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function assign_href(a, url, path) {
2+
fetch(url + "/" + path).then(response => {
3+
if (response.ok) {
4+
a.href = url + "/" + path;
5+
} else {
6+
a.href = url + "/index.html";
7+
}
8+
}).catch(error => {
9+
a.href = url + "/index.html";
10+
});
11+
}
12+
13+
function add_version_dropdown(json_loc, target_loc, text) {
14+
var dropdown = document.createElement("div");
15+
dropdown.className = "md-flex__cell md-flex__cell--shrink dropdown";
16+
var button = document.createElement("button");
17+
button.className = "dropdownbutton";
18+
var content = document.createElement("div");
19+
content.className = "dropdown-content md-hero";
20+
dropdown.appendChild(button);
21+
dropdown.appendChild(content);
22+
$.getJSON(json_loc, function(versions) {
23+
var currentURL = window.location.href;
24+
var path = currentURL.split("_site")[1];
25+
path = path.split("/");
26+
path = path.slice(2, path.length);
27+
path = path.join("/");
28+
for (var key in versions) {
29+
if (versions.hasOwnProperty(key)) {
30+
var a = document.createElement("a");
31+
a.innerHTML = key;
32+
a.title = key;
33+
assign_href(a, target_loc + versions[key], path);
34+
content.appendChild(a);
35+
}
36+
}
37+
}).done(function() {
38+
button.innerHTML = text;
39+
}).fail(function() {
40+
button.innerHTML = "Other Versions Not Found";
41+
}).always(function() {
42+
$(".navheader").append(dropdown);
43+
});
44+
};

0 commit comments

Comments
 (0)