1(function () { 2 'use strict'; 3 4 function sortItems(container, sortValue) { 5 var list = container.querySelector('.homes-row') || container; 6 var items = Array.prototype.slice.call(list.querySelectorAll(':scope > .item')); 7 var field = sortValue.indexOf('street') === 0 ? 'street' : 'price'; 8 var direction = sortValue.indexOf('asc') !== -1 ? 'asc' : 'desc'; 9 10 items.sort(function (a, b) { 11 if (field === 'street') { 12 var streetA = (a.getAttribute('data-street-name') || '').toLowerCase(); 13 var streetB = (b.getAttribute('data-street-name') || '').toLowerCase(); 14 if (streetA === streetB) return 0; 15 var result = streetA < streetB ? -1 : 1; 16 return direction === 'asc' ? result : -result; 17 } 18 var priceA = parseInt(a.getAttribute('data-sale-price'), 10) || 0; 19 var priceB = parseInt(b.getAttribute('data-sale-price'), 10) || 0; 20 return direction === 'asc' ? priceA - priceB : priceB - priceA; 21 }); 22 items.forEach(function (item) { 23 list.appendChild(item); 24 }); 25 } 26 27 function applyFilter(container) { 28 var minInput = container.querySelector('.homes-filter-min'); 29 var maxInput = container.querySelector('.homes-filter-max'); 30 var min = minInput.value !== '' ? parseInt(minInput.value, 10) : null; 31 var max = maxInput.value !== '' ? parseInt(maxInput.value, 10) : null; 32 var items = container.querySelectorAll('.item'); 33 var visibleCount = 0; 34 35 items.forEach(function (item) { 36 var price = parseInt(item.getAttribute('data-sale-price'), 10) || 0; 37 var visible = true; 38 if (min !== null && price < min) visible = false; 39 if (max !== null && price > max) visible = false; 40 item.hidden = !visible; 41 if (visible) visibleCount++; 42 }); 43 44 var empty = container.querySelector('.homes-filter-empty'); 45 if (empty) empty.hidden = visibleCount !== 0; 46 } 47 48 function init(container) { 49 var sortSelect = container.querySelector('.homes-filter-sort'); 50 var minInput = container.querySelector('.homes-filter-min'); 51 var maxInput = container.querySelector('.homes-filter-max'); 52 53 if (sortSelect) { 54 sortSelect.addEventListener('change', function () { 55 sortItems(container, sortSelect.value); 56 }); 57 } 58 if (minInput) { 59 minInput.addEventListener('change', function () { 60 applyFilter(container); 61 }); 62 } 63 if (maxInput) { 64 maxInput.addEventListener('change', function () { 65 applyFilter(container); 66 }); 67 } 68 } 69 70 document.addEventListener('DOMContentLoaded', function () { 71 document.querySelectorAll('[data-homes-filter]').forEach(init); 72 }); 73})();
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.