File tree 1 file changed +14
-2
lines changed
src/Resources/themes/default
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -76,8 +76,20 @@ var Doctum = {
76
76
{# Enable the version switcher #}
77
77
var versionSwitcher = document.getElementById('version-switcher');
78
78
if (versionSwitcher !== null) {
79
- versionSwitcher.addEventListener('change', function () {
80
- window.location = this.value;
79
+ var currentVersion = versionSwitcher.options[versionSwitcher.selectedIndex].dataset.version;
80
+ versionSwitcher.addEventListener('change', function (event) {
81
+ var targetVersion = event.target.options[event.target.selectedIndex].dataset.version;
82
+ var candidateUrl = window.location.pathname.replace(currentVersion, targetVersion);
83
+ // Check if the page exists before redirecting to it
84
+ var testRequest = new XMLHttpRequest();
85
+ testRequest.open('HEAD', candidateUrl, false);
86
+ testRequest.send();
87
+ if (testRequest.status < 200 || testRequest.status > 399) {
88
+ window.location = candidateUrl;
89
+ } else {
90
+ // otherwise reroute to the home page of the new version
91
+ window.location = this.value;
92
+ }
81
93
});
82
94
}
83
95
{% endif %}
You can’t perform that action at this time.
0 commit comments