Skip to content

Instantly share code, notes, and snippets.

@bulkan
Created November 18, 2013 23:32
Show Gist options
  • Save bulkan/7537344 to your computer and use it in GitHub Desktop.
Save bulkan/7537344 to your computer and use it in GitHub Desktop.
(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