From b92ac36d652eeeec997e330017288d933bf002a4 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Sat, 18 Apr 2020 14:47:46 +0200 Subject: [PATCH 1/4] Manipulate the URL in a helper and more robust function --- hoverxref/_static/js/hoverxref.js_t | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hoverxref/_static/js/hoverxref.js_t b/hoverxref/_static/js/hoverxref.js_t index 10aaf82c..547a845b 100644 --- a/hoverxref/_static/js/hoverxref.js_t +++ b/hoverxref/_static/js/hoverxref.js_t @@ -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: ' + params); + var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + $.param(params); + console.debug('URL: ' + url); + return url +} + $(document).ready(function() { $('.hoverxref.tooltip').tooltipster({ @@ -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 + '§ion=' + 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) @@ -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 + '§ion=' + section; + var url = getEmbedURL(project, version, doc, docpath, section); $.get(url, function(data) { var content = $('
'); content.html(data['content'][0]); From e852ad8b00dcf0e48970dfe1e54a99b48680c6da Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Sat, 18 Apr 2020 20:51:55 +0200 Subject: [PATCH 2/4] Log `params` nicely --- hoverxref/_static/js/hoverxref.js_t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hoverxref/_static/js/hoverxref.js_t b/hoverxref/_static/js/hoverxref.js_t index 547a845b..19542005 100644 --- a/hoverxref/_static/js/hoverxref.js_t +++ b/hoverxref/_static/js/hoverxref.js_t @@ -63,7 +63,7 @@ function getEmbedURL(project, version, doc, docpath, section) { 'docpath': docpath, 'section': section, } - console.debug('Data: ' + params); + console.debug('Data: ' + JSON.stringify(params)); var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + $.param(params); console.debug('URL: ' + url); return url From e34e8dbcd21f4cad54f2d8c84daa41f2027b5c4b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 20 Apr 2020 22:34:36 +0200 Subject: [PATCH 3/4] Fix URL test and add two small more --- tests/test_htmltag.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_htmltag.py b/tests/test_htmltag.py index 6077d369..8d0489ad 100644 --- a/tests/test_htmltag.py +++ b/tests/test_htmltag.py @@ -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 + '§ion=' + section;", + "var url = 'https://readthedocs.org' + '/api/v2/embed/?' + $.param(params);", + "var sphinxtabs = 'false'", + "var mathjax = 'false'", ] for chunk in chunks: From 2c93e7853024b348528e59c5a1241f8fc0ec009b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Fri, 24 Apr 2020 16:33:51 +0200 Subject: [PATCH 4/4] Fix JS test --- tests/test_htmltag.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_htmltag.py b/tests/test_htmltag.py index 8d0489ad..37287b0a 100644 --- a/tests/test_htmltag.py +++ b/tests/test_htmltag.py @@ -65,8 +65,8 @@ def test_js_render(app, status, warning): "animationDuration: 0", "content: 'Loading...'", "var url = 'https://readthedocs.org' + '/api/v2/embed/?' + $.param(params);", - "var sphinxtabs = 'false'", - "var mathjax = 'false'", + "var sphinxtabs = false", + "var mathjax = false", ] for chunk in chunks: