Skip to content

Commit 52a6472

Browse files
authored
Merge pull request readthedocs#67 from readthedocs/humitos/handle-embed-url
2 parents 1385bde + 2c93e78 commit 52a6472

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

hoverxref/_static/js/hoverxref.js_t

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ function reLoadSphinxTabs() {
5555
};
5656
};
5757

58+
function getEmbedURL(project, version, doc, docpath, section) {
59+
var params = {
60+
'project': project,
61+
'version': version,
62+
'doc': doc,
63+
'docpath': docpath,
64+
'section': section,
65+
}
66+
console.debug('Data: ' + JSON.stringify(params));
67+
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + $.param(params);
68+
console.debug('URL: ' + url);
69+
return url
70+
}
71+
5872

5973
$(document).ready(function() {
6074
$('.hoverxref.tooltip').tooltipster({
@@ -74,12 +88,10 @@ $(document).ready(function() {
7488
var docpath = $origin.data('docpath');
7589
var section = $origin.data('section');
7690

77-
console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + ' path=' + docpath + ' section=' + section);
7891

7992
// we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
8093
if ($origin.data('loaded') !== true) {
81-
// TODO: improve URL handling here
82-
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;
94+
var url = getEmbedURL(project, version, doc, docpath, section);
8395
$.get(url, function(data) {
8496
// call the 'content' method to update the content of our tooltip with the returned data.
8597
// note: this content update will trigger an update animation (see the updateAnimation option)
@@ -148,9 +160,8 @@ $(document).ready(function() {
148160
var doc = element.data('doc');
149161
var docpath = element.data('docpath');
150162
var section = element.data('section');
151-
console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + ' path=' + docpath + ' section=' + section);
152-
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;
153163

164+
var url = getEmbedURL(project, version, doc, docpath, section);
154165
$.get(url, function(data) {
155166
var content = $('<div></div>');
156167
content.html(data['content'][0]);

tests/test_htmltag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def test_js_render(app, status, warning):
6464
"animation: 'fade'",
6565
"animationDuration: 0",
6666
"content: 'Loading...'",
67-
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;",
67+
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + $.param(params);",
68+
"var sphinxtabs = false",
69+
"var mathjax = false",
6870
]
6971

7072
for chunk in chunks:

0 commit comments

Comments
 (0)