Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit a6871a4

Browse files
Standardize load handlers.
In js files use $(function) instead of deprecated $(document).ready(function). It gracefully handles situations in which the scripts are loaded after window.load has already fired. In code in html or injected into html, use window.load to guarantee script availability
1 parent 241ee51 commit a6871a4

16 files changed

Lines changed: 18 additions & 19 deletions

File tree

runestone/activecode/js/activecode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class ActiveCode extends RunestoneBase {
132132
);
133133
if (this.autorun) {
134134
// Simulate pressing the run button, since this will also prevent the user from clicking it until the initial run is complete, and also help the user understand why they're waiting.
135-
$(document).ready(this.runButtonHandler.bind(this));
135+
$(this.runButtonHandler.bind(this));
136136
}
137137
this.indicate_component_ready();
138138
}

runestone/animation/chart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// $("#visualization").gchart({type: 'graphviz', series: [$.gchart.series([20, 50, 30])]});
1919
// label: '<f0> left | <f1> middle | <f2> right'
2020

21-
document.addEventListener('load', (event) => {
21+
window.addEventListener('load', (event) => {
2222
$('#visualization').gchart($.gchart.graphviz(true,
2323
{
2424
struct1: {label: '<f0> left |<f1> middle |<f2> right'},

runestone/animation/jqchart/gChartBasic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
1010
<script src="jquery.gchart.js"></script>
1111
<script>
12-
document.addEventListener('load', (event) => {
12+
window.addEventListener('load', (event) => {
1313
$(function () {
1414
$('#basicGChart').gchart({type: 'line', maxValue: 40,
1515
title: 'Weather for|Brisbane, Australia', titleColor: 'green',

runestone/codelens/js/codelens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if (typeof allVsualizers === "undefined") {
4949
window.allVisualizers = [];
5050
}
5151

52-
$(document).ready(function () {
52+
$(function () {
5353
if (typeof allTraceData !== "undefined") {
5454
for (let divid in allTraceData) {
5555
let cl = document.getElementById(divid);
@@ -69,7 +69,7 @@ $(document).ready(function () {
6969
console.log(err);
7070
}
7171
}
72-
document.addEventListener("codelens:answer", function (evt) {
72+
window.addEventListener("codelens:answer", function (evt) {
7373
let rb = new RunestoneBase();
7474
rb.logBookEvent({
7575
event: "codelens",

runestone/common/js/bookfuncs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function notifyRunestoneComponents() {
222222
}
223223

224224
// initialize stuff
225-
$(document).ready(function () {
225+
$(function () {
226226
if (eBookConfig) {
227227
handlePageSetup();
228228
} else {
@@ -236,7 +236,7 @@ $(document).ready(function () {
236236

237237
// misc stuff
238238
// todo: This could be further distributed but making a video.js file just for one function seems dumb.
239-
$(document).ready(function () {
239+
window.addEventListener("load", function () {
240240
// add the video play button overlay image
241241
$(".video-play-overlay").each(function () {
242242
$(this).css(

runestone/common/js/presenter_mode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ function configureCodelens() {
211211
}
212212
}
213213

214-
//$(document).ready(configure);
215214
$(document).bind("runestone:login-complete", function () {
216215
// if user is instructor, enable presenter mode
217216
if (eBookConfig.isInstructor) {

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
{% endif %}
392392

393393
<script>
394-
document.addEventListener('load', (event) => {
394+
window.addEventListener('load', (event) => {
395395
runestoneComponents.getSwitch();
396396
});
397397
</script>

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/progress.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
document.getElementById("progressBar").style.width = book.curChapterPercent-1 + "%";
6666
}
6767
}
68-
document.addEventListener('DOMContentLoaded', function() {
68+
window.addEventListener('load', function() {
6969
loadProgressBar();
7070
}, false);
7171
</script>

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/relations.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'delay': { show: 100, hide: 50}
2626
};
2727

28-
document.addEventListener('load', (event) => {
28+
window.addEventListener('load', (event) => {
2929
$('#relations-prev').tooltip(opts);
3030
$('#relations-next').tooltip(opts);
3131
});

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/static/bootstrap-sphinx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
.attr("border", 0);
5252
};
5353

54-
$(document).ready(function () {
54+
$(function () {
5555

5656
/*
5757
* Scroll the window to avoid the topnav bar

0 commit comments

Comments
 (0)