Implement new search event handlers

This commit is contained in:
Oliver Hamlet
2016-03-05 11:49:26 +00:00
parent 863a6bc226
commit 03d8c96e30
2 changed files with 32 additions and 2 deletions
+29 -1
View File
@@ -576,6 +576,34 @@ function onSearchOpen() {
document.getElementById('mainToolbar').classList.add('search');
document.getElementById('searchBar').focusInput();
}
function onSearchClose() {
function onSearchBegin(evt) {
loot.game.plugins.forEach((plugin) => {
plugin.isSearchResult = false;
});
if (!evt.detail.needle) {
return;
}
// Don't push to the target's results property directly, as the
// change observer doesn't work correctly unless special Polymer APIs
// are used, which I don't want to get into.
const results = [];
loot.game.plugins.forEach((plugin, index) => {
if (plugin.getCardContent(loot.filters).containsText(evt.detail.needle)) {
results.push(index);
plugin.isSearchResult = true;
}
});
evt.target.results = results;
}
function onSearchChangeSelection(evt) {
document.getElementById('pluginCardList').scrollToIndex(evt.detail.selection);
}
function onSearchEnd(evt) {
loot.game.plugins.forEach((plugin) => {
plugin.isSearchResult = false;
});
document.getElementById('mainToolbar').classList.remove('search');
}
+3 -1
View File
@@ -75,7 +75,9 @@
/* Set up search event handlers. */
document.getElementById('showSearch').addEventListener('click', onSearchOpen);
document.getElementById('searchBar').addEventListener('loot-search-close', onSearchClose);
document.getElementById('searchBar').addEventListener('loot-search-begin', onSearchBegin);
document.getElementById('searchBar').addEventListener('loot-search-change-selection', onSearchChangeSelection, false);
document.getElementById('searchBar').addEventListener('loot-search-end', onSearchEnd);
window.addEventListener('keyup', onFocusSearch);
/* Set up event handlers for settings dialog. */