Created
November 18, 2013 23:32
-
-
Save bulkan/7537344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
return { | |
requests: { | |
/** | |
* Load a script file from the asset directory of the app | |
* | |
* @param asset String name of the JavaScript file to load | |
*/ | |
getScript: function(asset){ | |
return { | |
url: this.assetURL(asset), | |
dataType: 'script', | |
cors: true, | |
crossDomain: true | |
} | |
} | |
}, | |
events: { | |
'app.activated':'onAppActivated' | |
}, | |
onAppActivated: function(e) { | |
if (!e.firstLoad) return; | |
var scripts = []; | |
scripts.push(this.ajax('getScript', 'another.js')); | |
scripts.push(this.ajax('getScript', 'comment_lib.js')); | |
var self = this; | |
// wait until all promises are done | |
this.when.apply(this, scripts).done(function(data){ | |
console.log('all scripts loaded'); | |
// the app is loaded here | |
}).fail(function(data){ | |
console.log(data); | |
}); | |
}, | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment