@@ -10,8 +10,7 @@ function reRender (instance, helper) {
10
10
// https://stackoverflow.com/questions/5200545/how-to-recall-or-restart-mathjax
11
11
if (mathjax) {
12
12
if (typeof MathJax !== 'undefined') {
13
- console.debug('Triggering MathJax.Hub.Typeset()');
14
- MathJax.Hub.Queue((["Typeset", MathJax.Hub, helper.tooltip.id]));
13
+ reLoadMathJax(helper.tooltip.id);
15
14
} else {
16
15
console.debug('Not triggering MathJax because it is not defined');
17
16
};
@@ -24,7 +23,39 @@ function reRender (instance, helper) {
24
23
}
25
24
26
25
26
+ function reLoadMathJax(elementId) {
27
+ console.debug('Triggering MathJax.Hub.Typeset()');
28
+ MathJax.Hub.Queue((["Typeset", MathJax.Hub, elementId]));
29
+ }
30
+
31
+
32
+ function reLoadSphinxTabs() {
33
+ if (sphinxtabs) {
34
+ // https://github.com/djungelorm/sphinx-tabs
35
+ console.debug('Triggering Sphinx Tabs rendering');
36
+ (function(d, script) {
37
+ // HACK: please, improve this code to call the content of "tab.js" without creating a script element
38
+
39
+ // Get the URL from the current generated page since it's not always the same
40
+ var src = $('script[src$="sphinx_tabs/tabs.js"]')[0].src;
41
+
42
+ script = d.createElement('script');
43
+ script.type = 'text/javascript';
44
+ script.onload = function(){
45
+ // remote script has loaded
46
+ };
47
+ script.src = src;
48
+ d.getElementsByTagName('head')[0].appendChild(script);
49
+
50
+ // Once the script has been executed, we remove it from the DOM
51
+ script.parentNode.removeChild(script);
52
+ }(document));
53
+ };
54
+ };
55
+
56
+
27
57
$(document).ready(function() {
58
+ {% if hoverxref_tooltip or not hoverxref_modal %}
28
59
$('.hoverxref').tooltipster({
29
60
theme: {{ hoverxref_tooltip_theme }},
30
61
interactive: {{ 'true' if hoverxref_tooltip_interactive else 'false' }},
@@ -48,7 +79,6 @@ $(document).ready(function() {
48
79
// TODO: improve URL handling here
49
80
var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '§ion=' + section;
50
81
$.get(url, function(data) {
51
-
52
82
// call the 'content' method to update the content of our tooltip with the returned data.
53
83
// note: this content update will trigger an update animation (see the updateAnimation option)
54
84
instance.content(data['content']);
@@ -63,34 +93,77 @@ $(document).ready(function() {
63
93
// most of Read the Docs Sphinx theme bases its style on "rst-content".
64
94
// We add that class to the tooltipser HTML tag here by default or a user-defined one.
65
95
helper.tooltip.classList.add('{{ hoverxref_tooltip_class }}');
66
-
67
- if (sphinxtabs) {
68
- // https://github.com/djungelorm/sphinx-tabs
69
- console.debug('Triggering Sphinx Tabs rendering');
70
- (function(d, script) {
71
- // HACK: please, improve this code to call the content of "tab.js" without creating a script element
72
-
73
- // Get the URL from the current generated page since it's not always the same
74
- var src = $('script[src$="sphinx_tabs/tabs.js"]')[0].src;
75
-
76
- script = d.createElement('script');
77
- script.type = 'text/javascript';
78
- script.onload = function(){
79
- // remote script has loaded
80
- };
81
- script.src = src;
82
- d.getElementsByTagName('head')[0].appendChild(script);
83
-
84
- // Once the script has been executed, we remove it from the DOM
85
- script.parentNode.removeChild(script);
86
- }(document));
87
- };
88
-
96
+ reLoadSphinxTabs();
89
97
setTimeout(
90
98
reRender,
91
99
50,
92
100
instance,
93
101
helper
94
102
);
95
103
}
96
- })});
104
+ })
105
+ {% endif %}
106
+
107
+ {% if hoverxref_modal and not hoverxref_tooltip %}
108
+ var modalHtml = `
109
+ <div class="modal micromodal-slide {{ hoverxref_modal_class }}" id="micromodal" aria-hidden="true">
110
+ <div class="modal__overlay" tabindex="-1" data-micromodal-close>
111
+ <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="micromodal-title">
112
+ <header class="modal__header">
113
+ <h2 class="modal__title" id="micromodal-title"></h2>
114
+ <button class="modal__close" aria-label="Close modal" data-micromodal-close></button>
115
+ </header>
116
+ <main class="modal__content" id="micromodal-content"></main>
117
+ <footer class="modal__footer">
118
+ <button class="modal__btn" data-micromodal-close aria-label="Close this dialog window">Close</button>
119
+ </footer>
120
+ </div>
121
+ </div>
122
+ </div>
123
+ `
124
+ $('body').append(modalHtml);
125
+
126
+ var delay = {{ hoverxref_modal_hover_delay }}, setTimeoutConst;
127
+ $('.hoverxref').hover(function(event) {
128
+ event.preventDefault();
129
+
130
+ setTimeoutConst = setTimeout(function(){
131
+ showModal(event.target.parentNode);
132
+ }, delay);
133
+ }, function(){
134
+ clearTimeout(setTimeoutConst);
135
+ });
136
+
137
+ function showModal(element) {
138
+ var $origin = $(element);
139
+ var project = $origin.data('project');
140
+ var version = $origin.data('version');
141
+ var doc = $origin.data('doc');
142
+ var section = $origin.data('section');
143
+ console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + ' section=' + section);
144
+ var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '§ion=' + section;
145
+
146
+ $.get(url, function(data) {
147
+ var content = $('<div></div>');
148
+ content.html(data['content'][0]);
149
+
150
+ var title = $('h1', content)[0] || '';
151
+ content.replaceWith('h1', '');
152
+
153
+ $('#micromodal-title').html(title);
154
+ $('#micromodal-content').html(content);
155
+ MicroModal.show('micromodal', {
156
+ disableScroll: false,
157
+ });
158
+ reLoadSphinxTabs();
159
+ if (mathjax) {
160
+ if (typeof MathJax !== 'undefined') {
161
+ reLoadMathJax('micromodal');
162
+ } else {
163
+ console.debug('Not triggering MathJax because it is not defined');
164
+ };
165
+ };
166
+ });
167
+ };
168
+ {% endif %}
169
+ });
0 commit comments