1$(document).ready(function () { 2 3 let $grid = $('.doctor-filter-grid'); 4 console.log($grid); 5 6 if ($grid.length) { 7 let clearButton = $('#reset'); 8 let textSearch = $('#textSearch'); 9 let selectFields = $('.select-filter'); 10 let errorMessage = $('#errorMessage'); 11 let docSearchReset = $('#docSearchReset'); 12 let itemSelector = '.doc-item'; 13 let doctorTypeHeading = $('.doctor-type-heading'); 14 let filterValue; 15 let filters = {}; 16 let qsRegex; 17 $grid.isotope({ 18 layoutMode: 'fitRows', 19 itemSelector: itemSelector, 20 percentPosition: true, 21 transitionDuration: '0.4s', 22 filter: function () { 23 let $this = $(this); 24 let searchResult = qsRegex ? $this.text().match(qsRegex) : true; 25 let buttonResult = filterValue ? $this.is(filterValue) : true; 26 return searchResult && buttonResult; 27 } 28 }, updateFilteredNum); 29 30 selectFields.on('change', function (e) { 31 let $select = $(e.target); 32 let filterGroup = $select.data('group'); 33 filters[filterGroup] = e.target.value; 34 filterValue = concatValues(filters); 35 $grid.isotope(); 36 updateFilteredNum(); 37 }); 38 39 textSearch.keyup(debounce(function (e) { 40 if (e.keyCode === 27) { 41 $(this).val('').focus(); 42 } 43 if (textSearch.val().length > 1) { 44 qsRegex = new RegExp(textSearch.val(), 'gi'); 45 $grid.isotope(); 46 updateFilteredNum(); 47 docSearchReset.show(); 48 } else { 49 qsRegex = new RegExp('.*'); 50 $grid.isotope(); 51 updateFilteredNum(); 52 docSearchReset.hide(); 53 } 54 }, 200)); 55 56 57 clearButton.on('click', function (e) { 58 doctorTypeHeading.show(); 59 filters = {}; 60 filterValue = ''; 61 selectFields.val('*'); 62 textSearch.val(''); 63 errorMessage.text(''); 64 qsRegex = new RegExp('.*'); 65 $grid.isotope(); 66 updateFilteredNum(); 67 docSearchReset.hide(); 68 }); 69 70 docSearchReset.on('click', function (e) { 71 textSearch.val(''); 72 qsRegex = new RegExp('.*'); 73 $grid.isotope(); 74 updateFilteredNum(); 75 docSearchReset.hide(); 76 }); 77 78 function concatValues(obj) { 79 let value = ''; 80 for (let prop in obj) { 81 value += obj[prop]; 82 } 83 return value; 84 } 85 86 function debounce(fn, threshold) { 87 let timeout; 88 threshold = threshold || 150; 89 return function debounced() { 90 clearTimeout(timeout); 91 let args = arguments; 92 let _this = this; 93 94 function delayed() { 95 fn.apply(_this, args); 96 } 97 98 timeout = setTimeout(delayed, threshold); 99 }; 100 } 101 102 /* 103 * Originally used as a callback to arrangeComplete event but it was very slow to fire. 104 * It is now called directly after the isotope filter function so that it fires immediately and not after the animation 105 * PITA but is what it is 106 * */ 107 function updateFilteredNum() { 108 let elemNum = 0; 109 $grid.each(function () { 110 let el = $(this).data('isotope'); 111 let elems = el.filteredItems.length; 112 if (!$('.doctor-cols').length && $(this).prev('h2').length) { // only run on row layout and if headings exist 113 if (elems === 0) { 114 $(this).prev('h2').hide(); 115 } else { 116 $(this).prev('h2').show() 117 } 118 } 119 120 elemNum = elemNum + elems; 121 }); 122 123 if (elemNum === 0) { 124 errorMessage.text('No matches'); 125 } else { 126 errorMessage.text('Found: ' + elemNum); 127 } 128 } 129 } 130});
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.