|
| 1 | +$(document).ready(function() { |
| 2 | + /* For a URL that looks like |
| 3 | + https://blah.github.io/versions/VERSIONFOO/html/bar/index.html, set cur_version_dir to |
| 4 | + 'VERSIONFOO' (i.e., the portion of the path following 'versions'). |
| 5 | + */ |
| 6 | + var proj_end = document.baseURI.indexOf("versions") + 9; |
| 7 | + var end = document.baseURI.indexOf("/", proj_end); |
| 8 | + var cur_version_dir = document.baseURI.substring(proj_end, end); |
| 9 | + var mylist = $("#version-list"); |
| 10 | + mylist.empty(); |
| 11 | + $.getJSON(version_json_loc, function(data) { |
| 12 | + if (data.hasOwnProperty(cur_version_dir)) { |
| 13 | + /* First add the current version so that it appears first in the drop-down |
| 14 | + menu and starts as the selected element of the menu. If you click on the |
| 15 | + current version, you should stay at the current page. |
| 16 | +
|
| 17 | + The conditional around this block should generally be true, but we check it |
| 18 | + just in case the current version is missing from the versions.json file for |
| 19 | + some reason. |
| 20 | + */ |
| 21 | + cur_version_name = data[cur_version_dir]; |
| 22 | + mylist.append($("<option>", {value: document.baseURI, text: cur_version_name})); |
| 23 | + } |
| 24 | + // Now add the other versions |
| 25 | + $.each(data, function(version_dir, version_name) { |
| 26 | + if (version_dir != cur_version_dir) { |
| 27 | + /* If you click on a different version, you should go to the root of the |
| 28 | + documentation for that version. This assumes paths like |
| 29 | + https://blah.github.io/versions/VERSIONFOO/html/bar/index.html. So we |
| 30 | + need to go up two levels from the URL_ROOT (html) to then go back down |
| 31 | + into the appropriate version's html directory. |
| 32 | + */ |
| 33 | + mylist.append($("<option>", {value: DOCUMENTATION_OPTIONS.URL_ROOT + '../../' + version_dir + '/html', text: version_name})); |
| 34 | + } |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments