jQuery(document).ready(function($)
{
$(".filter-box").each(function(){
var checked = 0;
if($(this).find('[id="prices[0]"]').length > 0){
if($(this).find('[id="prices[0]"]').val() != ""){
checked++;
}
if($(this).find('[id="prices[1]"]').val() != ""){
checked++;
}
}else if($(this).find('[name="keywords"]').length > 0){
if($(this).find('[name="keywords"]').val() != ""){
checked++;
}
if($(this).find('[name="keywords_desc"]').val() != ""){
checked++;
}
}else{
checked = $(this).find('[checked="checked"]').length;
}
if( checked > 0 )
{
$(this).addClass("active");
$(this).find(".filter-title").attr("data-checked",checked);
}
});
$('#fcslowo input[type=text]').on('keyup', function(e) {
if(e.keyCode == 13 && $(this).val() != '') {
$('#f_filter').submit();
}
});
var type = 'many';
if(Cookies.get('search-list-type') != undefined)
{
type = Cookies.get('search-list-type');
$('.change-search-list-type[data-type="' + type + '"]').addClass('button-active');
switchSearchListType(type);
}else{
jQuery('.listing-classic').css('display','');
}
$(window).on('listing_products_loaded', function()
{
switchSearchListType(type);
});
$('.change-search-list-type').on('click',function()
{
loading_start();
type = $(this).data('type');
switchSearchListType(type);
$(this).siblings().removeClass('button-active');
$(this).addClass('button-active');
Cookies.set('search-list-type', type);
setTimeout(function(){ $(window).trigger('change_listing_type'); }, 50);
});
$(window).on('change_listing_type',function()
{
setTimeout(loading_stop,100);
});
if($('#sample-showcase').length > 0 ){
var slider = $('#sample-showcase')[0];
$('#sample-showcase').after('
' + dget('bfs','min-price') + '' + dget('bfs','max-price') + '
');
var min_start = dget('bfs','min-price');
var max_start = dget('bfs','max-price');
if(parseInt($("#prices\\[0\\]").val())>0)
min_start = $("#prices\\[0\\]").val();
if(parseInt($("#prices\\[1\\]").val())>0)
max_start = $("#prices\\[1\\]").val();
noUiSlider.create(slider, {
start: [ min_start, max_start ],
step: 0.1,
connect: true,
range: {
'min': [ parseFloat(dget('bfs','min-price')) ],
'max': [ parseFloat(dget('bfs','max-price')) ]
}
});
slider.noUiSlider.on('update', function( values, handle ) {
$('input[name="prices['+handle+']"]').val(values[handle]);
$('#price-show-'+handle).text(values[handle]+' '+dget('rcVer','currency'));
});
if(min_start == dget('bfs','min-price')) $('input[name="prices[0]"]').val('');
if(max_start == dget('bfs','max-price')) $('input[name="prices[1]"]').val('');
}
filtersInit();
$(window).on('resize', filtersInit);
$('#toggleFilters').on('click', function()
{
$('#mobile_filters').toggleClass('open');
$('body').toggleClass('mobile_filters_open');
});
$('.clearGroup').on('click',function(e){
var clearType = $(this).attr('data-type');
var clearId = $(this).attr('data-id');
if(clearType == 'producers')
$('[id^="'+clearType+'\["]').prop( "checked", false );
else
$('[id^="'+clearType+'\['+clearId+'\]"]').prop( "checked", false );
$('#f_filter').submit();
});
var filters_cookie = (Cookies.get('rc_fs') && JSON.parse(Cookies.get('rc_fs'))) || {};
$('.filter-content').each(function(){
var id = $(this).attr('id').substr(2);
if(filters_cookie[id] !== undefined) return;
if($(this).hasClass('in')) {
filters_cookie[id] = true;
} else {
filters_cookie[id] = false;
}
});
$.each(filters_cookie, function(k,v) {
if(v === true) {
$('#fc'+k).collapse('show');
} else {
$('#fc'+k).collapse('hide');
}
});
$('.filter-content').on('shown.bs.collapse', function() {
var id = $(this).attr('id').substr(2);
filters_cookie[id] = true;
Cookies.set('rc_fs',JSON.stringify(filters_cookie));
}).on('hidden.bs.collapse', function() {
var id = $(this).attr('id').substr(2);
filters_cookie[id] = false;
Cookies.set('rc_fs',JSON.stringify(filters_cookie));
});
//swapping start
$('.product-photo.swapping').on('mouseenter', function(){
var div = $(this);
var img = $(div.find('a').find('img')[0]);
var pid = div.attr('data-pid');
if($('#swapping-hidden-'+pid).length==0)
$.ajax({
method:"POST",
url:'/ajax/pinfo/get_next_image/',
data:{pid:pid},
async: false,
cache: false,
success:function(img){
if(img.length==0)
img = 'null';
div.append(''+img+'');
}
});
swapImg(img, pid);
});
$('.product-photo.swapping').on('mouseleave', function(){
var div = $(this);
var img = $(div.find('a').find('img')[0]);
var pid = div.attr('data-pid');
swapImg(img, pid);
});
function swapImg(img, pid)
{
var currentSrc = img.attr('src');
var toShow = $('#swapping-hidden-'+pid).html();
if(toShow.length > 0 && toShow!='null'){
$('#swapping-hidden-'+pid).html(getFile(currentSrc));
$(img).attr('src', swapFile(currentSrc, toShow));
}
}
function swapFile(src, file)
{
src = src.split('/');
src[(src.length -1)] = file;
src = src.join('/');
return src;
}
function getFile(src)
{
src = src.split('/');
return src[(src.length -1)];
}
//swapping end
});
function filtersInit()
{
if(jQuery('.rc-box-filter-search').length <= 0) return;
if(jQuery('#mobile_filters').length <= 0) jQuery('section#top_menu').append('');
var num = '';
if(dget('fsbc','filters',true) > 0) num = '' + dget('fsbc','filters',true) + '';
if(jQuery('#toggleFilters').length <= 0) jQuery('.header-wrap').append(''+num+' '+ def.index['RklMVFJVSiA='] +'
');
if(viewport_check.is_in(['xs','sm'])) {
var from = jQuery('.rc-box-filter-search').find('.box-simple');
var to = jQuery('#mobile_filters');
} else {
var from = jQuery('#mobile_filters');
var to = jQuery('.rc-box-filter-search').find('.box-simple');
}
if(viewport_check.is_in(['xs','sm'])) {
var t = from.find('.box-title');
var b = from.find('.box-body');
t.appendTo(to);
b.appendTo(to);
}
if(viewport_check.is_in(['md','lg']) && (viewport_check.previous() == 'xs' || viewport_check.previous() == 'sm')) {
var t = from.find('.box-title');
var b = from.find('.box-body');
t.appendTo(to);
b.appendTo(to);
}
}
function switchSearchListType(type)
{
var sclass = dget('sic','class');
var shighlightclass = dget('sic','highlight-class');
jQuery('.listing-classic > .product-item').removeClass(type == 'one' ? sclass : shighlightclass);
jQuery('.listing-classic > .product-item').addClass(type == 'many' ? sclass : shighlightclass);
jQuery('.listing-classic').css('display','');
correctHeights();
}
function addPaginationButton(paginationType)
{
var mr = jQuery('#more_result').html();
jQuery(document).on('click', '.ajax-page-loader', function(e) {
jQuery(window).trigger('listing_products_load');
nextPage(paginationType);
});
jQuery('.ajax-page-loader').append('' + mr + '');
}
function paginationButton(paginationType)
{
addPaginationButton(paginationType);
}
function nextPage(paginationType)
{
var url = jQuery('.ajax-page-loader').attr('data-url').replace(/amp;/g, '');
jQuery('.ajax-page-loader').find('a').text('Wczytywanie...');
jQuery('.ajax-page-loader').find('a').addClass('disabled');
jQuery('.ajax-page-loader').remove();
jQuery(document).off('click', '.ajax-page-loader');
if(paginationType == 2)
jQuery('.ajax-page-loader').remove();
loading_start();
jQuery.ajax({
url: url
}).done(function(data) {
// jQuery('.listing-classic').append(data); old
var resp = jQuery(data);
if(paginationType == 3 || paginationType == 2)
jQuery('.ajax-page-loader').remove();
jQuery('.listing-classic').append(resp.children('.listing-classic').html());
correctAddEventListener(document.querySelectorAll(".listing-classic .product-item .product-photo img"));
jQuery('.mobile-product-list').append(resp.children('.mobile-product-list').html());
window.history.pushState(null, null, url);
loading_stop();
rc3Event();
quickView();
if(paginationType == 3 || paginationType == 2) {
addPaginationButton(paginationType);
}
jQuery(window).trigger('listing_products_loaded');
});
}