Skip to content

Commit 5aec011

Browse files
authored
wait for ajax result before writing to document (#24)
1 parent afac69e commit 5aec011

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

versionwarning.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@
88
$.ajax({
99
type: 'HEAD',
1010
url: `https://mne.tools/stable/${filePath}`,
11-
}).fail(function() {
12-
filePath = '';
13-
});
14-
if (version !== 'stable') {
15-
// parse version to figure out which website theme classes to use
16-
var pre = '<div class="container-fluid alert-danger devbar"><div class="row no-gutters"><div class="col-12 text-center">';
17-
var post = '</div></div></div>';
18-
var anchor = 'class="btn btn-danger font-weight-bold ml-3 my-3 align-baseline"';
19-
if (parseFloat(version) < 0.23) { // 'dev' → NaN → false (which is what we want)
20-
pre = '<div class="d-block devbar alert alert-danger">';
21-
post = '</div>';
22-
anchor = 'class="btn btn-danger" style="font-weight: bold; vertical-align: baseline; margin: 0.5rem; border-style: solid; border-color: white;"';
23-
}
24-
// triage message
25-
var verText = `an <strong>old version (${version})</strong>`;
26-
if (version == 'dev') {
27-
verText = 'the <strong>unstable development version</strong>';
11+
error: function() {
12+
filePath = '';
13+
},
14+
complete: function() {
15+
if (version !== 'stable') {
16+
// parse version to figure out which website theme classes to use
17+
var pre = '<div class="container-fluid alert-danger devbar"><div class="row no-gutters"><div class="col-12 text-center">';
18+
var post = '</div></div></div>';
19+
var anchor = 'class="btn btn-danger font-weight-bold ml-3 my-3 align-baseline"';
20+
if (parseFloat(version) < 0.23) { // 'dev' → NaN → false (which is what we want)
21+
pre = '<div class="d-block devbar alert alert-danger">';
22+
post = '</div>';
23+
anchor = 'class="btn btn-danger" style="font-weight: bold; vertical-align: baseline; margin: 0.5rem; border-style: solid; border-color: white;"';
24+
}
25+
// triage message
26+
var verText = `an <strong>old version (${version})</strong>`;
27+
if (version == 'dev') {
28+
verText = 'the <strong>unstable development version</strong>';
29+
}
30+
$('body').prepend(`${pre}This is documentation for ${verText} of MNE-Python. <a ${anchor} href="https://mne.tools/stable/${filePath}">Switch to stable version</a>${post}`);
31+
}
2832
}
29-
$('body').prepend(`${pre}This is documentation for ${verText} of MNE-Python. <a ${anchor} href="https://mne.tools/stable/${filePath}">Switch to stable version</a>${post}`);
30-
}
33+
});
3134
}
3235
})()

0 commit comments

Comments
 (0)