Skip to content

Commit 75eb682

Browse files
committed
Check for theme using sphinx html_theme config
1 parent dfdaba3 commit 75eb682

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

hoverxref/_static/js/hoverxref.js_t

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var mathjax = {{ 'true' if hoverxref_mathjax else 'false' }};
22
var sphinxtabs = {{ 'true' if hoverxref_sphinxtabs else 'false' }};
3+
{% set sphinx_rtd_theme = 'true' if html_theme == 'sphinx_rtd_theme' else 'false' %}
4+
35

46
function reRenderTooltip (instance, helper) {
57
// Check if the content is the same as the default content until
@@ -124,23 +126,23 @@ $(document).ready(function() {
124126
`
125127
$('body').append(modalHtml);
126128

129+
{% if sphinx_rtd_theme %}
127130
function onShow(modal, element) {
128-
if (typeof READTHEDOCS_DATA !== 'undefined' && READTHEDOCS_DATA.theme == 'sphinx_rtd_theme') {
129-
// This is a HACK to get some "smart" left position of the
130-
// modal depending its size.
131-
var container = $('#micromodal .modal__container')
132-
var maxWidth = $('.wy-nav-content').innerWidth() - 150;
133-
var contentLeft = $('.wy-nav-content').position().left;
134-
if (container.width() >= maxWidth) {
135-
var left = contentLeft - 150;
136-
}
137-
else {
138-
var left = contentLeft + 150;
139-
}
140-
console.debug('Container left position: ' + left);
141-
container.css('left', left);
131+
// This is a HACK to get some "smart" left position of the
132+
// modal depending its size.
133+
var container = $('#micromodal .modal__container')
134+
var maxWidth = $('.wy-nav-content').innerWidth() - 150;
135+
var contentLeft = $('.wy-nav-content').position().left;
136+
if (container.width() >= maxWidth) {
137+
var left = contentLeft - 150;
138+
}
139+
else {
140+
var left = contentLeft + 150;
142141
}
142+
console.debug('Container left position: ' + left);
143+
container.css('left', left);
143144
}
145+
{% endif %}
144146

145147
function showModal(element) {
146148
var project = element.data('project');
@@ -168,7 +170,9 @@ $(document).ready(function() {
168170
$('#micromodal-title').html(a);
169171
$('#micromodal-content').html(content);
170172
MicroModal.show('micromodal', {
173+
{% if sphinx_rtd_theme or hoverxref_modal_onshow_function %}
171174
onShow: {{ hoverxref_modal_onshow_function|default('onShow', true) }},
175+
{% endif %}
172176
openClass: '{{ hoverxref_modal_openclass }}',
173177
disableScroll: {{ 'true' if hoverxref_modal_disable_scroll else 'false' }},
174178
disableFocus: {{ 'true' if hoverxref_modal_disable_focus else 'false' }},

hoverxref/extension.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def copy_asset_files(app, exception):
5353
# Then, add the values that the user overrides
5454
context[attr] = getattr(app.config, attr)
5555

56+
# Finally, add some non-hoverxref extra configs
57+
configs = ['html_theme']
58+
for attr in configs:
59+
context[attr] = getattr(app.config, attr)
60+
5661
for f in ASSETS_FILES:
5762
path = os.path.join(os.path.dirname(__file__), '_static', f)
5863
copy_asset(

0 commit comments

Comments
 (0)