changeset 2401:5e1fb07919e7

Better loading dependancy block chain to ensure core.js only executes after all the other files have parsed
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 26 May 2016 16:36:06 +0100
parents 5d7ad658c699
children 6b6422523c88 52aed03f5db9 c31f73252af5
files js/core.js
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/js/core.js	Thu May 26 16:06:42 2016 +0100
+++ b/js/core.js	Thu May 26 16:36:06 2016 +0100
@@ -116,6 +116,16 @@
     }
 }
 
+var check_dependancies = function() {
+    // This will check for the data dependancies
+    if (typeof(jQuery) != "function") {return false;}
+    if (typeof(Specification) != "function") {return false;}
+    if (typeof(calculateLoudness) != "function") {return false;}
+    if (typeof(WAVE) != "function") {return false;}
+    if (typeof(validateXML) != "function") {return false;}
+    return true;
+}
+
 var onload = function() {
 	// Function called once the browser has loaded all files.
 	// This should perform any initial commands such as structure / loading documents
@@ -3229,4 +3239,12 @@
 	};
 }
 
-onload();
\ No newline at end of file
+var window_depedancy_callback;
+window_depedancy_callback = window.setInterval(function(){
+    if (check_dependancies()) {
+        window.clearInterval(window_depedancy_callback);
+        onload();
+    } else {
+        document.getElementById("topLevelBody").innerHTML = "<h1>Loading Resources</h1>";
+    }
+},100);
\ No newline at end of file