Review players search behavior (arrow keys and click outside)

This commit is contained in:
Claude Brisson
2024-02-24 06:04:42 +01:00
parent 816ef24136
commit 945ae093d3
3 changed files with 23 additions and 5 deletions

View File

@@ -16,7 +16,7 @@ function initSearch() {
}
function searchResultShown() {
return !(typeof(searchHighlight) === 'undefined' || !searchResult || !searchResult.length || typeof(searchResult[searchHighlight]) === 'undefined')
return !(!searchResult || !searchResult.length)
}
function search(needle) {
@@ -40,7 +40,6 @@ function search(needle) {
store('searchFormState', searchFormState);
api.postJson('search', search)
.then(result => {
console.log(result)
if (Array.isArray(result)) {
searchResult = result
let html = resultTemplate.render(result);
@@ -272,6 +271,21 @@ onLoad(() => {
let index = e.target.closest('.result-line').data('index');
fillPlayer(searchResult[index]);
}
let tab = document.location.hash;
if (store('addingPlayers') && tab === '#registration') {
let modal = e.target.closest('#player');
if (!modal) {
let button = e.target.closest('button');
if (!button) {
if (searchResultShown()) {
$('#needle')[0].value = '';
initSearch();
} else {
close_modal();
}
}
}
}
});
$('#unregister').on('click', e => {
let form = $('#player-form')[0];