From 89e290f40564240a4bdd6116ccb223de5d3a0f43 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 6 Nov 2018 22:09:17 +1300 Subject: [PATCH 1/4] Update html file to use proper HTML5 meta tags --- docreadytest.html | 289 +++++++++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 147 deletions(-) diff --git a/docreadytest.html b/docreadytest.html index d01181c..761a3ba 100644 --- a/docreadytest.html +++ b/docreadytest.html @@ -1,162 +1,157 @@ - - + - - - - docReady Test Page - + function readyLoad() { + log("window load fired"); + if (!readyFired) { + log("window load firing ready"); + } + ready(); + } + // the one public interface + // docReady(fn, context); + // the context argument is optional - if present, it will be passed + // as an argument to the callback + window.docReady = function(callback, context) { + // if ready has already fired, then just schedule the callback + // to fire asynchronously, but right away + if (readyFired) { + setTimeout(function() { + callback(context); + }, 1); + return; + } else { + // add the function and context to the list + readyList.push({ + fn: callback, + ctx: context + }); + } + // if document already ready to go, schedule the ready function to run + if (document.readyState === "complete") { + setTimeout(ready, 1); + } else if (!readyEventHandlersInstalled) { + // otherwise if we don't have event handlers installed, install them + if (document.addEventListener) { + // first choice is DOMContentLoaded event + document.addEventListener("DOMContentLoaded", ready, false); + // backup is window load event + window.addEventListener("load", readyLoad, false); + } else { + // must be IE + document.attachEvent("onreadystatechange", readyStateChange); + window.attachEvent("onload", readyLoad); + } + readyEventHandlersInstalled = true; + } + } + })(); + // test basic functionality + docReady(function() { + document.body.appendChild(document.createTextNode("Hello Text 1")); + // test adding new docReady handler from a docReady callback + docReady(function() { + document.body.appendChild(document.createTextNode(", Hello Text 2")); + }); + }); + // test finding an ID in the document + docReady(function() { + document.getElementById("test").innerHTML = "Hello ID"; + }); + // test calling docReady after window load and + // docReady has already fired + addEvent(window, "load", function() { + setTimeout(function() { + document.body.appendChild(document.createTextNode(", Hello Text 2.5")); + docReady(function(arg) { + document.body.appendChild(document.createTextNode(arg)); + }, ", Hello Text 3"); + }, 1); + }); + -
-
+
+
- \ No newline at end of file + + From 03206c4f740a25b714753f42afab75018937c1d0 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 3 Oct 2022 11:57:02 +1300 Subject: [PATCH 2/4] Restore docreadytest.html --- docreadytest.html | 287 +++++++++++++++++++++++----------------------- 1 file changed, 146 insertions(+), 141 deletions(-) diff --git a/docreadytest.html b/docreadytest.html index 761a3ba..ca6ca1e 100644 --- a/docreadytest.html +++ b/docreadytest.html @@ -1,157 +1,162 @@ - - + + - - - - docReady Test Page - +// test finding an ID in the document +docReady(function() { + document.getElementById("test").innerHTML = "Hello ID"; +}); + +// test calling docReady after window load and +// docReady has already fired +addEvent(window, "load", function() { + setTimeout(function() { + document.body.appendChild(document.createTextNode(", Hello Text 2.5")); + + docReady(function(arg) { + document.body.appendChild(document.createTextNode(arg)); + }, ", Hello Text 3"); + }, 1); +}); + -
-
+
+
- From b1a0126e2c1723099f0ae65ef8876f7750977cbe Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 3 Oct 2022 11:57:22 +1300 Subject: [PATCH 3/4] Update docreadytest.html --- docreadytest.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docreadytest.html b/docreadytest.html index ca6ca1e..4534cef 100644 --- a/docreadytest.html +++ b/docreadytest.html @@ -3,6 +3,8 @@ + + docReady Test Page