'); var templateCompany = Hogan.compile('
'); var templatePerson = Hogan.compile('
'); var templateBuilding = Hogan.compile('
'); var templateComplex = Hogan.compile('
'); var templateCity = Hogan.compile('
'); var templateCountry = Hogan.compile('
'); var typeaheadCtrl = $('.search-inputs').typeahead({ minLength: 3, hint: false, highlight: false }, [ { source: algoliaCTBUH.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'title', templates: { header: "
CTBUH
", suggestion: function (hit) { return templateCTBUH.render(hit); }, } }, { source: algoliaPeople.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict', filters: 'public_search = 1' }), displayKey: 'name', templates: { header: "
People
", suggestion: function (hit) { hit.url = hit.profile_link; return templatePerson.render(hit); }, } }, { source: algoliaBuildings.ttAdapter({ hitsPerPage: 4, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'name', templates: { header: "
Buildings
", suggestion: function (hit) { var cityToUse = ''; var nameToUse = hit._highlightResult.name.value; if (hit.city != '') { cityToUse = ' (' + hit.city + ')'; } hit.cityToUse = cityToUse; hit.nameToUse = nameToUse; return templateBuilding.render(hit); } } }, { source: algoliaComplexes.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'name', templates: { header: "
Building Complexes
", suggestion: function (hit) { var cityToUse = ''; var nameToUse = hit._highlightResult.name.value; if (hit.city != '') { cityToUse = ' (' + hit.city + ')'; } hit.cityToUse = cityToUse; hit.nameToUse = nameToUse; return templateComplex.render(hit); } } }, { source: algoliaCompanies.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'name', templates: { header: "
Companies
", suggestion: function (hit) { hit.url = '/company/' + hit.id; return templateCompany.render(hit); }, } }, // add CITY + COUNTRY { source: algoliaCities.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'name', templates: { header: "
Cities
", suggestion: function (hit) { if (hit.slug) { hit.url_name = hit.slug; } else { hit.url_name = hit.name.replace(/ /g, '-').toLowerCase(); } return templateCity.render(hit); }, } }, { source: algoliaCountries.ttAdapter({ hitsPerPage: 3, replaceSynonymsInHighlight: false, typoTolerance: 'strict' }), displayKey: 'name', templates: { header: "
Countries
", suggestion: function (hit) { hit.url_name = hit.name.replace(/ /g, '-').toLowerCase(); return templateCountry.render(hit); }, } } // this is the end ]); typeaheadCtrl.on('typeahead:selected', function (evt, data) { if (false && typeof data.url === "undefined") { alert(JSON.stringify(data)); } else { window.location = 'https://' + window.location.host + data.url; } }); // Append view all link var AllResults = document.getElementsByClassName('all-results'); if (AllResults.length == 0) { $('.tt-dropdown-menu').append('
View all results
'); } $('#view-all-link').on('click', function (e) { e.preventDefault(); window.location = '/search#q=' + $('.search-inputs').val(); }); // Append Algolia credit var AlgoliaCredits = document.getElementsByClassName('powered-by-algoliasearch'); if (AlgoliaCredits.length == 0) { $('.tt-dropdown-menu').append('
'); } });