Fix toc link (#6148)
diff --git a/docs/_static/js/sidebar.js b/docs/_static/js/sidebar.js
index 54798b6..73c56d7 100644
--- a/docs/_static/js/sidebar.js
+++ b/docs/_static/js/sidebar.js
@@ -12,8 +12,8 @@
function render_left_helper(toc, currentText) {
var lefttoc = toc;
var currentText = currentText, trailing = ' Documents';
- if(currentText.endsWith(trailing)) currentText = currentText.substring(0, currentText.length - trailing.length);
- if(currentText == 'System') currentText = 'Architecture';
+ if (currentText.endsWith(trailing)) currentText = currentText.substring(0, currentText.length - trailing.length);
+ if (currentText == 'System') currentText = 'Architecture';
lefttoc.addClass('current');
$('.leftsidebar > .sphinxsidebarwrapper').children().remove();
@@ -31,17 +31,25 @@
/*Render content tree of different pages*/
function render_lefttoc() {
var url = window.location.href, indexTrailing = 'index.html';
- if(url.indexOf(indexTrailing) == -1) {
+ if (url.indexOf(indexTrailing) == -1) {
for(var i = 0; i < TITLE_WITH_LANG.length; ++i) {
var path = TITLE_WITH_LANG[i];
- if(url.indexOf(path) != -1) {
- $.get('http://' + window.location.host + path + indexTrailing, null, function(data) {
+ if (url.indexOf(path) != -1) {
+ var urlPath = 'http://' + window.location.host + path;
+ $.get(urlPath + indexTrailing, null, function(data) {
var currentText = $($.parseHTML(data)).find('.leftsidebar > .sphinxsidebarwrapper > ul.current > li.current > a').html();
- if(isAPI) {
+ if (isAPI) {
render_left_helper($($.parseHTML(data)).find('#table-of-contents > div > ul'), currentText);
}
else {
render_left_helper($($.parseHTML(data)).find('.leftsidebar > .sphinxsidebarwrapper > ul.current > li.current > ul'), currentText);
+ var tocLink = $('.leftsidebar .sphinxsidebarwrapper .leaf a');
+ var staticLink = 'http';
+ tocLink.each(function () {
+ if (!$(this).attr('href').startsWith(staticLink)) {
+ $(this).attr('href', urlPath + $(this).attr('href'));
+ }
+ });
}
keepExpand();
$('.sphinxsidebar').css("visibility", "visible");
@@ -72,7 +80,7 @@
$(this).css('color', '#337ab7');
});
- if(url.indexOf(indexTrailing) != -1 || isAPI) {
+ if (url.indexOf(indexTrailing) != -1 || isAPI) {
$('.rightsidebar').hide();
}
}
@@ -83,10 +91,10 @@
var links = $('.rightsidebar a');
for(var i = 1; i < links.length; ++i) {
var divID = links.eq(i).attr('href');
- if($(divID).offset().top - $(window).scrollTop() > navbarHeight) {
+ if ($(divID).offset().top - $(window).scrollTop() > navbarHeight) {
$('.rightsidebar a').css('color', 'black');
links.eq(i - 1).css('color', '#337ab7');
- if(!links.eq(i - 1).parent().hasClass('leaf')) {
+ if (!links.eq(i - 1).parent().hasClass('leaf')) {
links.eq(i - 1).parent().removeClass('closed');
links.eq(i - 1).parent().addClass('opened');
links.eq(i - 1).parent().find('ul').first().show();
@@ -100,7 +108,7 @@
function addToggle(tocClass) {
var allEntry = $(tocClass + " div.sphinxsidebarwrapper li");
var subEntry = $(tocClass + " div.sphinxsidebarwrapper").children("ul").first().children("li");
- if(subEntry.length == 1) {
+ if (subEntry.length == 1) {
subEntry.prepend("<span class='tocToggle' onclick='toggle(this)'></span>");
subEntry.addClass('opened');
allEntry = subEntry.find("li");
@@ -111,7 +119,7 @@
allEntry.each(function () {
$(this).prepend("<span class='tocToggle' onclick='toggle(this)'></span>");
var childUL = $(this).find("ul");
- if(childUL.length && childUL.first().children().length) {
+ if (childUL.length && childUL.first().children().length) {
$(this).addClass("closed");
$(this).find("ul").first().hide();
}
@@ -125,11 +133,11 @@
/*Sidebar toc toggle button behavior*/
function toggle(elem) {
- if($(elem).parent().hasClass("closed")) {
+ if ($(elem).parent().hasClass("closed")) {
$(elem).parent().find("ul").first().show();
$(elem).parent().removeClass("closed").addClass("opened");
}
- else if($(elem).parent().hasClass("opened")) {
+ else if ($(elem).parent().hasClass("opened")) {
$(elem).parent().find("ul").first().hide();
$(elem).parent().removeClass("opened").addClass("closed");
}
@@ -153,15 +161,15 @@
var entryList = isAPI ? $('.leftsidebar li') : $('.sphinxsidebar li');
for(var i = entryList.length - 1; i >= 0; --i) {
var entryURL = entryList.eq(i).find('a').first().attr('href');
- if(entryURL != '#' && url.indexOf(entryURL) != -1) {
+ if (entryURL != '#' && url.indexOf(entryURL) != -1) {
currentEntry = entryList.eq(i);
break;
}
}
- if(isAPI) {
+ if (isAPI) {
var rootEntry = currentEntry;
- if(rootEntry.parent().parent().is('li')) rootEntry = rootEntry.parent().parent();
+ if (rootEntry.parent().parent().is('li')) rootEntry = rootEntry.parent().parent();
rootEntry.children("ul").first().remove();
rootEntry.append($('.rightsidebar .sphinxsidebarwrapper > ul > li > ul').clone());
var allEntry = $(".leftsidebar div.sphinxsidebarwrapper li");
@@ -172,7 +180,7 @@
});
});
$('.sphinxsidebar li').each(function () {
- if(url.endsWith($(this).find('a').first().attr('href'))) {
+ if (url.endsWith($(this).find('a').first().attr('href'))) {
currentEntry = $(this);
return false;
}
@@ -184,7 +192,7 @@
}
currentEntry.find('a').first().css('color', '#337ab7');
currentEntry.children("ul").first().show();
- if(!currentEntry.hasClass('leaf')) currentEntry.removeClass("closed").addClass("opened");
+ if (!currentEntry.hasClass('leaf')) currentEntry.removeClass("closed").addClass("opened");
while(currentEntry.parent().is('ul') && currentEntry.parent().parent().is('li')) {
currentEntry = currentEntry.parent().parent();
currentEntry.removeClass("closed").addClass("opened");
@@ -195,15 +203,15 @@
$(document).ready(function () {
var url = window.location.href, searchFlag = 'search.html';
- if(url.indexOf(searchFlag) == -1) {
+ if (url.indexOf(searchFlag) == -1) {
for(var i = 0; i < API_PAGE.length; ++i) {
- if(url.indexOf('/api/' + API_PAGE[i]) != -1) {
+ if (url.indexOf('/api/' + API_PAGE[i]) != -1) {
isAPI = true;
break;
}
}
render_righttoc();
- if($('.leftsidebar').length) render_lefttoc();
+ if ($('.leftsidebar').length) render_lefttoc();
}
$(window).scroll(function () {
scroll_righttoc();