Enable entering search text before results are loaded

This commit is contained in:
Hillel Coren 2016-03-14 10:25:08 +02:00
parent ed7cbf1d2b
commit 9c0eaac6b8

View File

@ -258,18 +258,16 @@
localStorage.setItem('auth_provider', provider); localStorage.setItem('auth_provider', provider);
} }
window.loadedSearchData = false;
function showSearch() { function showSearch() {
$('#search').typeahead('val', ''); $('#search').typeahead('val', '');
$('#navbar-options').hide(); $('#navbar-options').hide();
$('#search-form').show(); $('#search-form').show();
$('#search').focus();
if (window.hasOwnProperty('loadedSearchData')) {
$('#search').focus(); if (!window.loadedSearchData) {
} else {
trackEvent('/activity', '/search'); trackEvent('/activity', '/search');
$.get('{{ URL::route('getSearchData') }}', function(data) { $.get('{{ URL::route('getSearchData') }}', function(data) {
window.loadedSearchData = true;
$('#search').typeahead({ $('#search').typeahead({
hint: true, hint: true,
highlight: true, highlight: true,
@ -307,6 +305,7 @@
).on('typeahead:selected', function(element, datum, name) { ).on('typeahead:selected', function(element, datum, name) {
window.location = datum.url; window.location = datum.url;
}).focus(); }).focus();
window.loadedSearchData = true;
}); });
} }
} }
@ -322,7 +321,9 @@
}, 3000); }, 3000);
$('#search').blur(function(event){ $('#search').blur(function(event){
hideSearch(); if (window.loadedSearchData) {
hideSearch();
}
}); });
if (isStorageSupported()) { if (isStorageSupported()) {