Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions versionwarning.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
(function() {
// adapted 2020-05 from https://scikit-learn.org/versionwarning.js
const latestStable = '0.20';
const goodPaths = ['stable', 'dev', latestStable];
const devbar_style = [
'text-align: center',
'padding: 5px',
'margin-bottom: 5px',
'border-radius: 0 0 4px 4px !important',
'background-color: #e74c3c',
'border-color: #e74c3c',
'color: #ffffff',
'font-weight: normal'
].join('; ')
const showWarning = (msg) => {
$('body').prepend(`<div class="d-block devbar alert alert-danger" style="${devbar_style}">${msg}</div>`)

};
if (location.hostname === 'mne.tools') {
const versionPath = location.pathname.split('/')[1];
if (!goodPaths.includes(versionPath)) {
const link_style = "color: #ffffff; font-weight: bold"
const warning = `This is documentation for an old release of MNE-Python (version ${versionPath}).
Try the <a style="${link_style}" href="https://mne.tools">latest stable release</a> (version ${latestStable})
or the <a style="${link_style}" href="https://mne.tools/dev">development</a> (unstable) version.`;
showWarning(warning)
const urlParts = location.pathname.split('/');
const version = urlParts[1];
// see if filePath exists in the stable version of the docs
var filePath = urlParts.slice(2).join('/');
$.ajax({
type: 'HEAD',
url: `https://mne.tools/stable/${filePath}`,
}).fail(function() {
filePath = '';
});
if (version !== 'stable') {
// parse version to figure out which website theme classes to use
var pre = '<div class="container-fluid alert-danger devbar"><div class="row no-gutters"><div class="col-12 text-center">';
var post = '</div></div></div>';
var anchor = 'class="btn btn-danger font-weight-bold ml-3 my-3 align-baseline"';
if (parseFloat(version) < 0.23) { // 'dev' → NaN → false (which is what we want)
pre = '<div class="d-block devbar alert alert-danger">';
post = '</div>';
anchor = `class="btn btn-danger" style="font-weight: bold; vertical-align: baseline; margin: 0.5rem; border-style: solid; border-color: white;"`;
}
// triage message
var verText = `an <strong>old version (${version})</strong>`;
if (version == 'dev') {
verText = 'the <strong>unstable development version</strong>';
}
$('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}`);
}
}
})()