js/src/common/Config.js
var Config = (function ($) {
var config = KB.appData.config || {};
return {
/**
* General getter
* Return complete config object if no key is given
* @param key
* @returns {*}
*/
get: function (key) {
if (!key) {
return config;
}
if (config[key]) {
return config[key];
}
return null;
},
/**
* Shortcut getter to nonces
* @param mode
* @returns {*}
*/
getNonce: function (mode) {
// possible modes: update, create, delete, read
var modes = ['update', 'create', 'delete', 'read'];
if (_.indexOf(modes, mode) !== -1) {
return config.nonces[mode];
} else {
console.error('Invalid nonce requested in kb.cm.Config.js');
return null;
}
},
isAdmin: function(){
return !config.frontend;
},
inDevMode: function () {
return config.env.dev;
},
getRootURL: function () {
return config.env.rootUrl;
},
getFieldJsUrl: function () {
return config.env.fieldJsUrl;
},
getHash: function () {
return config.env.hash;
},
getLayoutMode: function(){
return config.layoutMode || 'default-boxes';
}
}
})(jQuery);
module.exports = Config;