@phillipsharring/graspr-framework 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/hooks.js +6 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phillipsharring/graspr-framework",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "HTMX + Handlebars + Tailwind frontend framework",
5
5
  "type": "module",
6
6
  "exports": {
package/src/hooks.js CHANGED
@@ -19,6 +19,8 @@ const hooks = {
19
19
  historyRestore: [],
20
20
  };
21
21
 
22
+ var pageLoaded = document.readyState !== 'loading';
23
+
22
24
  /** Register a callback that runs after #app is swapped via boosted nav. */
23
25
  export function onAfterSwap(fn) {
24
26
  hooks.afterSwap.push(fn);
@@ -29,9 +31,11 @@ export function onAfterSettle(fn) {
29
31
  hooks.afterSettle.push(fn);
30
32
  }
31
33
 
32
- /** Register a callback that runs on DOMContentLoaded (full page load only). */
34
+ /** Register a callback that runs on DOMContentLoaded (full page load only).
35
+ * If DOMContentLoaded already fired, runs immediately. */
33
36
  export function onPageLoad(fn) {
34
37
  hooks.pageLoad.push(fn);
38
+ if (pageLoaded) fn(document);
35
39
  }
36
40
 
37
41
  /** Register a callback that runs on browser back/forward (history restore). */
@@ -56,6 +60,7 @@ document.body.addEventListener('htmx:afterSettle', function(e) {
56
60
  });
57
61
 
58
62
  document.addEventListener('DOMContentLoaded', function() {
63
+ pageLoaded = true;
59
64
  hooks.pageLoad.forEach(function(fn) { fn(document); });
60
65
  });
61
66