Skip to content

Commit b92ac36

Browse files
committed
Manipulate the URL in a helper and more robust function
1 parent 1385bde commit b92ac36

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
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: ' + 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]);

0 commit comments

Comments
 (0)