diff --git a/versionwarning.js b/versionwarning.js index 31e5b830115..ded0644cf2a 100644 --- a/versionwarning.js +++ b/versionwarning.js @@ -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(`
`) - - }; 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 latest stable release (version ${latestStable}) - or the development (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 = ''; + 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 = ''; + 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 old version (${version})`; + if (version == 'dev') { + verText = 'the unstable development version'; + } + $('body').prepend(`${pre}This is documentation for ${verText} of MNE-Python. Switch to stable version${post}`); } } })()