Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Commit 10daace

Browse files
authored
Merge pull request #117 from readthedocs/humitos/update-sphinx-tabs
2 parents 797e7ff + f6399a0 commit 10daace

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

docs/requirements.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ sphinx==3.4.3 # pyup: <3.5
77

88
sphinx-autoapi==1.8.1
99
sphinx-rtd-theme==0.5.2
10-
11-
# Newer versions drop support for Sphinx<2 and
12-
# Sphinx>2 is not detecting that MathJax is enabled
13-
# and so not rendering MathJax inside the tooltips
14-
sphinx-tabs==1.1.13 # pyup: ignore
15-
10+
sphinx-tabs==2.1.0
1611
sphinx-prompt==1.4.0
1712
sphinx-version-warning==1.1.2
1813
sphinx-notfound-page==0.6

hoverxref/_static/js/hoverxref.js_t

+29-10
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,37 @@ function reLoadSphinxTabs() {
4444
// HACK: please, improve this code to call the content of "tab.js" without creating a script element
4545

4646
// Get the URL from the current generated page since it's not always the same
47-
var src = $('script[src$="sphinx_tabs/tabs.js"]')[0].src;
47+
var older_tabs_src = $('script[src$="sphinx_tabs/tabs.js"]');
48+
if (older_tabs_src.length != 0) {
49+
// sphinx-tabs < 2
50+
older_tabs_src = older_tabs_src[0].older_tabs_src
51+
script = d.createElement('script');
52+
script.type = 'text/javascript';
53+
script.onload = function(){
54+
// remote script has loaded
55+
};
56+
script.older_tabs_src = older_tabs_src;
57+
d.getElementsByTagName('head')[0].appendChild(script);
4858

49-
script = d.createElement('script');
50-
script.type = 'text/javascript';
51-
script.onload = function(){
52-
// remote script has loaded
53-
};
54-
script.src = src;
55-
d.getElementsByTagName('head')[0].appendChild(script);
59+
// Once the script has been executed, we remove it from the DOM
60+
script.parentNode.removeChild(script);
61+
}
62+
var newer_tabs_src = $('script[src$="_static/tabs.js"]');
63+
if (newer_tabs_src.length != 0) {
64+
// sphinx-tabs > 2
65+
// Borrowed from
66+
// https://github.com/executablebooks/sphinx-tabs/blob/0f3cbbe/sphinx_tabs/static/tabs.js#L8-L17
67+
var allTabs = document.querySelectorAll('.sphinx-tabs-tab');
68+
var tabLists = document.querySelectorAll('[role="tablist"]');
69+
allTabs.forEach(tab => {
70+
tab.addEventListener("click", changeTabs);
71+
});
72+
73+
tabLists.forEach(tabList => {
74+
tabList.addEventListener("keydown", keyTabs);
75+
});
76+
}
5677

57-
// Once the script has been executed, we remove it from the DOM
58-
script.parentNode.removeChild(script);
5978
}(document));
6079
};
6180
};

0 commit comments

Comments
 (0)