Skip to content

Commit b6eb330

Browse files
Update versionwarning.js (#23)
* Update versionwarning.js * triage class/style based on docs version * remove spurious closing tag * use buttons * RFC: Use Bootstrap buttons * cleanups/tweaks - removed `d-md` and `text-dark` (not clear why needed?) - removed `alert-link` (not needed for buttons) - simplified margin CSS on BS3 version - fixed: no `font-weight-*` classes in BS3 - refactored single-use constant "style" * convert template string to normal string Co-authored-by: Richard Höchenberger <[email protected]> Co-authored-by: Richard Höchenberger <[email protected]>
1 parent f0b3e58 commit b6eb330

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

versionwarning.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
(function() {
22
// adapted 2020-05 from https://scikit-learn.org/versionwarning.js
3-
const latestStable = '0.20';
4-
const goodPaths = ['stable', 'dev', latestStable];
5-
const devbar_style = [
6-
'text-align: center',
7-
'padding: 5px',
8-
'margin-bottom: 5px',
9-
'border-radius: 0 0 4px 4px !important',
10-
'background-color: #e74c3c',
11-
'border-color: #e74c3c',
12-
'color: #ffffff',
13-
'font-weight: normal'
14-
].join('; ')
15-
const showWarning = (msg) => {
16-
$('body').prepend(`<div class="d-block devbar alert alert-danger" style="${devbar_style}">${msg}</div>`)
17-
18-
};
193
if (location.hostname === 'mne.tools') {
20-
const versionPath = location.pathname.split('/')[1];
21-
if (!goodPaths.includes(versionPath)) {
22-
const link_style = "color: #ffffff; font-weight: bold"
23-
const warning = `This is documentation for an old release of MNE-Python (version ${versionPath}).
24-
Try the <a style="${link_style}" href="https://mne.tools">latest stable release</a> (version ${latestStable})
25-
or the <a style="${link_style}" href="https://mne.tools/dev">development</a> (unstable) version.`;
26-
showWarning(warning)
4+
const urlParts = location.pathname.split('/');
5+
const version = urlParts[1];
6+
// see if filePath exists in the stable version of the docs
7+
var filePath = urlParts.slice(2).join('/');
8+
$.ajax({
9+
type: 'HEAD',
10+
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>';
28+
}
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}`);
2730
}
2831
}
2932
})()

0 commit comments

Comments
 (0)