From 2342988071eec0468af2ea8f6814d5cbf8575015 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 26 Nov 2012 07:28:02 -0500 Subject: [PATCH] added ability to load a couple scripts after one main is loaded in any position in anyLoadOnLoad function --- lib/client/dom.js | 28 ++++++++++++++++------------ lib/client/editor/_codemirror.js | 24 +++++++++++++----------- lib/client/storage/_github.js | 23 +++++++++++------------ 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 5c13b219..4ee89d94 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -91,7 +91,7 @@ var CloudCommander, Util, DOM, CloudFunc; return lRet_b; }; - /** + /** * safe add event listener * @param pType * @param pListener @@ -100,7 +100,7 @@ var CloudCommander, Util, DOM, CloudFunc; */ DOM.addListener = function(pType, pListener, pUseCapture, pElement){ return (pElement || document).addEventListener( - pType, + pType, pListener, pUseCapture || false ); @@ -251,16 +251,20 @@ var CloudCommander, Util, DOM, CloudFunc; */ DOM.anyLoadOnLoad = function(pParams_a, pFunc){ if( Util.isArray(pParams_a) ) { - var lParam = pParams_a.pop(); - - if(Util.isString(lParam) ) - lParam = { src : lParam }; - - - if(lParam && !lParam.func){ - lParam.func = function(){ + var lParam = pParams_a.pop(), + lFunc = function(){ DOM.anyLoadOnLoad(pParams_a, pFunc); }; + + if( Util.isString(lParam) ) + lParam = { src : lParam }; + else if( Util.isArray(lParam) ){ + + DOM.anyLoadInParallel(lParam, lFunc); + } + + if(lParam && !lParam.func){ + lParam.func = lFunc; DOM.anyload(lParam); @@ -292,7 +296,7 @@ var CloudCommander, Util, DOM, CloudFunc; pParams_a = [pParams_a]; } - for(var i = 0, n = pParams_a.length; i < n; i++){ + for(var i = 0, n = pParams_a.length; i < n; i++){ var lParam = pParams_a.pop(); if(lParam){ @@ -301,7 +305,7 @@ var CloudCommander, Util, DOM, CloudFunc; if(Util.isString(lParam) ) lParam = { src : lParam }; - var lFunc = lParam.func; + var lFunc = lParam.func; lParam.func = Util.retExec(doneFunc, lFunc); DOM.anyload(lParam); diff --git a/lib/client/editor/_codemirror.js b/lib/client/editor/_codemirror.js index 4a501505..07ccdf0f 100644 --- a/lib/client/editor/_codemirror.js +++ b/lib/client/editor/_codemirror.js @@ -85,19 +85,21 @@ var CloudCommander, Util, DOM, CloudFunc, CodeMirror; console.time('codemirror load'); var lDir = cloudcmd.LIBDIRCLIENT + 'editor/codemirror/'; - DOM.jsload(lDir + 'codemirror.js', function(){ - DOM.anyLoadInParallel([ - lDir + 'codemirror.css', - lDir + 'theme/night.css', - lDir + 'mode/javascript.js', + DOM.anyLoadOnLoad([ + [ + lDir + 'codemirror.css', + lDir + 'theme/night.css', + lDir + 'mode/javascript.js', ], - function(){ - console.timeEnd('codemirror load'); - CodeMirrorLoaded = true; - Util.exec(pCallBack); - }); - }); + lDir + 'codemirror.js' + ], + + function(){ + console.timeEnd('codemirror load'); + CodeMirrorLoaded = true; + Util.exec(pCallBack); + }); } diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 44ea9997..03e4d6e4 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -29,18 +29,17 @@ var CloudCommander, Util, DOM, $, Github, cb; console.time('github load'); var lDir = './lib/client/storage/github/'; - DOM.jsload(lDir + 'github.js', function(){ - DOM.anyLoadOnLoad([ - lDir + 'lib/base64.js', - lDir + 'lib/underscore.js'], - - function(){ - console.timeEnd('github load'); - DOM.Images.hideLoad(); - - Util.exec(pCallBack); - }); - }); + DOM.anyLoadInParallel([ + lDir + 'github.js', + lDir + 'lib/base64.js', + lDir + 'lib/underscore.js'], + + function(){ + console.timeEnd('github load'); + DOM.Images.hideLoad(); + + Util.exec(pCallBack); + }); } function setConfig(pCallBack){