-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jQuery not available in raw HTML directive #328
Comments
Ping? |
I wanted to add
However, as it is being loaded at the end of the page, my cells cannot benefit from it. I know nothing about modern web frontend, but perhaps loading the scripts asynchronously at the top of the page would help? https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/ |
This should be fixed by #467 |
#467 was closed without merging. Is there another way this issue could be solved? |
The issue is that jQuery is loaded in the document footer rather than in the header. This means it isn't loaded when your raw directive is executed. To workaround this, you could do something like: .. raw:: html
<div id="mydiv"></div>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var element = $('#mydiv');
var text = document.createTextNode("Hello JavaScript!");
element.append(text);
});
</script> |
Thanks @jessetan, #545 is good news! @davidfischer The point is that every other theme has jQuery available at that point, the RTD theme seems to be the only exception (until #545 is done). |
Do you have an example in the wild of Jupyter or something similar that expects jQuery to be available? I assumed any large JS project that is concerned about performance expects to be loaded at the end of body. Inline scripts using |
I know of one concrete bug report (issued in different projects): spatialaudio/nbsphinx#128, poliastro/poliastro#281, readthedocs/readthedocs.org#4367 Apart from that, I think it just makes sense that the RTD Sphinx theme tries to have similar features as other popular themes always had. |
Some more info in readthedocs/readthedocs.org#4367 (comment) |
It was moved away from <head> to the bottom of the page in readthedocs#78. This is a compressed version of readthedocs#545 by @Blendify, which fixes readthedocs#328.
I would like to use jQuery in raw HTML blocks, for example
This works nicely with the Sphinx default theme and all other themes I tried, except in the RTD theme, where it gives this error:
I assume this is because jQuery is loaded in the end of the HTML page, where it was moved to in #78.
Is there a way to move jQuery back up again?
Or is there a work-around available?
My actual use case is allowing JavaScript output in pages converted from Jupyter notebooks, see spatialaudio/nbsphinx#62. JavaScript outputs in Jupyter notebooks assume that jQuery is available, see http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.Javascript.
The text was updated successfully, but these errors were encountered: