Debian Codegraph @

doc/pasdoc/html-parts/cge-pasdoc.js

raw symbols SCIP
1 'use strict';
2
3 /* Change browser location to url, unless it doesn't exist,
4 then jump to fallbackUrl.
5 Detecting of url uses AJAX and will only work on the same domain. */
6 function cgeChangeLocation(url, fallbackUrl)
7 {
8 var ajax = jQuery.ajax({
9 type: "get",
10 url: url,
11 cache: false
12 });
13 ajax.done(function() {
14 window.location = url;
15 });
16 ajax.fail(function() {
17 window.location = fallbackUrl;
18 });
19 }
20
21 /* Append a form to switch API docs between various engine versions. */
22 jQuery(document).ready(function() {
23 var versionsForm = jQuery(`<form class="cge-version-form form-inline">
24 <div class="form-group">
25 <label for="engineVersion" class="">Engine version:</label>
26 <select class="form-control" id="engineVersion">
27 </select>
28 </div>
29 </form>`);
30
31 var versionSelect = versionsForm.find('#engineVersion');
32
33 // add all existing versions to <select>
34 cgeVersions.forEach(function (version) {
35 var option = jQuery('<option>', {
36 'selected': version.id == cgeCurrentVersion,
37 'name': version.id,
38 'html': version.id
39 });
40 versionSelect.append(option);
41 });
42
43 // when <select> changes, redirect to new version
44 versionSelect.change(function() {
45 var newVersion = jQuery(this).val();
46 if (newVersion == cgeCurrentVersion) {
47 return; // don't redirect to main page of current version
48 }
49
50 var newVersionUrl = '', oldVersionUrl = '';
51 cgeVersions.forEach(function (version) {
52 if (version.id == newVersion) {
53 newVersionUrl = version.url;
54 }
55 if (version.id == cgeCurrentVersion) {
56 oldVersionUrl = version.url;
57 }
58 });
59
60 /* We want to jump to newVersionUrl now.
61 Try to preserve a suffix in window.location (ignoring oldVersionUrl). */
62 if (newVersionUrl !== '') {
63 var completeNewVersionUrl = newVersionUrl;
64 if (oldVersionUrl !== '' && window.location.href.startsWith(oldVersionUrl)) {
65 completeNewVersionUrl =
66 window.location.href.replace(oldVersionUrl, newVersionUrl);
67 }
68
69 /* try to jump to completeNewVersionUrl, fallback on newVersionUrl */
70 cgeChangeLocation(completeNewVersionUrl, newVersionUrl);
71 }
72 });
73
74 jQuery('.navigation').append(versionsForm);
75 });