1(function ($) { 2 const $search = $('#search'); 3 const $search_input = $search.find('input[name=\'search\']'); 4 const $search_button = $('.search-button'); 5 6 function search() { 7 const query = $search_input.val().trim(); 8 9 if (!query) { 10 return false; 11 } 12 13 let url = Journal['search_url'].replace('__QUERY__', query); 14 15 const category_id = parseInt($search_input.attr('data-category_id'), 10); 16 17 if (category_id) { 18 url += '&category_id=' + category_id.toString(); 19 20 if (Journal['searchStyleSearchAutoSuggestSubCategories']) { 21 url += '&sub_category=1'; 22 } 23 } 24 25 if (Journal['searchStyleSearchAutoSuggestDescription']) { 26 url += '&description=1'; 27 } 28 29 window.location.href = url; 30 } 31 32 // set search category 33 $(document).on('click', '.search-categories li', function (e) { 34 const $this = $(this); 35 36 $('.search-categories-button').html($this.html()); 37 38 $search_input.attr('data-category_id', $this.attr('data-category_id')); 39 $search_input.focus(); 40 }); 41 42 // search page open 43 $search.on('shown.bs.dropdown', function (e) { 44 if (e.relatedTarget.classList.contains('search-trigger')) { 45 document.documentElement.classList.add('search-page-open'); 46 } 47 }); 48 49 $search.on('hide.bs.dropdown', function (e) { 50 if (e.relatedTarget.classList.contains('search-trigger')) { 51 document.documentElement.classList.remove('search-page-open'); 52 } 53 }); 54 55 // trigger focus 56 $search.on('shown.bs.dropdown', function () { 57 $search_input.focus(); 58 }); 59 60 // search focus 61 $search_input.on('focus', function () { 62 $(this).closest('.header-search').addClass('focused'); 63 }); 64 65 $search_input.on('blur', function () { 66 $(this).closest('.header-search').removeClass('focused'); 67 }); 68 69 $(function () { 70 // search on click 71 $search_button.off('click').on('click', function (e) { 72 search(); 73 }); 74 75 // search on enter 76 $search_input.off('keydown').on('keydown', function (e) { 77 if (e.keyCode === 13) { 78 search(); 79 } 80 }); 81 }); 82 83 // Autosuggest 84 if (Journal['searchStyleSearchAutoSuggestStatus']) { 85 $('#search-input-el').one('focus', function () { 86 Journal.load(Journal['assets']['typeahead'], 'typeahead', function () { 87 $search_input.typeahead({ 88 classNames: { 89 menu: `tt-menu ${Journal[Journal['mobile_header_active'] ? 'header_mobile_search_results_color_scheme' : 'header_search_results_color_scheme']}` 90 }, 91 hint: true, 92 minLength: 1, 93 autoSelect: true 94 }, { 95 async: true, 96 display: 'name', 97 limit: Infinity, 98 source: function (query, processSync, processAsync) { 99 let url = Journal['autosuggest_url'].replace('__QUERY__', query); 100 101 const category_id = parseInt($search_input.attr('data-category_id'), 10); 102 103 if (category_id) { 104 url += '&category_id=' + category_id.toString(); 105 106 if (Journal['searchStyleSearchAutoSuggestSubCategories']) { 107 url += '&sub_category=1'; 108 } 109 } 110 111 if (Journal['searchStyleSearchAutoSuggestDescription']) { 112 url += '&description=1'; 113 } 114 115 if (window['__journal_search_timeout']) { 116 clearTimeout(window['__journal_search_timeout']); 117 } 118 119 window['__journal_search_timeout'] = setTimeout(function () { 120 if (window['__journal_search_ajax']) { 121 window['__journal_search_ajax'].abort(); 122 } 123 124 window['__journal_search_ajax'] = $.get({ 125 url: url, 126 dataType: 'json', 127 success: function (json) { 128 return processAsync(json['response']); 129 } 130 }); 131 }, 250); 132 }, 133 templates: { 134 suggestion: function (data) { 135 if (data['view_more']) { 136 return '<div class="search-result view-more"><a href="' + data['href'] + '">' + data['name'] + '</a></div>'; 137 } 138 139 if (data['no_results']) { 140 return '<div class="search-result no-results"><a>' + data['name'] + '</a></div>'; 141 } 142 143 var html = ''; 144 145 html += '<div class="search-result"><a href="' + data['href'] + '">'; 146 147 if (data['thumb']) { 148 html += '<img src="' + data['thumb'] + '" srcset="' + data['thumb'] + ' 1x, ' + data['thumb2'] + ' 2x" />'; 149 } 150 151 var classes = []; 152 153 if (data['quantity'] <= 0) { 154 classes.push('out-of-stock'); 155 } 156 157 if (!data['price_value']) { 158 classes.push('has-zero-price'); 159 } 160 161 html += '<span class="' + classes.join(' ') + '">'; 162 163 html += '<span class="product-name">' + data['name'] + '</span>'; 164 165 if (data['price']) { 166 if (data['special']) { 167 html += '<span><span class="price-old">' + data['price'] + '</span><span class="price-new">' + data['special'] + '</span></span>'; 168 } else { 169 html += '<span class="price">' + data['price'] + '</span>'; 170 } 171 } 172 173 html += '</span>'; 174 175 html += '</a></div>'; 176 177 return html; 178 } 179 } 180 181 }); 182 183 $('.header-search > span > div').addClass('tt-empty'); 184 185 $('#search-input-el').trigger('focus'); 186 187 // mobile page zoom fix 188 $('.mobile .tt-menu').on('click', function (e) { 189 e.stopPropagation(); 190 }); 191 }); 192 }); 193 } 194})(jQuery);
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.