1$(document).ready(function() { 2 let rangeSlider = $(".price-range"); 3 4 let initialMin = parseInt(rangeSlider.data('min'), 10); 5 let initialMax = parseInt(rangeSlider.data('max'), 10); 6 let country = document.querySelector('[name="auto-country"]'); 7 8 let amount = $("#amount"); 9 let minPriceField = $('input[name="min_price"]'); 10 let maxPriceField = $('input[name="max_price"]'); 11 let shouldUpdateSlider = true; 12 13 function formatNumber(number) { 14 return number.toLocaleString('ru-RU'); 15 } 16 17 function initSlider(min, max) { 18 min = parseInt(min, 10); 19 max = parseInt(max, 10); 20 if (isNaN(min) || isNaN(max)) { 21 console.error('ÐекоÑÑекÑнÑе знаÑÐµÐ½Ð¸Ñ Ð´Ð»Ñ ÑлайдеÑа:', min, max); 22 return; 23 } 24 if (rangeSlider.slider('instance')) { 25 rangeSlider.slider('destroy'); 26 } 27 rangeSlider.slider({ 28 range: true, 29 min: min, 30 max: max, 31 values: [min, max], 32 slide: function (event, ui) { 33 amount.val(formatNumber(ui.values[0]) + "Ñ - " + formatNumber(ui.values[1]) + "Ñ"); 34 minPriceField.val(ui.values[0]); 35 maxPriceField.val(ui.values[1]); 36 }, 37 stop: function(event, ui) { 38 shouldUpdateSlider = false; 39 $(this).closest('.filters__form').submit(); 40 } 41 }); 42 amount.val(formatNumber(rangeSlider.slider("values", 0)) + "Ñ - " + formatNumber(rangeSlider.slider("values", 1)) + "Ñ"); 43 minPriceField.val(rangeSlider.slider("values", 0)); 44 maxPriceField.val(rangeSlider.slider("values", 1)); 45 } 46 47 initSlider(rangeSlider.data('min'), rangeSlider.data('max')); 48 49 $('.filters__form').on('submit', function(event) { 50 event.preventDefault(); 51 loadPosts($(this)); 52 }); 53 54 function loadPosts(form) { 55 const productsContainer = form.closest('.container').find('.products-container'); 56 const pageNavContainer = form.closest('.container').find('.post-pagination'); 57 58 $.ajax({
59 type: 'POST', 60 url: works['ajaxurl'], 61 data: form.serialize(), 62 beforeSend: function(xhr) { 63 form.block({ 64 message: null, 65 overlayCSS: { 66 background: '#fff url(' + window.location.protocol + '//' + window.location.hostname + '/wp-content/themes/autopro/assets/img/oval.svg) 50% 50% no-repeat', 67 opacity: 0.6 68 } 69 }); 70 }, 71 success: function(data) { 72 productsContainer.html(data.html_output); 73 74 if (data.autoBrandTaxObj) { 75 $('#auto-model').html('<option value="">ÐÑе модели</option>' + data.autoBrandTaxObj); 76 console.log(data); 77 // === ÐСТÐÐÐÐ: ÑÑÑановка модели, еÑли она бÑла ÑÐ¾Ñ Ñанена === 78 if (window.modelFromUrl) { 79 var $modelSelect = $('select[name="auto-model"]'); 80 if ($modelSelect.find('option[value="' + window.modelFromUrl + '"]').length) { 81 $modelSelect.val(window.modelFromUrl).trigger('change'); // оÑпÑавлÑем вÑоÑой запÑÐ¾Ñ Ñ Ð¼Ð¾Ð´ÐµÐ»ÑÑ 82 console.log('ÐÐ¾Ð´ÐµÐ»Ñ ÑÑÑановлена поÑле Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ ÑпиÑка: ' + window.modelFromUrl); 83 } else { 84 console.warn('ÐÐ¾Ð´ÐµÐ»Ñ Ð½Ðµ найдена в обновлÑнном ÑпиÑке: ' + window.modelFromUrl); 85 } 86 window.modelFromUrl = null; // ÑбÑаÑÑваем 87 } 88 } 89 90 if (data.paginationObj) { 91 pageNavContainer.html(data.paginationObj); 92 pageNavContainer.addClass('post-pagination--ajax'); 93 } else { 94 pageNavContainer.empty(); 95 } 96 97 if (country) { 98 if (country.value === '' && data.min_price === initialMin && data.max_price === initialMax) { 99 pageNavContainer.removeClass('post-pagination--ajax'); 100 } 101 } else { 102 if (data.min_price === initialMin && data.max_price === initialMax) { 103 pageNavContainer.removeClass('post-pagination--ajax'); 104 } 105 } 106 107 if (data.min_price !== undefined && data.max_price !== undefined) { 108 minPriceField.val(data.min_price); 109 maxPriceField.val(data.max_price); 110 if (shouldUpdateSlider) { 111 initSlider(data.min_price, data.max_price); 112 } 113 } 114 115 shouldUpdateSlider = true; 116 form.unblock(); 117 }, 118 error: function(jqXHR, textStatus, errorThrown) { 119 console.log(textStatus); 120 } 121 }); 122 } 123 124 function filterFormSubmit() { 125 let checkField = $(this).attr('name'); 126 127 if (checkField == 'auto-brand') { 128 $('#auto-model').val(''); 129 if ($(this).val() === '') { 130 minPriceField.val(initialMin); 131 maxPriceField.val(initialMax); 132 amount.val(formatNumber(initialMin) + "Ñ - " + formatNumber(initialMax) + "Ñ"); 133 initSlider(initialMin, initialMax); 134 shouldUpdateSlider = false; 135 } else { 136 shouldUpdateSlider = true; 137 } 138 } 139 140 $(this).closest('.filters__form').find('input[name="checkField"]').val(checkField); 141 $(this).closest('.filters__form').find('input[name="paged"]').val(1); 142 shouldUpdateSlider = true; 143 $(this).closest('.filters__form').submit(); 144 } 145 146 $('.filters__select').on('change', filterFormSubmit); 147 148 // === ÐÐÐЫРÐÐÐ ÐÐЯ Ð ÐÐÐТЫ С GET-ÐÐÐ ÐÐÐТРÐÐÐ === 149 function getUrlParams() { 150 const params = new URLSearchParams(window.location.search); 151 return { 152 country: params.get('filter_country'), 153 brand: params.get('filter_brand'), 154 model: params.get('filter_model') 155 }; 156 } 157 158 // ÐлобалÑÐ½Ð°Ñ Ð¿ÐµÑÐµÐ¼ÐµÐ½Ð½Ð°Ñ Ð´Ð»Ñ Ñ ÑÐ°Ð½ÐµÐ½Ð¸Ñ Ð¼Ð¾Ð´ÐµÐ»Ð¸, еÑли ÐµÑ Ð½ÐµÑ Ð² ÑпиÑке 159 window.modelFromUrl = null; 160 161 function applyFiltersFromUrl() { 162 var params = getUrlParams(); 163 var hasFilters = false; 164 165 // console.log(params); 166 167 // СÑÑана 168 if (params.country) { 169 var $country = $('select[name="auto-country"]'); 170 if ($country.find('option[value="' + params.country + '"]').length) { 171 $country.val(params.country).trigger('change'); 172 hasFilters = true; 173 } 174 } 175 176 // ÐÑенд 177 if (params.brand) { 178 var $brand = $('select[name="auto-brand"]'); 179 if ($brand.find('option[value="' + params.brand + '"]').length) { 180 $brand.val(params.brand).trigger('change'); 181 hasFilters = true; 182 } 183 } 184 185 // ÐÐ¾Ð´ÐµÐ»Ñ â пÑобÑем ÑÑÑановиÑÑ ÑÑазÑ, еÑли еÑÑÑ Ð² ÑекÑÑем ÑпиÑке 186 if (params.model) { 187 var $model = $('select[name="auto-model"]'); 188 if ($model.find('option[value="' + params.model + '"]').length) { 189 $model.val(params.model).trigger('change'); 190 hasFilters = true; 191 console.log('ÐÐ¾Ð´ÐµÐ»Ñ ÑÑÑановлена ÑÑазÑ: ' + params.model); 192 } else { 193 // ÐÐ¾Ð´ÐµÐ»Ñ Ð½Ðµ найдена â ÑÐ¾Ñ ÑанÑем Ð´Ð»Ñ ÑÑÑановки поÑле Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ ÑпиÑка 194 window.modelFromUrl = params.model; 195 hasFilters = true; 196 console.log('ÐÐ¾Ð´ÐµÐ»Ñ ÑÐ¾Ñ Ñанена Ð´Ð»Ñ Ð¿Ð¾ÑледÑÑÑей ÑÑÑановки: ' + params.model); 197 } 198 } 199 200 if (hasFilters) { 201 $('input[name="paged"]').val(1); 202 $('input[name="checkField"]').val('auto-brand'); 203 $('.filters__form').submit(); 204 } 205 } 206 207 // ÐапÑÑкаем ÑеÑез неболÑÑÑÑ Ð·Ð°Ð´ÐµÑжкÑ, ÑÑÐ¾Ð±Ñ Select2 и ÑÐ»Ð°Ð¹Ð´ÐµÑ ÑÑпели иниÑиализиÑоваÑÑÑÑ 208 setTimeout(applyFiltersFromUrl, 300); 209}); 210 211// ÐбÑабоÑка клика по пагинаÑии (вне $(document).ready) 212$(document).on('click', '.post-pagination--ajax a', function(e) { 213 e.preventDefault(); 214 var href = $(this).attr('href'); 215 var page = 1; 216 var match = href.match(/paged=(\d+)/); 217 if (match) { 218 page = match[1]; 219 } 220 $('.filters__form input[name="paged"]').val(page); 221 shouldUpdateSlider = false; 222 $('.filters__form').submit(); 223}); 224 225 226// Show more 227jQuery(function($) { 228 // опÑеделÑем в пеÑеменнÑе кнопкÑ, ÑекÑÑÑÑ ÑÑÑаниÑÑ Ð¸ макÑималÑное кол-во ÑÑÑÐ°Ð½Ð¸Ñ 229 const BUTTON = $( '#loadmore a' ); 230 let paged = BUTTON.data( 'paged' ); 231 let maxPages = BUTTON.data( 'max_pages' ); 232 233 BUTTON.click( function( event ) { 234 event.preventDefault(); 235 paged++; 236 237 let postsArgs = queryPostsArgs; 238 $.ajax({
239 type : 'POST', 240 url : works['ajaxurl'], // полÑÑаем из wp_localize_script() 241 data : { 242 'contentType' : 'application/json', 243 'paged' : paged, // Ð½Ð¾Ð¼ÐµÑ ÑекÑÑей ÑÑÑаниÑÑ 244 'action' : 'loadmore', // ÑкÑен Ð´Ð»Ñ wp_ajax_ и wp_ajax_nopriv_ 245 'nonce_code' : works['nonce'], 246 'product_object' : postsArgs, 247 }, 248 beforeSend : function( xhr ) { 249 BUTTON.text( 'ÐагÑÑжаем...' ); 250 }, 251 success : function( data ){ 252 BUTTON.closest('.container').find('.products-container').append( data ); 253 BUTTON.text( 'ÐагÑÑзиÑÑ ÐµÑÑ' ); 254 BUTTON.data('paged', paged); 255 BUTTON.closest('.products-lists__buttons').find('.products-lists__counter span').text(paged); 256 // еÑли поÑледнÑÑ ÑÑÑаниÑа, Ñо ÑдалÑем ÐºÐ½Ð¾Ð¿ÐºÑ 257 if( paged == maxPages ) { 258 BUTTON.remove(); 259 } 260 } 261 }); 262 } ); 263});
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.