From ef017f8eae478270a925e0fc264f8a1982bad14e Mon Sep 17 00:00:00 2001 From: raylu Date: Thu, 10 Nov 2011 23:04:51 -0800 Subject: 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 --- js/mapspecs.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'js') 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 = ""+blocks+""; - loadSol(); - if (isChallenge) - challengeLoad(); + window.attachEvent("onload", ready); } var isChallenge = false; -- cgit v1.2.3