mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
d5203c3b42
43
src/htmx.js
43
src/htmx.js
@ -3752,25 +3752,34 @@ return (function () {
|
|||||||
//====================================================================
|
//====================================================================
|
||||||
// Initialization
|
// Initialization
|
||||||
//====================================================================
|
//====================================================================
|
||||||
var isReady = false
|
|
||||||
getDocument().addEventListener('DOMContentLoaded', function() {
|
|
||||||
isReady = true
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a function now if DOMContentLoaded has fired, otherwise listen for it.
|
* We want to initialize the page elements after DOMContentLoaded
|
||||||
*
|
* fires, but there isn't always a good way to tell whether
|
||||||
* This function uses isReady because there is no realiable way to ask the browswer whether
|
* it has already fired when we get here or not.
|
||||||
* the DOMContentLoaded event has already been fired; there's a gap between DOMContentLoaded
|
|
||||||
* firing and readystate=complete.
|
|
||||||
*/
|
*/
|
||||||
function ready(fn) {
|
function ready(functionToCall) {
|
||||||
// Checking readyState here is a failsafe in case the htmx script tag entered the DOM by
|
// call the function exactly once no matter how many times this is called
|
||||||
// some means other than the initial page load.
|
var callReadyFunction = function() {
|
||||||
if (isReady || getDocument().readyState === 'complete') {
|
if (!functionToCall) return;
|
||||||
fn();
|
functionToCall();
|
||||||
} else {
|
functionToCall = null;
|
||||||
getDocument().addEventListener('DOMContentLoaded', fn);
|
};
|
||||||
|
|
||||||
|
if (getDocument().readyState === "complete") {
|
||||||
|
// DOMContentLoaded definitely fired, we can initialize the page
|
||||||
|
callReadyFunction();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* DOMContentLoaded *maybe* already fired, wait for
|
||||||
|
* the next DOMContentLoaded or readystatechange event
|
||||||
|
*/
|
||||||
|
getDocument().addEventListener("DOMContentLoaded", function() {
|
||||||
|
callReadyFunction();
|
||||||
|
});
|
||||||
|
getDocument().addEventListener("readystatechange", function() {
|
||||||
|
if (getDocument().readyState !== "complete") return;
|
||||||
|
callReadyFunction();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user