Replace jquery by vanilla JS. · matplotlib/matplotlib@5356ef0 · GitHub
Skip to content

Commit 5356ef0

Browse files
committed
Replace jquery by vanilla JS.
This is a mix of the change in ipympl, plus the same thing for our original version of other stuff. Fixes #14596.
1 parent c46699c commit 5356ef0

6 files changed

Lines changed: 228 additions & 169 deletions

File tree

examples/user_interfaces/embedding_webagg_sgskip.py

Lines changed: 10 additions & 2 deletions

lib/matplotlib/backends/web_backend/all_figures.html

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@
1010
<script src="{{ prefix }}/js/mpl.js"></script>
1111

1212
<script>
13-
{% for (fig_id, fig_manager) in figures %}
14-
$(document).ready(
15-
function() {
16-
var main_div = $('div#figures');
17-
var figure_div = $('<div id="figure-div"/>')
18-
main_div.append(figure_div);
13+
function ready(fn) {
14+
if (document.readyState != "loading") {
15+
fn();
16+
} else {
17+
document.addEventListener("DOMContentLoaded", fn);
18+
}
19+
}
20+
21+
function figure_ready(fig_id) {
22+
return function () {
23+
var main_div = document.querySelector("div#figures");
24+
var figure_div = document.createElement("div");
25+
figure_div.id = "figure-div";
26+
main_div.appendChild(figure_div);
1927
var websocket_type = mpl.get_websocket_type();
20-
var websocket = new websocket_type(
21-
"{{ ws_uri }}" + "{{ fig_id }}" + "/ws");
22-
var fig = new mpl.figure(
23-
"{{ fig_id }}", websocket, mpl_ondownload, figure_div);
28+
var websocket = new websocket_type("{{ ws_uri }}" + fig_id + "/ws");
29+
var fig = new mpl.figure(fig_id, websocket, mpl_ondownload, figure_div);
2430

2531
fig.focus_on_mouseover = true;
2632

27-
$(fig.canvas).attr('tabindex', {{ fig_id }});
28-
}
29-
);
33+
fig.canvas.setAttribute("tabindex", fig_id);
34+
}
35+
};
3036

31-
{% end %}
37+
{% for (fig_id, fig_manager) in figures %}
38+
ready(figure_ready({{ repr(str(fig_id)) }}));
39+
{% end %}
3240
</script>
3341

3442
<title>MPL | WebAgg current figures</title>

lib/matplotlib/backends/web_backend/ipython_inline_figure.html

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)