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

Fix version dropdown behavior #12632

Merged
merged 3 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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