From 8d259452fa874c185a2593b4660fe1a74292c2ba Mon Sep 17 00:00:00 2001 From: rylon Date: Sat, 8 Nov 2014 18:21:29 +0100 Subject: [PATCH] enforce js loading order --- files/sys/system.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/files/sys/system.js b/files/sys/system.js index b78189c..185eb25 100644 --- a/files/sys/system.js +++ b/files/sys/system.js @@ -91,15 +91,21 @@ SYSTEM.prototype.load = function(id){ system.load_css(entry['css'][i]);} //load js var call_func = true; + var loaded = 0; for(var i=0; i < entry['js'].length; i++){ system.log(system.LOG_INFO,'load js: '+entry['js'][i]); $.getScript(entry['js'][i]).done(function(response, status) { system.log(system.LOG_INFO,'load js: '+status); - var fn = window[entry['func']]; - if(call_func && typeof fn === 'function'){ - call_func = false; - fn(); - system.log(system.LOG_INFO,'call func: '+entry['func']);}}); + if(loaded++ == entry['js'].length-1){ + var fn = window[entry['func']]; + if(call_func && typeof fn === 'function'){ + call_func = false; + fn(); + system.log(system.LOG_INFO,'call func: '+entry['func']); + } else { + system.log(system.LOG_ERROR,'call func: '+entry['func']+' - fail'); + }} + }); } } });