Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit d22f638

Browse files
author
Dmitry Kochnev
committed
[FEATURE] Add onload event to init Items API properly
1 parent 2d4f50a commit d22f638

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

templates/init-items-js.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<script>
2-
window.learnosityCollection = window.learnosityCollection || [];
3-
window.learnosityCollection.push(LearnosityItems.init(<?php echo $signed_request; ?>, { errorListener: function(e) { console.log(e); } }));
2+
// WP can add "defer" flag to <script> inside "wp_enqueue_script" function
3+
// it might lead to the error that "LearnosityItems" below in undefined
4+
// to protect against it, we will use "load" global event to secure that all JS assets are loaded before calling any JS code
5+
window.addEventListener("load", function () {
6+
window.learnosityCollection = window.learnosityCollection || [];
7+
window.learnosityCollection.push(LearnosityItems.init(<?php echo $signed_request; ?>, {
8+
errorListener: function (e) {
9+
console.log(e);
10+
}
11+
}));
12+
});
413
</script>

templates/init-reports-js.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<script>
2+
// WP can add "defer" flag to <script> inside "wp_enqueue_script" function
3+
// it might lead to the error that "LearnosityReports" below in undefined
4+
// to protect against it, we will use "load" global event to secure that all JS assets are loaded before calling any JS code
25
window.addEventListener("load", function () {
36
window.learnosityCollection = window.learnosityCollection || [];
4-
window.learnosityCollection.push(LearnosityReports.init(<?php echo $signed_request; ?>, { errorListener: function(e) { console.log(e); } }));
7+
window.learnosityCollection.push(LearnosityReports.init(<?php echo $signed_request; ?>, {
8+
errorListener: function (e) {
9+
console.log(e);
10+
}
11+
}));
512
});
613
</script>

0 commit comments

Comments
 (0)