1 var module_25007063275 = (function() { 2 var __hs_messages = {}; 3 i18n_getmessage = function() { 4 return hs_i18n_getMessage(__hs_messages, hsVars['language'], arguments); 5 }; 6 i18n_getlanguage = function() { 7 return hsVars['language']; 8 }; 9document.addEventListener("DOMContentLoaded", function(event) { 10var hsSearch = function(_instance) { 11 var TYPEAHEAD_LIMIT = 3; 12 var searchTerm = "", 13 searchForm = _instance, 14 searchField = _instance.querySelector('.hs-search-field__input'), 15 searchResults = _instance.querySelector('.hs-search-field__suggestions'), 16 searchOptions = function() { 17 var formParams = []; 18 var form = _instance.querySelector('form'); 19 for ( var i = 0; i < form.querySelectorAll('input[type=hidden]').length; i++ ) { 20 var e = form.querySelectorAll('input[type=hidden]')[i]; 21 if (e.name !== 'limit') { 22 formParams.push(encodeURIComponent(e.name) + "=" + encodeURIComponent(e.value)); 23 } 24 } 25 var queryString = formParams.join("&"); 26 console.log("..." + queryString); 27 return queryString; 28 }; 29 30 var debounce = function(func, wait, immediate) { 31 var timeout; 32 return function() { 33 var context = this, 34 args = arguments; 35 var later = function() { 36 timeout = null; 37 if ( !immediate ) { 38 func.apply(context, args); 39 } 40 }; 41 var callNow = immediate && !timeout; 42 clearTimeout(timeout); 43 timeout = setTimeout(later, wait || 200); 44 if ( callNow ) { 45 func.apply(context, args); 46 } 47 }; 48 }, 49 emptySearchResults = function(){ 50 searchResults.innerHTML = ''; 51 searchField.focus(); 52 searchForm.classList.remove('hs-search-field--open'); 53 }, 54 fillSearchResults = function(response){ 55 var items = []; 56 items.push( "<li id='results-for'>Results for \"" + response.searchTerm + "\"</li>" ); 57 response.results.forEach(function(val, index) { 58 items.push( "<li id='result" + index + "'><a href='" + val.url + "'>" + val.title + "</a></li>" ); 59 }); 60 61 emptySearchResults(); 62 searchResults.innerHTML = items.join(""); 63 searchForm.classList.add('hs-search-field--open'); 64 }, 65 getSearchResults = function() { 66 var request = new XMLHttpRequest(); 67 var requestUrl = "/_hcms/search?&term="+encodeURIComponent(searchTerm)+"&limit="+encodeURIComponent(TYPEAHEAD_LIMIT)+"&autocomplete=true&analytics=false&" + searchOptions(); 68 69 request.open('GET', requestUrl, true); 70 request.onload = function() { 71 if (request.status >= 200 && request.status < 400) { 72 var data = JSON.parse(request.responseText); 73 if (data.total > 0) { 74 fillSearchResults(data); 75 trapFocus(); 76 } 77 else { 78 emptySearchResults(); 79 } 80 } else { 81 console.error('Server reached, error retrieving results.'); 82 } 83 }; 84 request.onerror = function() { 85 console.error('Could not reach the server.'); 86 }; 87 request.send(); 88 }, 89 trapFocus = function(){ 90 var tabbable = []; 91 tabbable.push(searchField); 92 var tabbables = searchResults.getElementsByTagName('A'); 93 for (var i = 0; i < tabbables.length; i++) { 94 tabbable.push(tabbables[i]); 95 } 96 var firstTabbable = tabbable[0], 97 lastTabbable = tabbable[tabbable.length-1]; 98 var tabResult = function(e){ 99 if (e.target == lastTabbable && !e.shiftKey) { 100 e.preventDefault(); 101 firstTabbable.focus(); 102 } 103 else if (e.target == firstTabbable && e.shiftKey) { 104 e.preventDefault(); 105 lastTabbable.focus(); 106 } 107 }, 108 nextResult = function(e) { 109 e.preventDefault(); 110 if (e.target == lastTabbable) { 111 firstTabbable.focus(); 112 } 113 else { 114 tabbable.forEach(function(el){ 115 if (el == e.target) { 116 tabbable[tabbable.indexOf(el) + 1].focus(); 117 } 118 }); 119 } 120 }, 121 lastResult = function(e) { 122 e.preventDefault(); 123 if (e.target == firstTabbable) { 124 lastTabbable.focus(); 125 } 126 else { 127 tabbable.forEach(function(el){ 128 if (el == e.target) { 129 tabbable[tabbable.indexOf(el) - 1].focus(); 130 } 131 }); 132 } 133 }; 134 searchForm.addEventListener('keydown', function(e){ 135 switch (e.which) { 136 case 9: 137 tabResult(e); 138 break; 139 case 27: 140 emptySearchResults(); 141 break; 142 case 38: 143 lastResult(e); 144 break; 145 case 40: 146 nextResult(e); 147 break; 148 } 149 }); 150 }, 151 isSearchTermPresent = debounce(function() { 152 searchTerm = searchField.value; 153 if(searchTerm.length > 2) { 154 getSearchResults(); 155 } 156 else if (searchTerm.length == 0) { 157 emptySearchResults(); 158 } 159 }, 250), 160 init = (function(){ 161 searchField.addEventListener('input', function(e) { 162 if ((e.which != 9) && (e.which != 40) && (e.which != 38) && (e.which != 27) && (searchTerm != searchField.value)) { 163 isSearchTermPresent(); 164 } 165 }); 166 })(); 167} 168 169if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ 170 var searchResults = document.querySelectorAll('.hs-search-field'); 171 Array.prototype.forEach.call(searchResults, function(el){ 172 var hsSearchModule = hsSearch(el); 173 }); 174} else { 175 document.addEventListener('DOMContentLoaded', function() { 176 var searchResults = document.querySelectorAll('.hs-search-field'); 177 Array.prototype.forEach.call(searchResults, function(el){ 178 var hsSearchModule = hsSearch(el); 179 }); 180 }); 181} 182 183}); 184 185 })();
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.