(function() { try { if(window.jQuery) { function pictureCategories(config, overrideIcons, iconCache, appTranslations) { this.translation = typeof appTranslations == 'undefined' ? {} : appTranslations; this.config = {}; this.overrideIcons = []; this.cacheIcons = []; this.categories = {}; this.categoryMap = {}; this.tmpCategories = []; var configJson = window.shoper.base64.decode(config); if (configJson) { cfg = jQuery.parseJSON(configJson); this.config = { 'show_product_count': (cfg['show_product_count'] != "0"), 'show_subcategories': (cfg['show_subcategories'] != "0"), 'show_in_custom_module': (cfg['show_in_custom_module'] != "0"), 'columns': cfg['columns'], 'subcategory_limit': cfg['subcategory_limit'], 'custom_module_id': cfg['custom_module_id'], 'header': cfg['header'], 'intro' : cfg['intro'], 'imageWidth': '300', 'imageHeight': '300', 'proportion': cfg['image_proportions'], 'theme': cfg['theme'], 'color': { 'tileBrd': cfg['color_border'], 'nameBg': cfg['color_background'], 'nameTxt': cfg['color_text'], 'tileBrdHover': cfg['color_hover_border'], 'nameBgHover': cfg['color_hover_background'], 'nameTxtHover': cfg['color_hover_text'], "submenuBg": cfg['color_sub_background'], "submenuTxt": cfg['color_sub_text'], "submenuBgHover": cfg['color_subhover_background'], "submenuTxtHover": cfg['color_subhover_text'] } }; } else { return; } var overrideIconsJson = window.shoper.base64.decode(overrideIcons); if (overrideIconsJson) { this.overrideIcons = jQuery.parseJSON(overrideIconsJson); } if (iconCache) { var cacheIconsJson = window.shoper.base64.decode(iconCache); if (cacheIconsJson) { this.cacheIcons = jQuery.parseJSON(cacheIconsJson); } } if (this.config.show_in_custom_module && $('#'+this.config.custom_module_id).length == 0) { return; } this.showModule(); }; pictureCategories.prototype = (function(){ var _downloadCategories = function(categoryId, page) { if (categoryId === 0) { window.frontAPI.getRootCategoryTree(function (mainCategories){ if (mainCategories.list.length > 0) { this.tmpCategories = this.tmpCategories.concat(mainCategories.list); } if (mainCategories.page >= mainCategories.pages) { _handleCategories.call(this, this.tmpCategories); } else { _downloadCategories.call(this, categoryId, ++page); } }.bind(this), { urlParams: '?limit=50&page='+page }); } else { window.frontAPI.getCategoryChildrens(function (categories){ if (categories.list.length > 0) { this.tmpCategories = this.tmpCategories.concat(categories.list); } if (categories.page >= categories.pages) { _handleCategories.call(this, this.tmpCategories); } else { _downloadCategories.call(this, categoryId, ++page); } }.bind(this), { id: categoryId, urlParams: '?limit=50&page='+page }); } }; var _handleCategories = function(categories){ if (this.config.show_in_custom_module && categories.length === 0) { $('#'+this.config.custom_module_id).removeClass('loading'); $('#'+this.config.custom_module_id).addClass('none'); } if (categories.length === 0) { return; } for (var i = 0; i < categories.length; i++) { var category = categories[i]; category.subcategories = []; category.subcategories_count = 0; category.items = 0; category.image = ''; if (this.cacheIcons.hasOwnProperty(String(category.category_id))) { category.items = this.cacheIcons[String(category.category_id)]['count']; category.image = this.cacheIcons[String(category.category_id)]['image']; } if ($.inArray(String(category.category_id), this.overrideIcons) !== -1) { category.image = window.shoper.url('public/assets/images/categories/category_'+category.category_id+'.jpg'); } var category_id = category.category_id; var categoryIndex = Object.keys(this.categories).length; this.categories[categoryIndex] = category; this.categoryMap[category_id] = categoryIndex; } _displayCategories.call(this); }; var _displayCategories = function() { if (this.categories.length === 0) { if (this.config.show_in_custom_module) { $('#'+this.config.custom_module_id).removeClass('loading'); } return; } var internalContent = $('