more cleanup

This commit is contained in:
Alex Yatskov 2017-08-05 19:11:06 -07:00
parent 8e1c6776d1
commit dfecef1f23
3 changed files with 13 additions and 10 deletions

View File

@ -35,7 +35,7 @@ async function apiOptionsSet(options) {
// to the DOM across to the background page, causing the options object to // to the DOM across to the background page, causing the options object to
// become a "DeadObject" after the options page is closed. The workaround used // become a "DeadObject" after the options page is closed. The workaround used
// here is to create a deep copy of the options object. // here is to create a deep copy of the options object.
backend().optionsSet(JSON.parse(JSON.stringify(options))); backend().onOptionsUpdated(JSON.parse(JSON.stringify(options)));
} }
async function apiOptionsGet() { async function apiOptionsGet() {

View File

@ -36,7 +36,7 @@ window.yomichan_backend = new class {
} }
} }
optionsSet(options) { onOptionsUpdated(options) {
this.options = options; this.options = options;
if (!options.general.enable) { if (!options.general.enable) {

View File

@ -21,12 +21,11 @@ window.displayWindow = new class extends Display {
constructor() { constructor() {
super($('#spinner'), $('#content')); super($('#spinner'), $('#content'));
const search = $('#search'); this.search = $('#search').click(this.onSearch.bind(this));
search.click(this.onSearch.bind(this)); this.query = $('#query').on('input', this.inputSearch.bind(this));
this.intro = $('#intro');
const query = $('#query'); window.wanakana.bind(this.query.get(0));
query.on('input', () => search.prop('disabled', query.val().length === 0));
window.wanakana.bind(query.get(0));
} }
handleError(error) { handleError(error) {
@ -34,15 +33,19 @@ window.displayWindow = new class extends Display {
} }
clearSearch() { clearSearch() {
$('#query').focus().select(); this.query.focus().select();
}
inputSearch() {
this.search.prop('disabled', this.query.val().length === 0);
} }
async onSearch(e) { async onSearch(e) {
e.preventDefault(); e.preventDefault();
try { try {
$('#intro').slideUp(); this.intro.slideUp();
const {length, definitions} = await apiTermsFind($('#query').val()); const {length, definitions} = await apiTermsFind(this.query.val());
super.showTermDefs(definitions, await apiOptionsGet()); super.showTermDefs(definitions, await apiOptionsGet());
} catch (e) { } catch (e) {
this.handleError(e); this.handleError(e);