Created
January 7, 2011 17:21
-
-
Save eltiare/769771 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
var application = { | |
page_loaded : false, | |
page_init : function() { | |
var i; | |
application.page_loaded = true; | |
// Load scripts that have not already been loaded. | |
var script; | |
for (i=0; script = application.scripts_to_load[i]; i++) { | |
application.load_script(script[0], script[1]); | |
} | |
application.scripts_to_load = []; | |
}, | |
scripts_to_load : [], | |
// Dynamically loads a script | |
// Waits until the DOM is read to append the script to body | |
load_script : function(url, args) { | |
if (!this.page_loaded) { | |
this.scripts_to_load.push([url, args]); | |
} else { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
var arg_array = []; | |
for ( v in args) { | |
arg_array.push(v.html_entities() + '=' + args[v].html_entities()); | |
} | |
var arg_string = arg_array.join('&'); | |
script.src = url + '?' + arg_string; | |
document.body.appendChild(script); | |
} | |
} | |
}; | |
// You can load the init with jQuery like so: | |
$(document).ready(application.page_init); | |
// Call the load script like this: | |
application.load_script('http://maps.google.com/maps/api/js', { | |
v : '3.2', | |
sensor : 'false', | |
key : 'google_key', | |
callback : 'google_init' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment