Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix version dropdown behavior (#12632)
Browse files Browse the repository at this point in the history
* sets the version dropdown to retain current doc location

* handle rewrites for anchor links

* support master version redirects
  • Loading branch information
aaronmarkham authored and nswamy committed Sep 22, 2018
1 parent 9f14a68 commit 6614b0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions docs/_static/js/docversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function setVersion(){
let doc = window.location.pathname.match(/^\/(api\/.*)$/) || window.location.pathname.match(/^\/versions\/[^*]+\/(api\/.*)$/);
if (doc) {
if (document.getElementById('dropdown-menu-position-anchor-version')) {
versionNav = $('#dropdown-menu-position-anchor-version a.main-nav-link');
$(versionNav).each( function( index, el ) {
currLink = $( el ).attr('href');
version = currLink.match(/\/versions\/([0-9.master]+)\//);
if (version) {
versionedDoc = '/versions/' + version[1] + '/' + doc[1] + (window.location.hash || '');
$( el ).attr('href', versionedDoc);
}
});
}
}
}

$(document).ready(function () {
setVersion();
});

$('a.reference.internal').click(function(){
setVersion();
});
1 change: 1 addition & 0 deletions docs/_static/mxnet-theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<script type="text/javascript" src="{{ pathto('_static/js/clipboard.min.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/js/copycode.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/js/page.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/js/docversion.js', 1) }}"></script>
<script type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
Expand Down
2 changes: 1 addition & 1 deletion docs/build_version_doc/AddVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'style="position: relative">' \
'<a href="#" tabindex="-1">Versions(%s)</a><ul class="dropdown-menu">' % (args.current_version)
for i, tag in enumerate(tag_list):
url = root_url if tag == args.tag_default else root_url + 'versions/%s/index.html' % (tag)
url = root_url + 'versions/%s/index.html' % (tag)
version_str += '<li><a class="main-nav-link" href=%s>%s</a></li>' % (url, tag)
version_str_mobile += '<li><a tabindex="-1" href=%s>%s</a></li>' % (url, tag)
version_str += '</ul></span>'
Expand Down

0 comments on commit 6614b0c

Please sign in to comment.