|
1 | 1 | (function() {
|
2 | 2 | // 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 |
| - }; |
19 | 3 | 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}`); |
27 | 30 | }
|
28 | 31 | }
|
29 | 32 | })()
|
0 commit comments