File: version.js

package info (click to toggle)
seqan3 3.0.2%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,052 kB
  • sloc: cpp: 144,641; makefile: 1,288; ansic: 294; sh: 228; xml: 217; javascript: 50; python: 27; php: 25
file content (74 lines) | stat: -rw-r--r-- 2,720 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Jongkyu Kim (j.kim@fu-berlin.de), 2016.01.12
   Adaptations by Enrico Seiler (enrico.seiler@fu-berlin.de), 2020 */

function changeVersion(form_id)
{
    // Get the base url without version information, e.g. "https://docs.seqan.de/seqan"
    var current_script_url = document.scripts[document.scripts.length - 1].src;
    var base_url = current_script_url.split('/').slice(0, -2).join('/');

    // Get the current page, e.g. "index.html"
    var full_url = window.top.location.href;
    var current_page = full_url.substring(full_url.lastIndexOf("/") + 1);

    // Get the selected version
    var form = document.getElementById(form_id);
    var version = form.options[form.selectedIndex].value;

    // Check if the current page is valid with the selected version
    var proposed_url = base_url + '/' + version + '/' + current_page;
    var request = new XMLHttpRequest();
    request.open('GET', proposed_url, false);
    request.send();
    // If the URL is invalid, redirect to main page of the selected version
    // If htaccess is configured to redirect invalid URLs to the base domain,
    // no 404 is returned, hence the second condition
    if (request.status === 404 || request.responseURL == window.location.origin + '/')
    {
        proposed_url = base_url + '/' + version;
    }

    // Load the proper page
    window.top.location.href = proposed_url;
}

function addVersionSelection(arr)
{
    // add HTMLs
    var version_select = document.createElement("select");
    var version_div = document.createElement("div");

    version_select.setAttribute("id","version_select");
    version_div.setAttribute("style","vertical-align:middle; text-align:right;");
    version_div.appendChild(document.createTextNode("Version: "));
    version_div.appendChild(version_select);
    document.getElementById("list_bottom_right").appendChild(version_div);

    version_select.addEventListener("change", function(){changeVersion(this.id);}, false);

    // current selection is..
    cur_sel = window.location.pathname.split("/")[2];

    for(i=0; i < arr.length; ++i)
    {
        var op = document.createElement("option");
        op.value = arr[i];
        op.text = arr[i];
        op.selected = ( arr[i] == cur_sel ) ? true : false;
        version_select.add(op);
    }
}

// get JSON data & add selection form
var request = new XMLHttpRequest();
request.open("GET", "version.php", true);
request.setRequestHeader("Content-type", "application/json");
request.onreadystatechange = function()
{
    if( request.readyState == 4 && request.status == 200 )
    {
        var response = JSON.parse(request.responseText);
        addVersionSelection(response); // add selection form
    }
}
request.send();