Skip to content

Commit

Permalink
Introduce Custom ihp:load Event
Browse files Browse the repository at this point in the history
  • Loading branch information
s0kil committed Feb 10, 2021
1 parent 61b2fef commit fa9aea7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Guide/view.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ Preloading with InstantClick on hover will only happen with links that

(So putting an anchor on a link, or explicitly setting the `data-turbolinks-preload` attribute to `false`, will let you selectively turn off preloading for that link.)

We provide an `ihp:load` event that will trigger when `DOMContentLoaded` or `turbolinks:load`

```javascript
document.addEventListener("ihp:load", () => {
console.log("Page Loaded");
});
```

## JSON

Views that are rendered by calling the `render` function can also respond with JSON.
Expand Down
6 changes: 6 additions & 0 deletions lib/IHP/static/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ihpLoadEvent = new Event("ihp:load")

document.addEventListener('DOMContentLoaded', function () {
initDelete();
initDisableButtonsOnSubmit();
Expand All @@ -6,6 +8,8 @@ document.addEventListener('DOMContentLoaded', function () {
initTime();
initDatePicker();
initFileUploadPreview();

document.dispatchEvent(ihpLoadEvent)
});

document.addEventListener('turbolinks:load', function () {
Expand All @@ -25,6 +29,8 @@ document.addEventListener('turbolinks:load', function () {
}, 1);

initDatePicker();

document.dispatchEvent(ihpLoadEvent)
});

function initTime() {
Expand Down

0 comments on commit fa9aea7

Please sign in to comment.