-
Notifications
You must be signed in to change notification settings - Fork 229
Enable switching different versions of documentation #621
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 all commits
Commits
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2013 PSF. Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 | ||
// File originates from the cpython source found in Doc/tools/sphinxext/static/version_switch.js | ||
|
||
(function() { | ||
'use strict'; | ||
|
||
var doc_url = "www.pygmt.org"; | ||
//var doc_url = "0.0.0.0:8000"; // for local testing only | ||
var url_re = new RegExp(doc_url + "\\/(dev|latest|(v\\d+\\.\\d+\\.\\d+))\\/"); | ||
// List all versions. | ||
// Add one entry "version: title" for any minor releases | ||
var all_versions = { | ||
'latest': 'latest', | ||
'dev': 'dev', | ||
'v0.2.0': 'v0.2.0', | ||
'v0.1.2': 'v0.1.2', | ||
'v0.1.1': 'v0.1.1', | ||
'v0.1.0': 'v0.1.0', | ||
'0.0.1a0': 'v0.0.1a0', | ||
}; | ||
|
||
function build_select(current_version, current_release) { | ||
var buf = ['<select>']; | ||
|
||
$.each(all_versions, function(version, title) { | ||
buf.push('<option value="' + version + '"'); | ||
if (version == current_version) { | ||
buf.push(' selected="selected">'); | ||
if (version == "latest" || version == "dev") { | ||
buf.push(title + ' (' + current_release + ')'); | ||
} else { | ||
buf.push(current_version); | ||
} | ||
} else { | ||
buf.push('>' + title); | ||
} | ||
buf.push('</option>'); | ||
}); | ||
|
||
buf.push('</select>'); | ||
return buf.join(''); | ||
} | ||
|
||
function patch_url(url, new_version) { | ||
return url.replace(url_re, doc_url + '/' + new_version + '/'); | ||
} | ||
|
||
function on_switch() { | ||
var selected = $(this).children('option:selected').attr('value'); | ||
|
||
var url = window.location.href, | ||
new_url = patch_url(url, selected); | ||
|
||
if (new_url != url) { | ||
// check beforehand if url exists, else redirect to version's start page | ||
$.ajax({ | ||
url: new_url, | ||
success: function() { | ||
window.location.href = new_url; | ||
}, | ||
error: function() { | ||
window.location.href = 'http://' + doc_url + '/' + selected; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
$(document).ready(function() { | ||
var match = url_re.exec(window.location.href); | ||
if (match) { | ||
var release = DOCUMENTATION_OPTIONS.VERSION; | ||
var version = match[1]; | ||
var select = build_select(version, release); | ||
$('.version_switch_note').html('Or, select a version from the drop-down menu above.'); | ||
$('.version').html(select); | ||
$('.version select').bind('change', on_switch); | ||
} | ||
}); | ||
})(); |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a frontend/javascript expert, and I don't expect you to work on this. But, just pointing out that the dropdown isn't super-accessible. I managed to tab-tab-tab my way to the version changer dropdown (with the benefit of sight), and change to a different version of the documentation by pressing up/down with my arrow keys (only once though, it doesn't seem to allow scrolling through the list of options).
Guess my point here is that we should keep the section at https://www.pygmt.org/v0.2.0/index.html#documentation-for-other-versions for now just for a11y reasons, until we get a good developer that knows this stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open an issue and see if someone with good web knowledge can help us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes are online now, and you can try it at https://www.pygmt.org.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay 🎉! I see you've made the change directly at ae2aee5. Good work 👍