Skip to content

Commit

Permalink
Detect DOMContentLoaded in FF3.5 and before
Browse files Browse the repository at this point in the history
  • Loading branch information
Tero Piirainen committed Dec 31, 2010
1 parent ce0a145 commit 6829b05
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

var head = doc.documentElement,
ie = navigator.userAgent.toLowerCase().indexOf("msie") != -1,
ready = false, // is HEAD "ready"
ready = false, // is HEAD "ready"
queue = [], // if not -> defer execution
handlers = {}, // user functions waiting for events
handlers = {}, // user functions waiting for events
scripts = {}; // loadable scripts in different states


Expand Down Expand Up @@ -90,6 +90,7 @@
};
*/

/*** private functions ***/
function toLabel(url) {
var els = url.split("/"),
name = els[els.length -1],
Expand All @@ -98,8 +99,6 @@
return i != -1 ? name.substring(0, i) : name;
}


/*** private functions ***/
function getScript(url) {

var script;
Expand Down Expand Up @@ -225,7 +224,7 @@

}

// if callback == true --> preload

function scriptTag(src, callback) {

var elem = doc.createElement('script');
Expand All @@ -245,7 +244,7 @@
}

/*
Start after a small delay: guessing that the the head tag needs to be closed
Start after HEAD tag is closed
*/
setTimeout(function() {
ready = true;
Expand All @@ -254,5 +253,14 @@
});
}, 200);



// required: shim for FF <= 3.5 not having document.readyState
if (doc.readyState == null && doc.addEventListener) {
doc.readyState = "loading";
doc.addEventListener("DOMContentLoaded", handler = function () {
doc.removeEventListener("DOMContentLoaded", handler, false);
doc.readyState = "complete";
}, false);
}

})(document);

0 comments on commit 6829b05

Please sign in to comment.