diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-10-03 16:46:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-03 16:46:15 -0400 |
commit | be8ef53e90c3893dc2696b846dadb185be8c4514 (patch) | |
tree | 93b75d0f2f974e12a2a3d33dc9b51dc674a43504 /ext/js/display/display-anki.js | |
parent | d14268eb574d39b5ecc1e83302d45d5933770a73 (diff) |
Display refactoring (#1978)
* Refactor _setContentTermsOrKanji
* Update query assignment
* Simplify
* Remove redundant _updateQueryParser
* Reorder query assignment
* Remove isTerms, replace with isKanji
* Simplify defaults
* Refactor events
* Update DisplayAnki to use events
* Simplify
* Update DisplayAudio to use events
* Simplify
* Move audio hotkeys
* Add frameVisibilityChange event
* Fix name
* Add logDictionaryEntryData event
* Move clearAutoPlayTimer handler
* Fix call
* Externalize DisplayAnki and DisplayAudio from Display
* Simplify clear
Diffstat (limited to 'ext/js/display/display-anki.js')
-rw-r--r-- | ext/js/display/display-anki.js | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index 216e3108..46e88ae0 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -23,8 +23,9 @@ */ class DisplayAnki { - constructor(display, japaneseUtil) { + constructor(display, displayAudio, japaneseUtil) { this._display = display; + this._displayAudio = displayAudio; this._ankiFieldTemplates = null; this._ankiFieldTemplatesDefault = null; this._ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil}); @@ -70,28 +71,11 @@ class DisplayAnki { ['viewNote', this._viewNoteForSelectedEntry.bind(this)] ]); this._display.on('optionsUpdated', this._onOptionsUpdated.bind(this)); - } - - cleanupEntries() { - this._updateDictionaryEntryDetailsToken = null; - this._dictionaryEntryDetails = null; - this._hideAnkiNoteErrors(false); - } - - setupEntriesBegin() { - this._noteContext = this._getNoteContext(); - } - - setupEntry(entry) { - this._addMultipleEventListeners(entry, '.action-view-tags', 'click', this._onShowTagsBind); - this._addMultipleEventListeners(entry, '.action-add-note', 'click', this._onNoteAddBind); - this._addMultipleEventListeners(entry, '.action-view-note', 'click', this._onViewNoteButtonClickBind); - this._addMultipleEventListeners(entry, '.action-view-note', 'contextmenu', this._onViewNoteButtonContextMenuBind); - this._addMultipleEventListeners(entry, '.action-view-note', 'menuClose', this._onViewNoteButtonMenuCloseBind); - } - - setupEntriesComplete() { - this._updateDictionaryEntryDetails(); + this._display.on('contentClear', this._onContentClear.bind(this)); + this._display.on('contentUpdateStart', this._onContentUpdateStart.bind(this)); + this._display.on('contentUpdateEntry', this._onContentUpdateEntry.bind(this)); + this._display.on('contentUpdateComplete', this._onContentUpdateComplete.bind(this)); + this._display.on('logDictionaryEntryData', this._onLogDictionaryEntryData.bind(this)); } async getLogData(dictionaryEntry) { @@ -173,6 +157,32 @@ class DisplayAnki { this._updateAnkiFieldTemplates(options); } + _onContentClear() { + this._updateDictionaryEntryDetailsToken = null; + this._dictionaryEntryDetails = null; + this._hideAnkiNoteErrors(false); + } + + _onContentUpdateStart() { + this._noteContext = this._getNoteContext(); + } + + _onContentUpdateEntry({element}) { + this._addMultipleEventListeners(element, '.action-view-tags', 'click', this._onShowTagsBind); + this._addMultipleEventListeners(element, '.action-add-note', 'click', this._onNoteAddBind); + this._addMultipleEventListeners(element, '.action-view-note', 'click', this._onViewNoteButtonClickBind); + this._addMultipleEventListeners(element, '.action-view-note', 'contextmenu', this._onViewNoteButtonContextMenuBind); + this._addMultipleEventListeners(element, '.action-view-note', 'menuClose', this._onViewNoteButtonMenuCloseBind); + } + + _onContentUpdateComplete() { + this._updateDictionaryEntryDetails(); + } + + _onLogDictionaryEntryData({dictionaryEntry, promises}) { + promises.push(this.getLogData(dictionaryEntry)); + } + _onNoteAdd(e) { e.preventDefault(); const node = e.currentTarget; @@ -526,7 +536,7 @@ class DisplayAnki { const fields = Object.entries(modeOptions.fields); const contentOrigin = this._display.getContentOrigin(); const details = this._ankiNoteBuilder.getDictionaryEntryDetailsForNote(dictionaryEntry); - const audioDetails = (details.type === 'term' ? this._display.getAnkiNoteMediaAudioDetails(details.term, details.reading) : null); + const audioDetails = (details.type === 'term' ? this._displayAudio.getAnkiNoteMediaAudioDetails(details.term, details.reading) : null); const optionsContext = this._display.getOptionsContext(); const {note, errors, requirements: outputRequirements} = await this._ankiNoteBuilder.createNote({ |