pui.loadJS(path or config)
This function dynamically loads an external JavaScript file. If the file is already loaded, the function returns false. If the load process initiated successfully, the function returns true. If the parameter passed into the function is invalid (i.e. path is not specified), the function returns null.
Parameter:
path or config - the JavaScript path to load or a configuration object that specifies the JavaScript path to load along with other configuration options
Configuration Options:
path - the JavaScript path to load
callback - optional function to call once the JavaScript file is loaded
onerror - optional function to call if loading the JavaScript was unsuccessful
test - optional test function that can determine whether the JavaScript file was loaded successfully; if the test returns true before loading of the JavaScript is initiated, the process stops because the JavaScript is already loaded; if the test does not return true after the script has loaded, the callback is not called because the proper objects have not been loaded
Examples:
Simple usage
pui.loadJS("/profoundui/userdata/js/myfile.js");
Using config options
pui.loadJS({
path: "/profoundui/userdata/js/myfile.js",
callback: function() {
myfunction(); // if myfunction is defined in myfile.js, it should be safe to call it here; the file should have loaded by this time
}
});
Using config options to load the dojo library and test if it loaded properly
pui.loadJS({
path: "http://ajax.googleapis.com/ajax/libs/dojo/1.8.2/dojo/dojo.js",
callback: function() {
// here, we can place code that will proceed to use the dojo library once it is fully loaded
},
test: function() {
return (typeof dojo != "undefined"); // return true if the dojo object is defined, false if undefined
}
});