From ce524bdf5755c59187265b54ad587a3c3ffe6b7b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 17 Jun 2016 07:15:50 +0100 Subject: [PATCH] Use separate content filter event handler --- src/gui/html/js/events.js | 60 ++++++++++++++++------------------- src/gui/html/js/initialise.js | 2 +- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/gui/html/js/events.js b/src/gui/html/js/events.js index f3ba0933..26d5e163 100644 --- a/src/gui/html/js/events.js +++ b/src/gui/html/js/events.js @@ -1,13 +1,34 @@ 'use strict'; function onSidebarFilterToggle(evt) { - if (evt.target.id !== 'contentFilter') { - loot.filters[evt.target.id] = evt.target.checked; - loot.query('saveFilterState', evt.target.id, evt.target.checked).catch(loot.handlePromiseError); - } else { - loot.filters.contentSearchString = evt.target.value; - } + loot.filters[evt.target.id] = evt.target.checked; + loot.query('saveFilterState', evt.target.id, evt.target.checked).catch(loot.handlePromiseError); loot.filters.apply(loot.game.plugins); } +function onContentFilter(evt) { + loot.filters.contentSearchString = evt.target.value; + loot.filters.apply(loot.game.plugins); +} +function onConflictsFilter(evt) { + /* evt.currentTarget.value is the name of the target plugin, or an empty string + if the filter has been deactivated. */ + if (evt.currentTarget.value) { + /* Now get conflicts for the plugin. */ + loot.Dialog.showProgress(loot.l10n.translate('Identifying conflicting plugins...')); + loot.filters.activateConflictsFilter(evt.currentTarget.value).then((plugins) => { + plugins.forEach((plugin) => { + const gamePlugin = loot.game.plugins.find(item => item.name === plugin.name); + if (gamePlugin) { + gamePlugin.update(plugin); + } + }); + loot.filters.apply(loot.game.plugins); + loot.Dialog.closeProgress(); + }).catch(loot.handlePromiseError); + } else { + loot.filters.deactivateConflictsFilter(); + loot.filters.apply(loot.game.plugins); + } +} function onJumpToGeneralInfo() { document.getElementById('pluginCardList').scroll(0, 0); } @@ -408,33 +429,6 @@ function onEditorClose(evt) { loot.state.exitEditingState(); }).catch(loot.handlePromiseError); } -function onConflictsFilter(evt) { - /* evt.currentTarget.value is the name of the target plugin, or an empty string - if the filter has been deactivated. */ - if (evt.currentTarget.value) { - /* Now get conflicts for the plugin. */ - loot.Dialog.showProgress(loot.l10n.translate('Identifying conflicting plugins...')); - loot.filters.activateConflictsFilter(evt.currentTarget.value).then((plugins) => { - plugins.forEach((plugin) => { - const gamePlugin = loot.game.plugins.find(item => item.name === plugin.name); - if (gamePlugin) { - gamePlugin.update(plugin); - } - }); - loot.filters.apply(loot.game.plugins); - - /* Scroll to the target plugin */ - const list = document.getElementById('pluginCardList'); - const index = list.items.findIndex(item => item.name === evt.target.value); - list.scrollToIndex(index); - - loot.Dialog.closeProgress(); - }).catch(loot.handlePromiseError); - } else { - loot.filters.deactivateConflictsFilter(); - loot.filters.apply(loot.game.plugins); - } -} function onCopyMetadata(evt) { loot.query('copyMetadata', evt.target.getName()).then(() => { loot.Dialog.showNotification(loot.l10n.translate('The metadata for "%s" has been copied to the clipboard.', evt.target.getName())); diff --git a/src/gui/html/js/initialise.js b/src/gui/html/js/initialise.js index f142220c..d9d82308 100644 --- a/src/gui/html/js/initialise.js +++ b/src/gui/html/js/initialise.js @@ -58,7 +58,7 @@ document.getElementById('hideInactivePlugins').addEventListener('change', onSidebarFilterToggle); document.getElementById('hideAllPluginMessages').addEventListener('change', onSidebarFilterToggle); document.getElementById('hideMessagelessPlugins').addEventListener('change', onSidebarFilterToggle); - document.getElementById('contentFilter').addEventListener('change', onSidebarFilterToggle); + document.getElementById('contentFilter').addEventListener('change', onContentFilter); document.getElementById('conflictsFilter').addEventListener('iron-select', onConflictsFilter); document.addEventListener('loot-filter-conflicts-deactivate', Filters.onDeactivateConflictsFilter);