diff options
author | raylu <raylu@mixpanel.com> | 2011-11-10 23:04:51 -0800 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-11-10 23:05:04 -0800 |
commit | ef017f8eae478270a925e0fc264f8a1982bad14e (patch) | |
tree | 9d5321d63d8598136667bcdf6cf51718dceef8de /js | |
parent | 9f3a7ca806638f6f33387ab80d85fff5a019cc3b (diff) | |
download | pathery-ef017f8eae478270a925e0fc264f8a1982bad14e.tar.xz |
fix ready function
basically, reproduce jQuery.ready more closely
there was a race condition where the document was already ready
also, for some reason, it's necessary to bind (on)load
Diffstat (limited to 'js')
-rw-r--r-- | js/mapspecs.js | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/js/mapspecs.js b/js/mapspecs.js index 21286ee..00bde30 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -1,13 +1,22 @@ -if (document.addEventListener) // Mozilla, Opera, webkit
+var ready_done = false,
+ ready = function() {
+ if (ready_done)
+ return;
+ ready_done = true;
+ loadSol();
+ if (isChallenge)
+ challengeLoad();
+ }
+
+if (document.readyState === 'complete')
+ ready();
+else if (document.addEventListener) { // gecko, webkit, opera, IE 9
document.addEventListener("DOMContentLoaded", ready, false);
-else if (document.attachEvent) // IE
+ window.addEventListener("load", ready, false);
+}
+else if (document.attachEvent) { // IE 8-
document.attachEvent("onreadystatechange", ready);
-
-var ready = function() {
- //document.getElementById('blocksdisplay').innerHTML = "<b>"+blocks+"</b>";
- loadSol();
- if (isChallenge)
- challengeLoad();
+ window.attachEvent("onload", ready);
}
var isChallenge = false;
|