From 7d93587acb250266782e3788894a9e26ddf1eaa5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 19 Oct 2016 08:52:22 -0700 Subject: Conditionally show add buttons --- ext/fg/js/driver.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 1be69f11..75dbe219 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -139,14 +139,25 @@ class Driver { }); const sequence = ++this.sequence; - return renderText({definitions, sequence, root: this.fgRoot, options: this.options}, 'term-list.html').then(content => { + const context = { + definitions, + sequence, + addable: this.options.ankiMethod !== 'disabled', + root: this.fgRoot, + options: this.options + }; + + return renderText(context, 'term-list.html').then(content => { this.definitions = definitions; this.pendingLookup = false; this.showPopup(textSource, content); return canAddDefinitions(definitions, ['term_kanji', 'term_kana']); }).then(states => { if (states !== null) { - states.forEach((state, index) => this.popup.invokeApi('setActionState', {index, state, sequence})); + states.forEach((state, index) => this.popup.invokeApi( + 'setActionState', + {index, state, sequence} + )); } return true; @@ -167,14 +178,25 @@ class Driver { definitions.forEach(definition => definition.url = window.location.href); const sequence = ++this.sequence; - return renderText({definitions, sequence, root: this.fgRoot, options: this.options}, 'kanji-list.html').then(content => { + const context = { + definitions, + sequence, + addable: this.options.ankiMethod !== 'disabled', + root: this.fgRoot, + options: this.options + }; + + return renderText(context, 'kanji-list.html').then(content => { this.definitions = definitions; this.pendingLookup = false; this.showPopup(textSource, content); return canAddDefinitions(definitions, ['kanji']); }).then(states => { if (states !== null) { - states.forEach((state, index) => this.popup.invokeApi('setActionState', {index, state, sequence})); + states.forEach((state, index) => this.popup.invokeApi( + 'setActionState', + {index, state, sequence} + )); } return true; @@ -278,7 +300,15 @@ class Driver { definitions.forEach(definition => definition.url = window.location.href); const sequence = ++this.sequence; - return renderText({definitions, sequence, root: this.fgRoot, options: this.options}, 'kanji-list.html').then(content => { + const context = { + definitions, + sequence, + addable: this.options.ankiMethod !== 'disabled', + root: this.fgRoot, + options: this.options + }; + + return renderText(context, 'kanji-list.html').then(content => { this.definitions = definitions; this.popup.setContent(content, definitions); return canAddDefinitions(definitions, ['kanji']); -- cgit v1.2.3