Skip to content

Commit 3b01fbe

Browse files
authored
Drop JavaScript Frameworks (sphinx-doc#10028)
* Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
1 parent 444dfc5 commit 3b01fbe

File tree

20 files changed

+2777
-1507
lines changed

20 files changed

+2777
-1507
lines changed

.github/workflows/nodejs.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
env:
9-
node-version: 10.7
9+
node-version: 16
1010

1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Use Node.js ${{ env.node-version }}
14-
uses: actions/setup-node@v1
14+
uses: actions/setup-node@v2
1515
with:
1616
node-version: ${{ env.node-version }}
17+
cache: "npm"
1718
- run: npm install
1819
- name: Run headless test
1920
uses: GabrielBB/xvfb-action@v1

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Other co-maintainers:
1818

1919
Other contributors, listed alphabetically, are:
2020

21+
* Adam Turner -- JavaScript improvements
2122
* Alastair Houghton -- Apple Help builder
2223
* Alexander Todorov -- inheritance_diagram tests and improvements
2324
* Andi Albrecht -- agogo theme

CHANGES

+20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ Incompatible changes
2727
Deprecated
2828
----------
2929

30+
* #10028: jQuery and underscore.js will no longer be automatically injected into
31+
themes from Sphinx 6.0. If you develop a theme or extension that uses the
32+
``jQuery``, ``$``, or ``$u`` global objects, you need to update your
33+
JavaScript or use the mitigation below.
34+
35+
To re-add jQuery and underscore.js, you will need to copy ``jquery.js`` and
36+
``underscore.js`` from `the Sphinx repository`_ to your ``static`` directory,
37+
and add the following to your ``layout.html``:
38+
39+
.. _the Sphinx repository: https://github.com/sphinx-doc/sphinx/tree/v4.3.2/sphinx/themes/basic/static
40+
.. code-block:: html+jinja
41+
42+
{%- block scripts %}
43+
<script src="{{ pathto('_static/jquery.js', resource=True) }}"></script>
44+
<script src="{{ pathto('_static/underscore.js', resource=True) }}"></script>
45+
{{ super() }}
46+
{%- endblock %}
3047
* setuptools integration. The ``build_sphinx`` sub-command for setup.py is
3148
marked as deprecated to follow the policy of setuptools team.
3249
* The ``locale`` argument of ``sphinx.util.i18n:babel_format_date()`` becomes
@@ -41,6 +58,9 @@ Features added
4158
* #9075: autodoc: The default value of :confval:`autodoc_typehints_format` is
4259
changed to ``'smart'``. It will suppress the leading module names of
4360
typehints (ex. ``io.StringIO`` -> ``StringIO``).
61+
* #10028: Removed internal usages of JavaScript frameworks (jQuery and
62+
underscore.js) and modernised ``doctools.js`` and ``searchtools.js`` to
63+
EMCAScript 2018.
4464

4565
Bugs fixed
4666
----------

doc/_templates/indexsidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h3>{%trans%}Questions? Suggestions?{%endtrans%}</h3>
1414
<form action="https://groups.google.com/group/sphinx-users/boxsubscribe"
1515
class="subscribeform">
1616
<input type="text" name="email" value="your@email"
17-
onfocus="$(this).val('');" />
17+
onfocus="this.value = ''" />
1818
<input type="submit" name="sub" value="Subscribe" />
1919
</form>
2020
</div>

doc/_themes/sphinx13/layout.html

+13-16
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,28 @@
2727
</style>
2828
<script>
2929
// intelligent scrolling of the sidebar content
30-
$(window).scroll(function() {
31-
var sb = $('.sphinxsidebarwrapper');
32-
var win = $(window);
33-
var sbh = sb.height();
34-
var offset = $('.sphinxsidebar').position()['top'];
35-
var wintop = win.scrollTop();
36-
var winbot = wintop + win.innerHeight();
37-
var curtop = sb.position()['top'];
38-
var curbot = curtop + sbh;
30+
window.onscroll = () => {
31+
const sb = document.getElementsByClassName('sphinxsidebarwrapper')[0]
32+
const sbh = sb.offsetHeight
33+
const offset = document.getElementsByClassName('sphinxsidebar')[0].offsetTop;
34+
const wintop = window.scrollTop;
35+
const winbot = wintop + window.offsetHeight
36+
const curtop = sb.offsetTop;
37+
const curbot = curtop + sbh;
3938
// does sidebar fit in window?
40-
if (sbh < win.innerHeight()) {
39+
if (sbh < window.offsetHeight) {
4140
// yes: easy case -- always keep at the top
42-
sb.css('top', $u.min([$u.max([0, wintop - offset - 10]),
43-
$(document).height() - sbh - 200]));
41+
sb.style.top = Math.min(Math.max(0, wintop - offset - 10), window.innerHeight - sbh - 200)
4442
} else {
4543
// no: only scroll if top/bottom edge of sidebar is at
4644
// top/bottom edge of window
4745
if (curtop > wintop && curbot > winbot) {
48-
sb.css('top', $u.max([wintop - offset - 10, 0]));
46+
sb.style.top = Math.max(wintop - offset - 10, 0)
4947
} else if (curtop < wintop && curbot < winbot) {
50-
sb.css('top', $u.min([winbot - sbh - offset - 20,
51-
$(document).height() - sbh - 200]));
48+
sb.style.top = Math.min(winbot - sbh - offset - 20, window.innerHeight - sbh - 200)
5249
}
5350
}
54-
});
51+
}
5552
</script>
5653
{%- endif %}
5754
{% endblock %}

karma.conf.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module.exports = function(config) {
1515

1616
// list of files / patterns to load in the browser
1717
files: [
18-
'sphinx/themes/basic/static/underscore.js',
19-
'sphinx/themes/basic/static/jquery.js',
2018
'sphinx/themes/basic/static/doctools.js',
2119
'sphinx/themes/basic/static/searchtools.js',
2220
'tests/js/*.js'
@@ -59,7 +57,7 @@ module.exports = function(config) {
5957

6058
// start these browsers
6159
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62-
browsers: ['Chrome', 'Firefox'],
60+
browsers: ["Firefox"],
6361

6462

6563
// Continuous Integration mode

0 commit comments

Comments
 (0)