1let brainSearchSuggest = { 2 /** 3 * Initialize suggest search action ajax calls 4 */ 5 init: function () { 6 let self = this; 7 self.initSearchToggle(); 8 self.initTypeahead(); 9 }, 10 initSearchToggle: function () { 11 let btnSearchToggle = document.querySelector('.search-toggle'); 12 if (btnSearchToggle) { 13 btnSearchToggle.addEventListener('ba-nav-on-open', function (evt) { 14 let target = document.querySelector(btnSearchToggle.dataset.target); 15 if (target.classList.contains('in')) { 16 document.body.classList.remove('search-modal-open'); 17 document.body.classList.remove('search-is-closing'); 18 target.classList.remove('in'); 19 let mvbItem = document.querySelector('.search-visible-background'); 20 mvbItem.remove(); 21 target.classList.add('collapse'); 22 btnSearchToggle.setAttribute('aria-expanded', 'false'); 23 target.removeAttribute('style'); 24 } 25 }); 26 btnSearchToggle.addEventListener('click', function (evt) { 27 evt.preventDefault(); 28 let target = document.querySelector(btnSearchToggle.dataset.target); 29 if (target.classList.contains('in')) { 30 target.classList.remove('in'); 31 target.classList.add('collapsing'); 32 let mvbItem = document.querySelector('.search-visible-background'); 33 document.body.classList.add('search-is-closing'); 34 setTimeout(function () { 35 target.classList.remove('collapsing'); 36 target.classList.add('collapse'); 37 mvbItem.remove(); 38 document.body.classList.remove('search-modal-open'); 39 document.body.classList.remove('search-is-closing'); 40 btnSearchToggle.setAttribute('aria-expanded', 'false'); 41 target.removeAttribute('style'); 42 }, 400); 43 } else { 44 let searchOpenEvent = new CustomEvent('ba-search-on-open'); 45 document 46 .querySelectorAll('.js-search-on-open') 47 .forEach(function (listener) { 48 listener.dispatchEvent(searchOpenEvent); 49 }); 50 if (document.body.classList.contains('d-nav-open')) { 51 let navbarMain = document.getElementById('navbar-main'); 52 let dropdownExpanded = navbarMain.querySelector( 53 '.js-toggle-sub-nav[aria-expanded="true"]', 54 ); 55 if (dropdownExpanded) { 56 dropdownExpanded.click(); 57 } else { 58 document.body.classList.remove('d-nav-open'); 59 } 60 } 61 document.body.classList.add('search-modal-open'); 62 target.classList.remove('collapse'); 63 target.classList.add('collapsing'); 64 65 let minHeight = jQuery('.wrap.all').outerHeight(); 66 let mvbItem = document.createElement('div'); 67 mvbItem.setAttribute('class', 'search-visible-background'); 68 mvbItem.style.minHeight = minHeight + 'px'; 69 document.body.prepend(mvbItem); 70 setTimeout(function () { 71 target.classList.remove('collapsing'); 72 target.classList.add('collapse', 'in'); 73 btnSearchToggle.setAttribute('aria-expanded', 'true'); 74 }, 400); 75 } 76 }); 77 } 78 }, 79 initTypeahead: function () { 80 let self = this; 81 let typeAheadList = document.querySelectorAll('.typeahead'); 82 typeAheadList.forEach(function (listElt) { 83 // @see extensions/hs_lu_t3theme/Resources/Private/Partials/Page/Search.html 84 let searchUrl = listElt.dataset.searchurl; 85 //let sep = searchUrl.indexOf('?') >= 0 ? '&' : '?'; 86 //searchUrl += sep + 'tx_hslut3theme_suggest[search]=%QUERY'; 87 let suggester = new Bloodhound({ 88 datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), 89 queryTokenizer: Bloodhound.tokenizers.whitespace, 90 remote: { 91 cache: 'false', 92 url: searchUrl, 93 wildcard: 'SGQUERY', 94 transport: function (ajaxOptions, onSuccess, onError) { 95 ajaxOptions.dataType = 'html'; 96 $.ajax(ajaxOptions).done(done).fail(fail); 97 98 function done(data, textStatus, request) { 99 onSuccess(JSON.parse(self.removeHTML(data))); 100 } 101 102 function fail(request, textStatus, errorThrown) { 103 onError(errorThrown); 104 } 105 }, 106 }, 107 }); 108 suggester.initialize(); 109 110 let textMinLength = listElt.dataset.minLength; 111 if (!textMinLength || textMinLength < 1) { 112 textMinLength = 2; 113 } 114 let resultLimit = listElt.dataset.limit; 115 if (!resultLimit || resultLimit < 2) { 116 resultLimit = 10; 117 } 118 $(listElt) 119 .typeahead( 120 { 121 hint: false, 122 highlight: true, 123 minLength: textMinLength, 124 }, 125 { 126 limit: resultLimit, 127 displayKey: 'value', 128 source: suggester.ttAdapter(), 129 }, 130 ) 131 .on('typeahead:selected', function (e) { 132 e.target.form.requestSubmit(); 133 }) 134 .on( 135 'typeahead:open typeahead:render typeahead:active', 136 function (ev, suggestion) { 137 let $container = $(listElt).parents('.ba-tt-container'); 138 let $ttDataset = $container.find('.tt-dataset'); 139 $container.toggleClass('tt-open', !$ttDataset.is(':empty')); 140 }, 141 ) 142 .on('typeahead:close typeahead:idle', function (ev, suggestion) { 143 $(listElt).parents('.ba-tt-container').removeClass('tt-open'); 144 }); 145 }); 146 }, 147 removeHTML: function (input) { 148 return input.replace(/<\/?[^>]+>/gi, ''); 149 }, 150};
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.