Skip to content

Commit

Permalink
Merge pull request #22 from frontier-sh/master
Browse files Browse the repository at this point in the history
Handling injection after domready event
  • Loading branch information
peterthomson authored Sep 14, 2024
2 parents 89c89b7 + 2eb8e5b commit ea56302
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/resources/views/chart-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,26 @@
@endonce

<canvas id="{!! $element !!}" width="{!! $size['width'] !!}" height="{!! $size['height'] !!}">
<script>
document.addEventListener("DOMContentLoaded", function(event) {
<script>
(function() {
"use strict";
var ctx = document.getElementById("{!! $element !!}");
window.{!! $element !!} = new Chart(ctx, {
type: @js($type),
data: {
labels: {!! $labels !!},
datasets: {!! $datasets !!}
},
options: {!! $options !!}
});
var init = function() {
"use strict";
var ctx = document.getElementById("{!! $element !!}");
window.{!! $element !!} = new Chart(ctx, {
type: @js($type),
data: {
labels: {!! $labels !!},
datasets: {!! $datasets !!}
},
options: {!! $options !!}
});
};
if (document.readyState !== 'loading') {
init();
} else {
document.addEventListener("DOMContentLoaded", init);
}
})();
});
</script>
</script>
</canvas>

0 comments on commit ea56302

Please sign in to comment.