(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 = $('
', { 'class': 'wce_categoriesImg wce_perrow'+this.config.columns+' r--l-flex r--l-flex-wrap' }); for (var category_id in this.categories) { var category = this.categories[category_id]; var row = _generateBox.call(this, category); internalContent.append(row); } var boxContent = $('', { 'id':'wce_pictureCategories' }).append(internalContent); _insertCustomStyleTo.call(this, boxContent); if (navigator.userAgent.indexOf(".NET") >= 0) { boxContent.addClass('wce_ieFix'); } if (this.config.show_in_custom_module) { if ($('#'+this.config.custom_module_id).find('.innerbox').length > 0) { $('#'+this.config.custom_module_id+' .innerbox').append(boxContent); } else { $('#'+this.config.custom_module_id).append(boxContent); } $('#'+this.config.custom_module_id).removeClass('loading'); } else { if ($('div.main div.centercol')) { var boxContainer = $('', {'class': 'box', 'id':'box_pictureCategoriesDefault'}).append($('', {'class':'boxhead'}).append($('').append('
', {'class':'px1'}).append(this.config.header))).append($('', {'class':'innerbox'}).append(boxContent)); $('div.main div.centercol').prepend(boxContainer); if(typeof this.config.intro === 'string' && this.config.intro.length > 0) { boxContainer.find('.innerbox').prepend($('', {class: "boxintro", html: this.config.intro})); } } } var _that = this; if($("#wce_pictureCategories .wce_tile").length > 0){ $("#wce_pictureCategories .wce_tile").each(function(){ _calculateFontBaseSize.call(_that, $(this)); }); } $(window).resize(function(){ if($("#wce_pictureCategories .wce_tile").length > 0){ $("#wce_pictureCategories .wce_tile").each(function(){ _calculateFontBaseSize.call(_that, $(this)); }); } }); for (var categoryIndex in this.categories) { category = this.categories[categoryIndex]; _getProductsFromCategory.call(this, category); _getCategoryChildrens.call(this, category); } }; var _getProductsFromCategory = function(category){ if ((this.config.show_product_count || $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').hasClass('loading')) === false) { return; } if (category.items > 0 && category.image.length > 0) { return; } window.frontAPI.getProductsFromCategory(function (products) { if ($('#wce_pictureCategories li[data-category-id='+category.category_id+']').length) { if (products.count) { var imageUrl = _generateImageUrl.call(this, products.list[0].main_image); if (typeof this.categoryMap[category.category_id] !== 'undefined') { var categoryIndex = this.categoryMap[category.category_id]; this.categories[categoryIndex]['image'] = imageUrl; } if ($('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').hasClass('loading')) { $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').append($('
', { 'class': ' wce_transition', 'src':imageUrl, 'alt':category.translation.name, 'title':category.translation.name })); } if (this.config.show_product_count && $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .wce_count').length) { $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .wce_count').text(products.count); } } else if ($('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').hasClass('loading')) { $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').append($('
', { 'class': ' wce_transition', 'src':_generateImageUrl.call(this, ''), 'alt': '' })); } $('#wce_pictureCategories li[data-category-id='+category.category_id+'] .img-wrap').removeClass('loading'); } }.bind(this), { urlParams: '?limit=1', id: category.category_id }); }; var _getCategoryChildrens = function(category){ if (!($('#wce_pictureCategories li[data-category-id='+category.category_id+']').length && this.config.show_subcategories && this.config.subcategory_limit)) { return; } window.frontAPI.getCategoryChildrens(function (subcategories) { if (subcategories.count) { var tile = $('#wce_pictureCategories li[data-category-id='+category.category_id+']'); tile.addClass('wce_hasSublist'); var ulElement = $('', {'class':'wce_subCategories'}); for (var i = 0; i < subcategories.list.length; i++) { var subcategory = subcategories.list[i]; ulElement.append($('').append($('', { 'class': 'block', 'href':subcategory.url }).text(subcategory.translation.name))); } if (subcategories.count > this.config.subcategory_limit) { ulElement.append($('', {'class':'wce_more'}).append($('', { 'class': 'block', 'href':category.url }).text(this.translation['more']))); } tile.find('.wce_links').append(ulElement); _setTileFx.call(this, tile); } }.bind(this), { urlParams: '?limit='+this.config.subcategory_limit, id: category.category_id }); }; var _generateBox = function(category){ var tile = $('', { 'class': 'wce_tile wce_boxsizing', 'data-category-id': category.category_id }); var imgElement = $('', { 'class': 'wce_proportioner '+this.config.proportion, 'href':category.url, 'title':category.translation.name }).append($('', { 'class':'img-wrap r--l-flex r--l-flex-hcenter r--l-flex-vcenter' })); if (category.image) { imgElement.find(".img-wrap").append($('
', { 'class': ' wce_transition', 'src':category.image, 'alt':category.translation.name, 'title':category.translation.name })); } else { imgElement.find(".img-wrap").addClass('loading'); } tile.append(imgElement); var linksWrap = $(''); var nameElement = $('', { 'class':'wce_name wce_transition' }).append($('', { 'href':category.url, 'title':category.translation.name, 'html': category.translation.name })); if (this.config.show_product_count) { tile.append($('', {'class':'wce_count'}).text(category.items)); } linksWrap.append(nameElement); tile.append(linksWrap); return tile; }; var _insertCustomStyleTo = function(boxContent){ var c = this.config.color; var styleObj = $(''); var styleStr = ''; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile{ background: '+c.nameBg+'; border-color: '+c.tileBrd+'}\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile .wce_name a{ color: '+c.nameTxt+' }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile .wce_subCategories{ border-color: '+c.tileBrd+'; }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile .wce_subCategories:after{ background-color: '+c.submenuBg+' }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile .wce_subCategories a{ color: '+c.submenuTxt+'; }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile .wce_subCategories a:hover{ color: '+c.submenuTxtHover+'; background-color: '+c.submenuBgHover+' }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile:hover{ background: '+c.nameBgHover+'; border-color: '+c.tileBrdHover+'}\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile:hover .wce_name a{ color: '+c.nameTxtHover+' }\n'; styleStr += '#wce_pictureCategories .wce_categoriesImg .wce_tile:hover .wce_subCategories{ border-color: '+c.tileBrdHover+'}\n'; styleObj.text(styleStr); boxContent.append(styleObj); }; var _setTileFx = function(tile){ if(tile.find(".wce_subCategories").length > 0){ tile.find(".wce_subCategories").hide(); var trig = $("",{ class: "wce_showSublist wce_transition fa fa-angle-right", }); tile.find(".wce_name").append(trig); trig.click(function(){ tile.find(".wce_subCategories").stop().slideDown(300); trig.addClass("wce_rotate"); }); trig.parent().hover( function(){ tile.find(".wce_subCategories").stop().slideDown(300); trig.addClass("wce_rotate"); }, function(){} ); tile.hover( function(){}, function(){ tile.find(".wce_subCategories").stop().slideUp(300); trig.removeClass("wce_rotate"); } ); } }; var _calculateFontBaseSize = function(tile){ var fontSize = tile.outerWidth() * 0.059; if(fontSize > 18.2){ fontSize = 18.2; } if(fontSize < 14){ fontSize = 14; } tile.css("font-size", fontSize); }; var _generateImageUrl = function(main_image){ if (typeof main_image !== 'string' || main_image.length === 0) { return window.shoper.url('environment/cache/images/'+this.config.imageWidth+'_'+this.config.imageHeight+'_productGfx___overlay.jpg'); } return window.shoper.url('environment/cache/images/'+this.config.imageWidth+'_'+this.config.imageHeight+'_productGfx_'+main_image+'.jpg'); }; return { constructor:pictureCategories, showModule: function () { if (this.config.show_in_custom_module) { $('#'+this.config.custom_module_id).addClass('loading'); } if ($('body').hasClass('shop_index')) { _downloadCategories.call(this, 0, 1); } else if ($('body').hasClass('shop_product_list') && $('body').attr('id') !== 'shop_category0' && !$('body').hasClass('shop_product_promo') && !$('body').hasClass('shop_product_new') && !$('body').hasClass('shop_product_producer')) { var catId = $('body').attr('id'); catId = catId.replace('shop_category', ''); _downloadCategories.call(this, catId, 1); } else { if (this.config.show_in_custom_module) { $('#'+this.config.custom_module_id).removeClass('loading'); $('#'+this.config.custom_module_id).addClass('none'); } } }, getCategory: function(categoryId) { categoryId = parseInt(categoryId); if (isNaN(categoryId)) { return false; } if ($.inArray(String(categoryId), this.overrideIcons) !== -1) { return {'image':window.shoper.url('public/assets/images/categories/category_'+categoryId+'.jpg')}; } if (typeof this.categoryMap[categoryId] === 'undefined') { return false; } var categoryIndex = this.categoryMap[categoryId]; var category = this.categories[categoryIndex]; return category; } }; })(); var appTranslations = { more: "więcej" }; var wcePictureCategories_loaded = false; function wcePictureCategoriesInit() { if (wcePictureCategories_loaded) { return; } if(window.frontAPI && window.shoper){ wcePictureCategories_loaded = true; window.wcePictureCategories = new pictureCategories('eyJzaG9wX2lkIjoiMzI3IiwiYWN0aXZlIjoiMSIsInNob3dfcHJvZHVjdF9jb3VudCI6IjAiLCJzaG93X3N1YmNhdGVnb3JpZXMiOiIxIiwic3ViY2F0ZWdvcnlfbGltaXQiOiIzIiwiY29sdW1ucyI6IjUiLCJzaG93X2luX2N1c3RvbV9tb2R1bGUiOiIxIiwiY3VzdG9tX21vZHVsZV9pZCI6ImJveF93Y2VfY2F0ZWdvcmllcyIsImltYWdlX3Byb3BvcnRpb25zIjoid2NlX2hyIiwidGhlbWUiOiIwIiwiY29sb3JfYmFja2dyb3VuZCI6IiMxZjYxYWUiLCJjb2xvcl90ZXh0IjoiI2ZlZmVmZSIsImNvbG9yX2JvcmRlciI6IiMxZjYxYWUiLCJ1c2VfY2FjaGUiOiIwIiwiY29sb3JfaG92ZXJfYmFja2dyb3VuZCI6IiNmN2Y3ZjciLCJjb2xvcl9ob3Zlcl90ZXh0IjoiIzI4MjgyOCIsImNvbG9yX2hvdmVyX2JvcmRlciI6IiM5OTk5OTkiLCJjb2xvcl9zdWJfYmFja2dyb3VuZCI6IiNmZmZmZmYiLCJjb2xvcl9zdWJfdGV4dCI6IiMyODI4MjgiLCJjb2xvcl9zdWJob3Zlcl9iYWNrZ3JvdW5kIjoiI2Q4ZDhkOCIsImNvbG9yX3N1YmhvdmVyX3RleHQiOiIjMjgyODI4IiwibWV0YWZpZWxkX2tleSI6ImFwcFN0eWxlIiwibWV0YWZpZWxkX2lkIjoiMTciLCJtZXRhZmllbGRfdmFsdWVfaWQiOiIxNyJ9', 'WyIxIiwiOSIsIjE2IiwiMjgiLCIzOSIsIjU1IiwiNzMiLCI4NyIsIjk3IiwiMTU4IiwiMjMwIiwiMjYwIiwiMzUyIiwiNzY0IiwiNzY1Il0=', '', appTranslations); } else { console.log('App PictureCategories: FrontApi or Shoper not initialized yet'); setTimeout(function(){ wcePictureCategoriesInit();}, 2000); } } wcePictureCategoriesInit(); } else { console.log('No jQuery'); } } catch (e) { console.log(e); } })();