diff --git a/selectVersion.js b/selectVersion.js
index 6b6d3ed..4513c27 100644
--- a/selectVersion.js
+++ b/selectVersion.js
@@ -1,90 +1,97 @@
/**
* selectVersion.js: select an angular distribution version.
*
* author: Christian Steiner
* email: christian.steiner@unibas.ch
* license: GPL v3
*
* Copyright (C) University of Basel 2021
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
**/
/**
* Script adds a selection that allows the user to select a specific angular distribution folder.
* Based on the selection (or the current URL), the script loads the relevant scripts from the selected angular folder.
* Reads a json-file 'versions.json' that describes the distribution versions.
* (The json-file can be created with the python script 'addVersion.py'.)
**/
$(document).ready(function(){
var currentUrl = new URL(location.href);
$("body").prepend("
");
$.getJSON("/versions.json", function(versions){
- var currentVersion = writeBase(currentUrl, versions[0].number);
+ if (versions.length == 1){
+ $("body").remove("#selectVersion");
+ $("selectContainer").append("");
+ }
+ var currentVersion = writeBase(currentUrl, versions[0].number, versions.map(version =>version.number));
$("body").append("<\/app-root>");
versions.forEach(version =>{
writeOptions(version, currentVersion);
writeScripts(version.scripts);
});
}).fail(function(){
console.log("Could not read 'versions.json'!");
});
// Poll for fullscreen toggle change
var fullscreen = false;
setInterval(function(){
if(location.href.includes('fullscreen=true') && !fullscreen){
fullscreen = true;
$("#selectContainer").hide();
} else if (location.href.includes('fullscreen=false') && fullscreen){
fullscreen = false;
$("#selectContainer").show();
}
},500);
// Act on selection changes -> change location to new version.
$("#selectVersion").change(function(){
var version = $(this).find("option:selected").attr("value");
currentUrl = new URL(location.href);
location.href = "/" + version + "/" + currentUrl.pathname.split('/').slice(2).join('/') + "?" + currentUrl.searchParams.toString();
});
});
/**
* Write the current base to the document body and return its value.
**/
-function writeBase(currentUrl, newestVersion){
- var baseHref = (currentUrl.pathname.split('/')[1] != '') ? currentUrl.pathname.split('/')[1] : newestVersion;
+function writeBase(currentUrl, newestVersion, versionNumbers){
+ var baseHref = currentUrl.pathname.split('/')[1];
+ if (baseHref == '' || !versionNumbers.includes(baseHref)){
+ baseHref = newestVersion;
+ }
$("head").append("");
return baseHref;
}
/**
* Write the options of the version selection to #selectVersion.
**/
function writeOptions(version, currentVersion){
if(version.number == currentVersion){
$("#selectVersion").append("");
} else {
$("#selectVersion").append("");
}
}
/**
* Write the scripts that should be loaded to the document body.
**/
function writeScripts(scripts){
scripts.forEach(script =>{
if(script.isModule){
$("body").append("