JSFiddle - React, Tailwind, and code Playground
by VeryGoodFiddle
JavaScript
'use strict';
define('vgs',['ActionTagConfig', 'loadScript', 'jquery'], function (config, loadScript, $) {
// VGS = VeryGoodSecurity
function init(){
if(!config.VGS_JS_URL || !config.VGS_VAULT_ID){
return $.Deferred().resolve(false);
}
if (window.VGSCollect) {
return $.Deferred().resolve(true);
}
if (window.nvtagDebug) {
var dfd = $.Deferred();
try {
// dynamic loading of JS doesn't work properly using the AT debugger
// so dynamically load it with requirejs here.
// dynamically loading with requirejs doesn't work in prod because
// we optimize with almond which doesn't support loading modules dynamically
require([config.VGS_JS_URL],
function () {
// this will automatically set window.VGSCollect
dfd.resolve(true);
});
}
catch(e) {
console.debug('error loading VGS libraries in debug mode');
dfd.resolve(false);
}
return dfd.promise();
}
return loadScript.nocache(config.VGS_JS_URL, 15000)
.then(function (){
if (!window.VGSCollect) {
return loadScript.nocache(config.VGS_JS_URL, 15000);
}
}, function() {
if (!window.VGSCollect) {
return loadScript.nocache(config.VGS_JS_URL, 15000);
}
});
}
function isLoaded(){
if(!config.VGS_JS_URL || !config.VGS_VAULT_ID){
return false;
}
return !!window.VGSCollect;
}
function waitUntilLoaded(){
return init().then(isLoaded, isLoaded);
}
function createForm(){
if(!isLoaded()){
throw 'Cannot create VGS form, VGS is not loaded.';
}
// passthrough args
var args = [config.VGS_VAULT_ID].concat(Array.prototype.slice.call(arguments));
return window.VGSCollect.create.apply(window.VGSCollect, args);
}
function submitForm(form){
var dfd = $.Deferred();
if(!form || !form.state || Object.keys(form.state) <= 0){
...