Skip to content

Commit

Permalink
Merge pull request #67 from readthedocs/humitos/handle-embed-url
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos authored Apr 24, 2020
2 parents 1385bde + 2c93e78 commit 52a6472
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 16 additions & 5 deletions hoverxref/_static/js/hoverxref.js_t
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ function reLoadSphinxTabs() {
};
};

function getEmbedURL(project, version, doc, docpath, section) {
var params = {
'project': project,
'version': version,
'doc': doc,
'docpath': docpath,
'section': section,
}
console.debug('Data: ' + JSON.stringify(params));
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + $.param(params);
console.debug('URL: ' + url);
return url
}


$(document).ready(function() {
$('.hoverxref.tooltip').tooltipster({
Expand All @@ -74,12 +88,10 @@ $(document).ready(function() {
var docpath = $origin.data('docpath');
var section = $origin.data('section');

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

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

var url = getEmbedURL(project, version, doc, docpath, section);
$.get(url, function(data) {
var content = $('<div></div>');
content.html(data['content'][0]);
Expand Down
4 changes: 3 additions & 1 deletion tests/test_htmltag.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def test_js_render(app, status, warning):
"animation: 'fade'",
"animationDuration: 0",
"content: 'Loading...'",
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&path=' + docpath + '&section=' + section;",
"var url = 'https://readthedocs.org' + '/api/v2/embed/?' + $.param(params);",
"var sphinxtabs = false",
"var mathjax = false",
]

for chunk in chunks:
Expand Down

0 comments on commit 52a6472

Please sign in to comment.