| 1 |
'use strict'; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 44 |
versionSelect.change(function() { |
| 45 |
var newVersion = jQuery(this).val(); |
| 46 |
if (newVersion == cgeCurrentVersion) { |
| 47 |
return; |
| 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 |
|
| 61 |
|
| 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 |
|
| 70 |
cgeChangeLocation(completeNewVersionUrl, newVersionUrl); |
| 71 |
} |
| 72 |
}); |
| 73 |
|
| 74 |
jQuery('.navigation').append(versionsForm); |
| 75 |
}); |