Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b94812c

Browse files
authored
Merge pull request #17053 from QuLogic/no-jquery
Replace most jQuery with vanilla JavaScript
2 parents 355cd3d + 4a1bc03 commit b94812c

File tree

6 files changed

+229
-180
lines changed

6 files changed

+229
-180
lines changed

examples/user_interfaces/embedding_webagg_sgskip.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ def create_figure():
7171
window.open('download.' + format, '_blank');
7272
};
7373
74-
$(document).ready(
74+
function ready(fn) {
75+
if (document.readyState != "loading") {
76+
fn();
77+
} else {
78+
document.addEventListener("DOMContentLoaded", fn);
79+
}
80+
}
81+
82+
ready(
7583
function() {
7684
/* It is up to the application to provide a websocket that the figure
7785
will use to communicate to the server. This websocket object can
@@ -89,7 +97,7 @@ def create_figure():
8997
// A function called when a file type is selected for download
9098
ondownload,
9199
// The HTML element in which to place the figure
92-
$('div#figure'));
100+
document.getElementById("figure"));
93101
}
94102
);
95103
</script>

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({{ 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
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
function init_figure{{ fig_id }}(e) {
1313
$('div.output').off('resize');
1414

15-
var output_div = $(e.target).find('div.output_subarea');
15+
var output_div = e.target.querySelector('div.output_subarea');
1616
var websocket_type = mpl.get_websocket_type();
1717
var websocket = new websocket_type(
1818
"ws://" + window.location.hostname + ":{{ port }}{{ prefix}}/" +

0 commit comments

Comments
 (0)