function getUrlFilter() { var params = []; var urlSplit = linkPage.split('?'); var resultUrl = urlSplit[0]; $('#ocfilter-content .option-values').each(function (key, value) { var filterName = $(this).data('filter-name'); var filterUrl = $(this).data('filter-url'); var filterId = $(this).data('filter-id'); var filterType = $(this).data('filter-type'); var filterParams = []; $(this).find('input').each(function () { if ($(this).is(':checked')) { if ($(this).data('filter-value') != '') filterParams[filterParams.length] = $(this).data('filter-value'); } }); if (filterParams.length > 0) { if (filterName == '') { params[params.length] = filterParams.join('/'); } else { params[params.length] = filterName + '/' + filterParams.join('/'); } } if (filterType == 'slide_dual') { console.log(filterUrl); var min = $('#scale-' + filterId).data('range-min'); var max = $('#scale-' + filterId).data('range-max'); var start = $('#left-value-' + filterId).text(); var end = $('#right-value-' + filterId).text(); if ((min != start) || (max != end)) { resultUrl += filterUrl + '/' + start + '-' + end + '/'; } console.log(resultUrl); } }); var stringParams = params.join('/').replace(/\/\//gi, '/'); resultUrl += stringParams; var minPrice = $('#scale-price').data('range-min'); var maxPrice = $('#scale-price').data('range-max'); var startPrice = $('#price-from').text(); var endPrice = $('#price-to').text(); if ((minPrice != startPrice) || (maxPrice != endPrice)) { resultUrl += '/price/' + startPrice + '-' + endPrice; } if (typeof urlSplit[1] != 'undefined') { var paramsUrl = urlSplit[1].replace(/&/gi, '&'); resultUrl += '?' + paramsUrl; } return resultUrl; } $('.option-values label input').click(function () { ajaxGetFilterValue(); }); function ajaxGetFilterValue() { var url = getUrlFilter(); if (url.indexOf('?') == -1) { url += '&ajax_filter=true'; } else { url += '?ajax_filter=true'; } $.ajax({ url: url, dataType: "json" }).done(function (json) { var jsonParse = JSON.parse(JSON.stringify(json)); var options = []; var optionsObject = {}; for (key in jsonParse) { for (keyOption in jsonParse[key].values) { options = options.concat(jsonParse[key].values[keyOption].id); optionsObject[jsonParse[key].values[keyOption].id + ""] = jsonParse[key].values[keyOption]; } } refreshFilterOptions(options, optionsObject); }); } function refreshFilterOptions(options, optionsObject) { //console.log(optionsObject["60009572730598"]); $('#ocfilter-content .option-values label').each(function (key, value) { var id = $(this).attr('id'); id = id.substr(2); if (options.indexOf("" + id) !== -1) { if ($(this).hasClass('inactive_option')) { $(this).removeClass('inactive_option'); } $(this).find('.badge').text(optionsObject[id].count); $(this).find('input').prop('disabled', false); } else { $(this).addClass('inactive_option'); $(this).find('input').prop('checked', false); $(this).find('input').prop('disabled', true); } }); } // $(document).mouseup(function (e) { // var container = $(".panel-oc-ocfilter"); // if (container.has(e.target).length === 0){ // $('#ocfilter').animate({ // right: '-250px' // }, 200); // $(this).animate({ // right: '0' // }, 200); // $(this).removeClass("actives"); // } // }); let filterOc = function () { //главная функция $('#filter-click').click(function () { if ($(this).hasClass('actives')) { $('#ocfilter').animate({ right: '-250px' }, 200); $(this).animate({ right: '0' }, 200); $(this).removeClass("actives"); } else { $(this).animate({ right: '250px' }, 200); $('#ocfilter').animate({ right: '0' }, 200); $(this).addClass("actives"); } }); }; $(document).ready(filterOc);