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

Commit

Permalink
[FEATURE] Add onload event to init Items API properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kochnev committed Dec 4, 2018
1 parent 2d4f50a commit d22f638
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions templates/init-items-js.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<script>
window.learnosityCollection = window.learnosityCollection || [];
window.learnosityCollection.push(LearnosityItems.init(<?php echo $signed_request; ?>, { errorListener: function(e) { console.log(e); } }));
// WP can add "defer" flag to <script> inside "wp_enqueue_script" function
// it might lead to the error that "LearnosityItems" below in undefined
// to protect against it, we will use "load" global event to secure that all JS assets are loaded before calling any JS code
window.addEventListener("load", function () {
window.learnosityCollection = window.learnosityCollection || [];
window.learnosityCollection.push(LearnosityItems.init(<?php echo $signed_request; ?>, {
errorListener: function (e) {
console.log(e);
}
}));
});
</script>
9 changes: 8 additions & 1 deletion templates/init-reports-js.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script>
// WP can add "defer" flag to <script> inside "wp_enqueue_script" function
// it might lead to the error that "LearnosityReports" below in undefined
// to protect against it, we will use "load" global event to secure that all JS assets are loaded before calling any JS code
window.addEventListener("load", function () {
window.learnosityCollection = window.learnosityCollection || [];
window.learnosityCollection.push(LearnosityReports.init(<?php echo $signed_request; ?>, { errorListener: function(e) { console.log(e); } }));
window.learnosityCollection.push(LearnosityReports.init(<?php echo $signed_request; ?>, {
errorListener: function (e) {
console.log(e);
}
}));
});
</script>

0 comments on commit d22f638

Please sign in to comment.