Using JS Libraries in Volt
It is possible to extend Volt by adding external JavaScript libraries. Below are some examples. Many libraries will work. Some will not due to conflicts with the product's internal libraries.
To use external libraries you need to set secureJS=false. This can be done in the Volt Configuration NSF. The term security is a misnomer (and the name should be changed). What it really means is that the JavaScript sandbox is turned off which allows you to use full JavaScript. Turning the sandbox on with secureJS=true (the default) is good practice when you do not know or trust developers. This could be the case when you deploy the product so that anyone and everyone in the organization can create apps. The sandbox will prevent them from doing anything malicious. But if you do know and trust your developers then turn it off and take advantage of full JavaScript to do cool things! More on the sandbox can be found here.
There are two ways to load a Javascript library in Domino Volt.
The first technique is to use a JavaScript function to add the the library url to the head section and then set the call back to do what you want with the library. You will see this technique in the signature pad example. Sample code is below.
//global function to load JS library - placed in the app onStart event
app.getSharedData().loadScript = function (url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement("script")
script.type = "text/javascript";
script.src = url;
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
}
//typically placed in the form onLoad or an onShow event
var url = 'url_to_your_js_library';
app.getSharedData().loadScript(url,function(){
// what you want to execute when the JS library is loaded
});
The second technique takes advantage of the require function in Volt's dojo. This approach allows you to create a function where the you can ensure the library is loaded before you start executing code which has a dependency on it. A good place to see this technique is in the moment.js example. Sample code is below.
var url = 'url_to_your_js_library';
require([url], function() {
//what you want to execute when the JS library is loaded
});