Clear results on empty search
This commit is contained in:
parent
afb086d2ed
commit
204d5837c5
@ -26,10 +26,18 @@ function fireChangeEvents(element){
|
||||
console.debug('change event dispatched for element: ' + element.id);
|
||||
}
|
||||
|
||||
function removeSearchResults() {
|
||||
var resultList = document.getElementById('tapiResults');
|
||||
if (resultList) {
|
||||
resultList.parentNode.removeChild(resultList);
|
||||
}
|
||||
}
|
||||
|
||||
var doSearch = function () {
|
||||
var search = document.getElementById('tapiSearchInput');
|
||||
var searchText = search.value.trim();
|
||||
if (searchText == '') {
|
||||
removeSearchResults();
|
||||
return;
|
||||
}
|
||||
console.log('Searching TAPI');
|
||||
@ -40,10 +48,7 @@ var doSearch = function() {
|
||||
console.log('TAPI Search response', response);
|
||||
var contacts = JSON.parse(response.responseText);
|
||||
console.log('TAPI Contacts', contacts);
|
||||
var resultList = document.getElementById('tapiResults');
|
||||
if (resultList) {
|
||||
resultList.parentNode.removeChild(resultList);
|
||||
}
|
||||
removeSearchResults();
|
||||
|
||||
resultList = document.createElement('ul');
|
||||
resultList.id = 'tapiResults';
|
||||
@ -56,8 +61,12 @@ var doSearch = function() {
|
||||
var li = document.createElement('li');
|
||||
li.classList.add('search-result');
|
||||
li.classList.add('pointer');
|
||||
li.onmouseover = function() { this.classList.add('bg-light'); };
|
||||
li.onmouseout = function() { this.classList.remove('bg-light'); };
|
||||
li.onmouseover = function () {
|
||||
this.classList.add('bg-light');
|
||||
};
|
||||
li.onmouseout = function () {
|
||||
this.classList.remove('bg-light');
|
||||
};
|
||||
li.contact = contacts[i];
|
||||
li.onclick = function () {
|
||||
var contact = this.contact;
|
||||
@ -121,11 +130,7 @@ waitForKeyElements('div.nav-search', (element) => {
|
||||
console.log('TAPI Search exit');
|
||||
setTimeout(function () {
|
||||
console.log('TAPI clear search results');
|
||||
var resultList = document.getElementById('tapiResults');
|
||||
console.log('TAPI tapiResults', resultList);
|
||||
if (resultList) {
|
||||
resultList.parentNode.removeChild(resultList);
|
||||
};
|
||||
removeSearchResults();
|
||||
}, 500);
|
||||
};
|
||||
searchWrapper.appendChild(search);
|
||||
@ -139,4 +144,3 @@ waitForKeyElements('div.nav-search', (element) => {
|
||||
|
||||
element.appendChild(form);
|
||||
}, false);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user