-
Notifications
You must be signed in to change notification settings - Fork 11
Update versionwarning.js #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51deff8
Update versionwarning.js
drammock f8cfe59
triage class/style based on docs version
drammock 7e9716e
remove spurious closing tag
drammock c8b3af1
use buttons
drammock 95ad385
RFC: Use Bootstrap buttons
hoechenberger fd9c595
cleanups/tweaks
drammock 3767a64
convert template string to normal string
drammock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`); | ||
| } | ||
| } | ||
| })() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.