Browse Source

Invoke `doAfterLoad` even if page is loaded

Fixes #3.
master v0.0.27
F.W. Dekker 8 months ago
parent
commit
79b68fdb2c
Signed by: FWDekker GPG Key ID: B1B567AF58D6EE0F
  1. 2
      package.json
  2. 8
      src/main/js/Template.js

2
package.json

@ -1,6 +1,6 @@
{
"name": "@fwdekker/template",
"version": "0.0.26",
"version": "0.0.27",
"description": "The base template for pages on fwdekker.com.",
"author": "Felix W. Dekker (https://fwdekker.com)",
"license": "MIT",

8
src/main/js/Template.js

@ -27,11 +27,17 @@ export const $ = q => document.querySelector(q);
/**
* Runs the given function once the page is loaded.
*
* This function can be used multiple times. It does not overwrite existing callbacks for the page load event.
* This function can be used multiple times. It does not overwrite existing callbacks for the page load event. If the
* page has already loaded when this function is invoked, `fun` is invoked immediately inside this function.
*
* @param fun {function(...*): *} the function to run
*/
export const doAfterLoad = function (fun) {
if (document.readyState === "complete") {
fun();
return;
}
const oldOnLoad = window.onload || (() => {
});

Loading…
Cancel
Save