1// Scripts for handling CMS configuration 2// @author Roman Kovalev <[email protected]> 3(function($) { 4"use strict"; 5 6 CMS.config = { 7 data: null, 8 }; 9 10 /** 11 * Get value from the CMS configuration 12 * @param name If name contains '.', method will attempt to return property 13 * value from config object. Otherwise whole object will be returned. 14 * For example: CMS.config.get("map.defaultCenter") 15 * @param def Default value that will be returned if config has no required property 16 * @returns {*} 17 */ 18 CMS.config.get = function(name, def) { 19 let key = ''; 20 if (this.data !== null) { 21 if (name.indexOf('.') !== -1) { 22 let parts = name.split('.'); 23 name = parts[0]; 24 key = parts[1]; 25 } 26 let obj = this.data[name]; 27 if (typeof obj !== "undefined") { 28 return key ? obj[key] : obj; 29 } 30 } 31 return def; 32 }; 33 34 /** 35 * Init CMS configuration system. Method should be triggered as early as possible 36 * from both frontend and backend parts. Each part should provide it's own ajax-response method 37 * for loading configuration 38 * @param url This URL should return whole set of config data by request 39 * @returns {boolean} 40 */ 41 CMS.config.init = function(url) { 42 if (this.data !== null) { return false; } 43 $.get(url) 44 .done(function(resp) { 45 if (resp.status && resp.data) { 46 CMS.config.data = resp.data; 47 } 48 }) 49 .fail(function() { 50 CMS.logger.error("Unable to load configuration data by url " + url); 51 }); 52 } 53 54 55})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.