var determineType = function(configType) { var patternArray = [/Text$/g, /Image$/g, /Color$/g, /Visible$/g]; if(configType) { for (var i = 0; i < patternArray.length; i++) { if (configType.match(patternArray[i])) { return configType.match(patternArray[i])[0]; } } } return ""; }; var convertToClass = function (name) { return "." + name.charAt(0).toLowerCase() + name.slice(1); }; var handleImage = function (configType, typeData) { var imageEle = document.createElement('img'); imageEle.setAttribute('src', typeData); $(convertToClass(configType)).html(imageEle); }; var handleText = function (configType, typeData) { $(convertToClass(configType)).html(typeData); }; var handleVisible = function (configType, typeData) { if (typeData.toUpperCase() === "TRUE") { $(convertToClass(configType)).show(); } else if (typeData.toUpperCase() === "FALSE") { $(convertToClass(configType)).hide(); } }; var handleConfigs = function(config) { var type = determineType(config.ConfigType); switch (type) { case "Image": handleImage(config.ConfigType, config.TypeData); break; case "Text": handleText(config.ConfigType, config.TypeData); break; case "Visible": handleVisible(config.ConfigType, config.TypeData); break; } }; var brandingServiceCall = function (clientId, product, apiEndpoint, callback) { if (!product) product = ""; if (clientId) { var completeURL = apiEndpoint + 'CustomerConfig/' + clientId + '/' + product; var encodedURL = completeURL.replace(/\s/g, '%20'); $.getJSON(encodedURL, function(data) { if (data) { for(var product in data.Products) { for (var config in data.Products[product].Configs) { handleConfigs(data.Products[product].Configs[config]); } } if (typeof callback === "function") callback(data); } setTimeout(function() { $('.loading-screen').remove() }, 500); }); } else { $('.loading-screen').remove(); } };