From 6f530304693534bfac41dfbe77cbbd9c79387617 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 10 Nov 2019 12:25:28 -0500 Subject: Use for of loop instead of forEach --- ext/mixed/js/display.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 6d992897..df887fb0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -279,9 +279,9 @@ class Display { } addEventListeners(selector, type, listener, options) { - this.container.querySelectorAll(selector).forEach((node) => { + for (const node of this.container.querySelectorAll(selector)) { Display.addEventListener(this.eventListeners, node, type, listener, options); - }); + } } setContent(type, details) { -- cgit v1.2.3 From d6cdd693c87ffd999cb770172629a256c0b7dde1 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 10 Nov 2019 13:55:37 -0500 Subject: Fix several warnings about name conflicts --- ext/bg/js/settings.js | 12 ++++++------ ext/mixed/js/display.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 9d95e358..129d5f10 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -188,8 +188,8 @@ async function onFormOptionsChanged(e) { await ankiDeckAndModelPopulate(options); ankiErrorShow(); } - } catch (e) { - ankiErrorShow(e); + } catch (error) { + ankiErrorShow(error); } finally { ankiSpinnerShow(false); } @@ -602,8 +602,8 @@ async function onAnkiModelChanged(e) { ankiSpinnerShow(true); await ankiFieldsPopulate(element, options); ankiErrorShow(); - } catch (e) { - ankiErrorShow(e); + } catch (error) { + ankiErrorShow(error); } finally { ankiSpinnerShow(false); } @@ -627,8 +627,8 @@ async function onAnkiFieldTemplatesResetConfirm(e) { $('#field-templates').val(fieldTemplates); onAnkiTemplatesValidateCompile(); await settingsSaveOptions(); - } catch (e) { - ankiErrorShow(e); + } catch (error) { + ankiErrorShow(error); } } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index df887fb0..5a824561 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -77,8 +77,8 @@ class Display { const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); - } catch (e) { - this.onError(e); + } catch (error) { + this.onError(error); } } @@ -140,8 +140,8 @@ class Display { } this.setContentTerms(definitions, context); - } catch (e) { - this.onError(e); + } catch (error) { + this.onError(error); } } -- cgit v1.2.3 From d9b44040751846d6b0bbf5fcf6ea4152f6ce9bcc Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 10 Nov 2019 14:00:44 -0500 Subject: Create functions for the cases of isMouseButton jshint was showing a warning that there was no break statement after the first case, which there doesn't need to be. The most straightforward way to fix this without using the unclear // jshint ignore:line is to just have two functions. This change also updates invocations of isMouseButton to use the exact case function, as this will remove the need to check the case of mosueEvent.type. This was done because onMouseMove is invoked at a high frequency. --- ext/fg/js/frontend.js | 40 ++++++++++++++++++++++++++-------------- ext/mixed/js/display.js | 4 ++-- 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index e67008df..7c62b51b 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -80,7 +80,7 @@ class Frontend { onMouseMove(e) { this.popupTimerClear(); - if (this.pendingLookup || Frontend.isMouseButton('primary', e)) { + if (this.pendingLookup || Frontend.isMouseButtonDown('primary', e)) { return; } @@ -88,7 +88,7 @@ class Frontend { const scanningModifier = scanningOptions.modifier; if (!( Frontend.isScanningModifierPressed(scanningModifier, e) || - (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e)) + (scanningOptions.middleMouse && Frontend.isMouseButtonDown('auxiliary', e)) )) { return; } @@ -504,18 +504,30 @@ class Frontend { switch (mouseEvent.type) { case 'mouseup': case 'mousedown': - case 'click': switch (button) { - case 'primary': return mouseEvent.button === 0; - case 'secondary': return mouseEvent.button === 2; - case 'auxiliary': return mouseEvent.button === 1; - default: return false; - } - default: switch (button) { - case 'primary': return (mouseEvent.buttons & 0x1) !== 0x0; - case 'secondary': return (mouseEvent.buttons & 0x2) !== 0x0; - case 'auxiliary': return (mouseEvent.buttons & 0x4) !== 0x0; - default: return false; - } + case 'click': + return Frontend.isMouseButtonPressed(button, mouseEvent); + default: + return Frontend.isMouseButtonDown(button, mouseEvent); + } + } + + static isMouseButtonPressed(button, mouseEvent) { + const mouseEventButton = mouseEvent.button; + switch (button) { + case 'primary': return mouseEventButton === 0; + case 'secondary': return mouseEventButton === 2; + case 'auxiliary': return mouseEventButton === 1; + default: return false; + } + } + + static isMouseButtonDown(button, mouseEvent) { + const mouseEventButtons = mouseEvent.buttons; + switch (button) { + case 'primary': return (mouseEventButtons & 0x1) !== 0x0; + case 'secondary': return (mouseEventButtons & 0x2) !== 0x0; + case 'auxiliary': return (mouseEventButtons & 0x4) !== 0x0; + default: return false; } } } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 5a824561..801011df 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -83,7 +83,7 @@ class Display { } onGlossaryMouseDown(e) { - if (Frontend.isMouseButton('primary', e)) { + if (Frontend.isMouseButtonPressed('primary', e)) { this.clickScanPrevent = false; } } @@ -93,7 +93,7 @@ class Display { } onGlossaryMouseUp(e) { - if (!this.clickScanPrevent && Frontend.isMouseButton('primary', e)) { + if (!this.clickScanPrevent && Frontend.isMouseButtonPressed('primary', e)) { this.onTermLookup(e); } } -- cgit v1.2.3 From 3a225c3f916d435e04fb30afa731c30c4309fc7f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 4 Nov 2019 20:43:40 -0500 Subject: Add details field to apiTermsFind --- ext/bg/js/api.js | 4 ++-- ext/bg/js/backend.js | 2 +- ext/bg/js/search.js | 2 +- ext/bg/js/translator.js | 22 +++++++++++----------- ext/fg/js/api.js | 4 ++-- ext/fg/js/frontend.js | 2 +- ext/mixed/js/display.js | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index c50db76f..df73aa2a 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -72,9 +72,9 @@ async function apiOptionsSave(source) { backend.onOptionsUpdated(source); } -async function apiTermsFind(text, optionsContext) { +async function apiTermsFind(text, details, optionsContext) { const options = await apiOptionsGet(optionsContext); - const [definitions, length] = await utilBackend().translator.findTerms(text, options); + const [definitions, length] = await utilBackend().translator.findTerms(text, details, options); definitions.splice(options.general.maxResults); return {length, definitions}; } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 71393467..efad153a 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -179,7 +179,7 @@ Backend.messageHandlers = { optionsGet: ({optionsContext}) => apiOptionsGet(optionsContext), optionsSet: ({changedOptions, optionsContext, source}) => apiOptionsSet(changedOptions, optionsContext, source), kanjiFind: ({text, optionsContext}) => apiKanjiFind(text, optionsContext), - termsFind: ({text, optionsContext}) => apiTermsFind(text, optionsContext), + termsFind: ({text, details, optionsContext}) => apiTermsFind(text, details, optionsContext), definitionAdd: ({definition, mode, context, optionsContext}) => apiDefinitionAdd(definition, mode, context, optionsContext), definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext), noteView: ({noteId}) => apiNoteView(noteId), diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index ad579918..abd40640 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -207,7 +207,7 @@ class DisplaySearch extends Display { this.setIntroVisible(!valid, animate); this.updateSearchButton(); if (valid) { - const {definitions} = await apiTermsFind(query, this.optionsContext); + const {definitions} = await apiTermsFind(query, {}, this.optionsContext); this.setContentTerms(definitions, { focus: false, sentence: null, diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1cdd79db..dac53f93 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -141,23 +141,23 @@ class Translator { return result; } - async findTerms(text, options) { + async findTerms(text, details, options) { switch (options.general.resultOutputMode) { case 'group': - return await this.findTermsGrouped(text, options); + return await this.findTermsGrouped(text, details, options); case 'merge': - return await this.findTermsMerged(text, options); + return await this.findTermsMerged(text, details, options); case 'split': - return await this.findTermsSplit(text, options); + return await this.findTermsSplit(text, details, options); default: return [[], 0]; } } - async findTermsGrouped(text, options) { + async findTermsGrouped(text, details, options) { const dictionaries = dictEnabledSet(options); const titles = Object.keys(dictionaries); - const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details); const definitionsGrouped = dictTermsGroup(definitions, dictionaries); await this.buildTermFrequencies(definitionsGrouped, titles); @@ -171,11 +171,11 @@ class Translator { return [definitionsGrouped, length]; } - async findTermsMerged(text, options) { + async findTermsMerged(text, details, options) { const dictionaries = dictEnabledSet(options); const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches); const titles = Object.keys(dictionaries); - const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const definitionsMerged = []; const mergedByTermIndices = new Set(); @@ -209,17 +209,17 @@ class Translator { return [dictTermsSort(definitionsMerged), length]; } - async findTermsSplit(text, options) { + async findTermsSplit(text, details, options) { const dictionaries = dictEnabledSet(options); const titles = Object.keys(dictionaries); - const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details); await this.buildTermFrequencies(definitions, titles); return [definitions, length]; } - async findTermsInternal(text, dictionaries, alphanumeric) { + async findTermsInternal(text, dictionaries, alphanumeric, details) { if (!alphanumeric && text.length > 0) { const c = text[0]; if (!jpIsKana(c) && !jpIsKanji(c)) { diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index 54818702..945ba076 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -25,8 +25,8 @@ function apiOptionsSet(changedOptions, optionsContext, source) { return utilInvoke('optionsSet', {changedOptions, optionsContext, source}); } -function apiTermsFind(text, optionsContext) { - return utilInvoke('termsFind', {text, optionsContext}); +function apiTermsFind(text, details, optionsContext) { + return utilInvoke('termsFind', {text, details, optionsContext}); } function apiKanjiFind(text, optionsContext) { diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 7c62b51b..6002dfcb 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -413,7 +413,7 @@ class Frontend { const searchText = textSource.text(); if (searchText.length === 0) { return null; } - const {definitions, length} = await apiTermsFind(searchText, this.getOptionsContext()); + const {definitions, length} = await apiTermsFind(searchText, {}, this.getOptionsContext()); if (definitions.length === 0) { return null; } textSource.setEndOffset(length); diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 801011df..8ad3ee1b 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -112,7 +112,7 @@ class Display { try { textSource.setEndOffset(this.options.scanning.length); - ({definitions, length} = await apiTermsFind(textSource.text(), this.getOptionsContext())); + ({definitions, length} = await apiTermsFind(textSource.text(), {}, this.getOptionsContext())); if (definitions.length === 0) { return false; } -- cgit v1.2.3 From f63e8e4be0e7bdb1a2e45e349bf667ea7ca4adab Mon Sep 17 00:00:00 2001 From: siikamiika Date: Tue, 29 Oct 2019 23:49:36 +0200 Subject: add simple query parser --- ext/bg/js/search-query-parser.js | 44 ++++++++++++++++++++++++++++++++++++++++ ext/bg/js/search.js | 24 ++++++++++++++-------- ext/bg/search.html | 3 +++ ext/mixed/css/display.css | 9 ++++++++ ext/mixed/js/display.js | 2 ++ 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 ext/bg/js/search-query-parser.js (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js new file mode 100644 index 00000000..debe53b4 --- /dev/null +++ b/ext/bg/js/search-query-parser.js @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class QueryParser { + constructor(search) { + this.search = search; + + this.queryParser = document.querySelector('#query-parser'); + + // TODO also enable for mouseover scanning + this.queryParser.addEventListener('click', (e) => this.onTermLookup(e)); + } + + onError(error) { + logError(error, false); + } + + async onTermLookup(e) { + const {textSource} = await this.search.onTermLookup(e, {isQueryParser: true}); + if (textSource) { + textSource.select(); + } + } + + setText(text) { + this.queryParser.innerText = text; + } +} diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 56316217..20d0c58c 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -32,6 +32,8 @@ class DisplaySearch extends Display { url: window.location.href }; + this.queryParser = new QueryParser(this); + this.search = document.querySelector('#search'); this.query = document.querySelector('#query'); this.intro = document.querySelector('#intro'); @@ -72,11 +74,11 @@ class DisplaySearch extends Display { const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || ''; if (e.target.checked) { window.wanakana.bind(this.query); - this.query.value = window.wanakana.toKana(query); + this.setQuery(window.wanakana.toKana(query)); apiOptionsSet({general: {enableWanakana: true}}, this.getOptionsContext()); } else { window.wanakana.unbind(this.query); - this.query.value = query; + this.setQuery(query); apiOptionsSet({general: {enableWanakana: false}}, this.getOptionsContext()); } this.onSearchQueryUpdated(this.query.value, false); @@ -86,9 +88,9 @@ class DisplaySearch extends Display { const query = DisplaySearch.getSearchQueryFromLocation(window.location.href); if (query !== null) { if (this.isWanakanaEnabled()) { - this.query.value = window.wanakana.toKana(query); + this.setQuery(window.wanakana.toKana(query)); } else { - this.query.value = query; + this.setQuery(query); } this.onSearchQueryUpdated(this.query.value, false); } @@ -159,6 +161,7 @@ class DisplaySearch extends Display { e.preventDefault(); const query = this.query.value; + this.queryParser.setText(query); const queryString = query.length > 0 ? `?query=${encodeURIComponent(query)}` : ''; window.history.pushState(null, '', `${window.location.pathname}${queryString}`); this.onSearchQueryUpdated(query, true); @@ -168,9 +171,9 @@ class DisplaySearch extends Display { const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || ''; if (this.query !== null) { if (this.isWanakanaEnabled()) { - this.query.value = window.wanakana.toKana(query); + this.setQuery(window.wanakana.toKana(query)); } else { - this.query.value = query; + this.setQuery(query); } } @@ -258,9 +261,9 @@ class DisplaySearch extends Display { } if (curText && (curText !== this.clipboardPrevText) && jpIsJapaneseText(curText)) { if (this.isWanakanaEnabled()) { - this.query.value = window.wanakana.toKana(curText); + this.setQuery(window.wanakana.toKana(curText)); } else { - this.query.value = curText; + this.setQuery(curText); } const queryString = curText.length > 0 ? `?query=${encodeURIComponent(curText)}` : ''; @@ -287,6 +290,11 @@ class DisplaySearch extends Display { return this.optionsContext; } + setQuery(query) { + this.query.value = query; + this.queryParser.setText(query); + } + setIntroVisible(visible, animate) { if (this.introVisible === visible) { return; diff --git a/ext/bg/search.html b/ext/bg/search.html index 54c5fb6c..48e7dbf5 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -47,6 +47,8 @@ +
+
@@ -67,6 +69,7 @@ + diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index 7ee6f5ac..5e5213ff 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -88,6 +88,15 @@ ol, ul { user-select: none; } +#query-parser { + margin-top: 10px; + font-size: 24px; +} + +.highlight { + background-color: lightblue; +} + /* * Entries diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 8ad3ee1b..07a851f5 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -140,6 +140,8 @@ class Display { } this.setContentTerms(definitions, context); + + return {textSource}; } catch (error) { this.onError(error); } -- cgit v1.2.3 From c35a05cd62d43ff435c022a353de55510b020277 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Wed, 30 Oct 2019 03:58:24 +0200 Subject: add kana to text --- ext/bg/js/api.js | 37 +++++++++++++++ ext/bg/js/backend.js | 1 + ext/bg/js/search-query-parser.js | 97 ++++++++++++++++++++++++++++++++++++---- ext/fg/js/api.js | 4 ++ ext/mixed/css/display.css | 4 ++ ext/mixed/js/display.js | 78 +++++++++++++++++++++----------- 6 files changed, 188 insertions(+), 33 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index df73aa2a..064903ca 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -79,6 +79,43 @@ async function apiTermsFind(text, details, optionsContext) { return {length, definitions}; } +async function apiTextParse(text, optionsContext) { + const options = await apiOptionsGet(optionsContext); + const translator = utilBackend().translator; + + const results = []; + while (text) { + let [definitions, length] = await translator.findTerms(text, {}, options); + if (definitions.length > 0) { + definitions = dictTermsSort(definitions); + const {expression, source, reading} = definitions[0]; + + let stemLength = source.length; + while (source[stemLength - 1] !== expression[stemLength - 1]) { + --stemLength; + } + const offset = source.length - stemLength; + + for (const result of jpDistributeFurigana( + source.slice(0, offset === 0 ? source.length : source.length - offset), + reading.slice(0, offset === 0 ? reading.length : source.length + (reading.length - expression.length) - offset) + )) { + results.push(result); + } + + if (stemLength !== source.length) { + results.push({text: source.slice(stemLength)}); + } + + text = text.slice(source.length); + } else { + results.push({text: text[0]}); + text = text.slice(1); + } + } + return results; +} + async function apiKanjiFind(text, optionsContext) { const options = await apiOptionsGet(optionsContext); const definitions = await utilBackend().translator.findKanji(text, options); diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index efad153a..d0e404f2 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -180,6 +180,7 @@ Backend.messageHandlers = { optionsSet: ({changedOptions, optionsContext, source}) => apiOptionsSet(changedOptions, optionsContext, source), kanjiFind: ({text, optionsContext}) => apiKanjiFind(text, optionsContext), termsFind: ({text, details, optionsContext}) => apiTermsFind(text, details, optionsContext), + textParse: ({text, optionsContext}) => apiTextParse(text, optionsContext), definitionAdd: ({definition, mode, context, optionsContext}) => apiDefinitionAdd(definition, mode, context, optionsContext), definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext), noteView: ({noteId}) => apiNoteView(noteId), diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index debe53b4..c3a3900b 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -23,22 +23,103 @@ class QueryParser { this.queryParser = document.querySelector('#query-parser'); - // TODO also enable for mouseover scanning - this.queryParser.addEventListener('click', (e) => this.onTermLookup(e)); + this.queryParser.addEventListener('click', (e) => this.onClick(e)); + this.queryParser.addEventListener('mousemove', (e) => this.onMouseMove(e)); } onError(error) { logError(error, false); } - async onTermLookup(e) { - const {textSource} = await this.search.onTermLookup(e, {isQueryParser: true}); - if (textSource) { - textSource.select(); + onClick(e) { + this.onTermLookup(e, {disableScroll: true, selectText: true}); + } + + async onMouseMove(e) { + if ( + (e.buttons & 0x1) !== 0x0 // Left mouse button + ) { + return; + } + + const scanningOptions = this.search.options.scanning; + const scanningModifier = scanningOptions.modifier; + if (!( + QueryParser.isScanningModifierPressed(scanningModifier, e) || + (scanningOptions.middleMouse && (e.buttons & 0x4) !== 0x0) // Middle mouse button + )) { + return; } + + await this.onTermLookup(e, {disableScroll: true, selectText: true, disableHistory: true}) + } + + onTermLookup(e, params) { + this.search.onTermLookup(e, params); } - setText(text) { - this.queryParser.innerText = text; + async setText(text) { + this.search.setSpinnerVisible(true); + + const results = await apiTextParse(text, this.search.getOptionsContext()); + + const tempContainer = document.createElement('div'); + for (const {text, furigana} of results) { + if (furigana) { + const rubyElement = document.createElement('ruby'); + const furiganaElement = document.createElement('rt'); + furiganaElement.innerText = furigana; + rubyElement.appendChild(document.createTextNode(text)); + rubyElement.appendChild(furiganaElement); + tempContainer.appendChild(rubyElement); + } else { + tempContainer.appendChild(document.createTextNode(text)); + } + } + this.queryParser.innerHTML = ''; + this.queryParser.appendChild(tempContainer); + + this.search.setSpinnerVisible(false); + } + + async parseText(text) { + const results = []; + while (text) { + const {definitions, length} = await apiTermsFind(text, {}, this.search.getOptionsContext()); + if (length) { + results.push(definitions); + text = text.slice(length); + } else { + results.push(text[0]); + text = text.slice(1); + } + } + return results; + } + + popupTimerSet(callback) { + const delay = this.options.scanning.delay; + if (delay > 0) { + this.popupTimer = window.setTimeout(callback, delay); + } else { + Promise.resolve().then(callback); + } + } + + popupTimerClear() { + if (this.popupTimer !== null) { + window.clearTimeout(this.popupTimer); + this.popupTimer = null; + } + } + + static isScanningModifierPressed(scanningModifier, mouseEvent) { + switch (scanningModifier) { + case 'alt': return mouseEvent.altKey; + case 'ctrl': return mouseEvent.ctrlKey; + case 'shift': return mouseEvent.shiftKey; + case 'none': return true; + default: return false; + } } } diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index 945ba076..cc1e0e90 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -29,6 +29,10 @@ function apiTermsFind(text, details, optionsContext) { return utilInvoke('termsFind', {text, details, optionsContext}); } +function apiTextParse(text, optionsContext) { + return utilInvoke('textParse', {text, optionsContext}); +} + function apiKanjiFind(text, optionsContext) { return utilInvoke('kanjiFind', {text, optionsContext}); } diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index 5e5213ff..81109fc6 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -73,6 +73,10 @@ ol, ul { } +html:root[data-yomichan-page=search] body { + min-height: 101vh; /* always show scroll bar to avoid scanning problems */ +} + /* * Search page */ diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 07a851f5..82385bf9 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -98,17 +98,62 @@ class Display { } } - async onTermLookup(e) { + async onTermLookup(e, {disableScroll, selectText, disableHistory}) { + const termLookupResults = await this.termLookup(e); + if (!termLookupResults) { + return false; + } + + try { + const {textSource, definitions} = termLookupResults; + + const scannedElement = e.target; + const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + + if (!disableScroll) { + this.windowScroll.toY(0); + } + let context; + if (disableHistory) { + const {url, source} = this.context || {}; + context = {sentence, url, source, disableScroll}; + } else { + context = { + disableScroll, + source: { + definitions: this.definitions, + index: this.entryIndexFind(scannedElement), + scroll: this.windowScroll.y + } + }; + + if (this.context) { + context.sentence = sentence; + context.url = this.context.url; + context.source.source = this.context.source; + } + } + + this.setContentTerms(definitions, context); + + if (selectText) { + textSource.select(); + } + } catch (error) { + this.onError(error); + } + } + + async termLookup(e) { try { e.preventDefault(); - const clickedElement = e.target; const textSource = docRangeFromPoint(e.clientX, e.clientY, this.options); if (textSource === null) { return false; } - let definitions, length, sentence; + let definitions, length; try { textSource.setEndOffset(this.options.scanning.length); @@ -118,30 +163,11 @@ class Display { } textSource.setEndOffset(length); - - sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); } finally { textSource.cleanup(); } - this.windowScroll.toY(0); - const context = { - source: { - definitions: this.definitions, - index: this.entryIndexFind(clickedElement), - scroll: this.windowScroll.y - } - }; - - if (this.context) { - context.sentence = sentence; - context.url = this.context.url; - context.source.source = this.context.source; - } - - this.setContentTerms(definitions, context); - - return {textSource}; + return {textSource, definitions}; } catch (error) { this.onError(error); } @@ -338,8 +364,10 @@ class Display { const content = await apiTemplateRender('terms.html', params); this.container.innerHTML = content; - const {index, scroll} = context || {}; - this.entryScrollIntoView(index || 0, scroll); + const {index, scroll, disableScroll} = context || {}; + if (!disableScroll) { + this.entryScrollIntoView(index || 0, scroll); + } if (options.audio.enabled && options.audio.autoPlay) { this.autoPlayAudio(); -- cgit v1.2.3 From 408aa73cced09e1d4fd00cfd193d7f3bcb18b689 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Wed, 30 Oct 2019 13:09:11 +0200 Subject: fix default params for term clicking --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 82385bf9..4c698ecf 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -98,7 +98,7 @@ class Display { } } - async onTermLookup(e, {disableScroll, selectText, disableHistory}) { + async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { const termLookupResults = await this.termLookup(e); if (!termLookupResults) { return false; -- cgit v1.2.3 From c7cb1b3d9e5d738e36175b850a9c696a3ab0bf6d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 11:43:58 -0500 Subject: Require context for setContentTerms and setContentKanji --- ext/mixed/js/display.js | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 4c698ecf..651a43c9 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -326,6 +326,7 @@ class Display { } async setContentTerms(definitions, context) { + if (!context) { throw new Error('Context expected'); } if (!this.isInitialized()) { return; } try { @@ -333,7 +334,7 @@ class Display { this.setEventListenersActive(false); - if (!context || context.focus !== false) { + if (context.focus !== false) { window.focus(); } @@ -343,7 +344,7 @@ class Display { const sequence = ++this.sequence; const params = { definitions, - source: context && context.source, + source: context.source, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -352,19 +353,14 @@ class Display { debug: options.general.debugInfo }; - if (context) { - for (const definition of definitions) { - if (context.sentence) { - definition.cloze = Display.clozeBuild(context.sentence, definition.source); - } - - definition.url = context.url; - } + for (const definition of definitions) { + definition.cloze = Display.clozeBuild(context.sentence, definition.source); + definition.url = context.url; } const content = await apiTemplateRender('terms.html', params); this.container.innerHTML = content; - const {index, scroll, disableScroll} = context || {}; + const {index, scroll, disableScroll} = context; if (!disableScroll) { this.entryScrollIntoView(index || 0, scroll); } @@ -382,6 +378,7 @@ class Display { } async setContentKanji(definitions, context) { + if (!context) { throw new Error('Context expected'); } if (!this.isInitialized()) { return; } try { @@ -389,7 +386,7 @@ class Display { this.setEventListenersActive(false); - if (!context || context.focus !== false) { + if (context.focus !== false) { window.focus(); } @@ -399,24 +396,19 @@ class Display { const sequence = ++this.sequence; const params = { definitions, - source: context && context.source, + source: context.source, addable: options.anki.enable, debug: options.general.debugInfo }; - if (context) { - for (const definition of definitions) { - if (context.sentence) { - definition.cloze = Display.clozeBuild(context.sentence); - } - - definition.url = context.url; - } + for (const definition of definitions) { + definition.cloze = Display.clozeBuild(context.sentence); + definition.url = context.url; } const content = await apiTemplateRender('kanji.html', params); this.container.innerHTML = content; - const {index, scroll} = context || {}; + const {index, scroll} = context; this.entryScrollIntoView(index || 0, scroll); this.setEventListenersActive(true); -- cgit v1.2.3 From cb9f9b585a802c7b8dfb5689d326e7482f5ff2db Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 12:29:49 -0500 Subject: Update how source terms are navigated --- ext/mixed/js/display.js | 76 +++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 651a43c9..cbf8efb7 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -58,23 +58,25 @@ class Display { async onKanjiLookup(e) { try { e.preventDefault(); + if (!this.context) { return; } const link = e.target; this.windowScroll.toY(0); const context = { source: { - definitions: this.definitions, - index: this.entryIndexFind(link), - scroll: this.windowScroll.y - } + type: 'terms', + details: { + definitions: this.definitions, + context: Object.assign({}, this.context, { + index: this.entryIndexFind(link), + scroll: this.windowScroll.y + }) + } + }, + sentence: this.context.sentence, + url: this.context.url }; - if (this.context) { - context.sentence = this.context.sentence; - context.url = this.context.url; - context.source.source = this.context.source; - } - const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -99,12 +101,10 @@ class Display { } async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { - const termLookupResults = await this.termLookup(e); - if (!termLookupResults) { - return false; - } - try { + if (!this.context) { return; } + const termLookupResults = await this.termLookup(e); + if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; const scannedElement = e.target; @@ -113,26 +113,22 @@ class Display { if (!disableScroll) { this.windowScroll.toY(0); } - let context; - if (disableHistory) { - const {url, source} = this.context || {}; - context = {sentence, url, source, disableScroll}; - } else { - context = { - disableScroll, - source: { + + const context = { + source: disableHistory ? this.context.source : { + type: 'terms', + details: { definitions: this.definitions, - index: this.entryIndexFind(scannedElement), - scroll: this.windowScroll.y + context: Object.assign({}, this.context, { + index: this.entryIndexFind(scannedElement), + scroll: this.windowScroll.y + }) } - }; - - if (this.context) { - context.sentence = sentence; - context.url = this.context.url; - context.source.source = this.context.source; - } - } + }, + disableScroll, + sentence, + url: this.context.url + }; this.setContentTerms(definitions, context); @@ -501,17 +497,9 @@ class Display { } sourceTermView() { - if (this.context && this.context.source) { - const context = { - url: this.context.source.url, - sentence: this.context.source.sentence, - index: this.context.source.index, - scroll: this.context.source.scroll, - source: this.context.source.source - }; - - this.setContentTerms(this.context.source.definitions, context); - } + if (!this.context || !this.context.source) { return; } + const {type, details} = this.context.source; + this.setContent(type, details); } noteTryAdd(mode) { -- cgit v1.2.3 From befee9ceca1a8a74b0cb70ae5b29f42f2d8f8e26 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:49:55 -0500 Subject: Pass kanji character to clozeBuild --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cbf8efb7..2f10da30 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -398,7 +398,7 @@ class Display { }; for (const definition of definitions) { - definition.cloze = Display.clozeBuild(context.sentence); + definition.cloze = Display.clozeBuild(context.sentence, definition.character); definition.url = context.url; } -- cgit v1.2.3 From afddec66eb749aa0a39c7e7142f929e68697995d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:50:29 -0500 Subject: Update cloze.body to use original sentence text --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2f10da30..21d00bbc 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -640,7 +640,7 @@ class Display { if (source) { result.prefix = sentence.text.substring(0, sentence.offset).trim(); - result.body = source.trim(); + result.body = sentence.text.substring(sentence.offset, sentence.offset + source.length); result.suffix = sentence.text.substring(sentence.offset + source.length).trim(); } -- cgit v1.2.3 From 3a7ef6c560fc6437dc33ad197c136af4498db15c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:53:21 -0500 Subject: Simplify clozeBuild --- ext/mixed/js/display.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 21d00bbc..f231fab5 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -633,18 +633,13 @@ class Display { return index >= 0 && index < entries.length ? entries[index] : null; } - static clozeBuild(sentence, source) { - const result = { - sentence: sentence.text.trim() + static clozeBuild({text, offset}, source) { + return { + sentence: text.trim(), + prefix: text.substring(0, offset).trim(), + body: text.substring(offset, offset + source.length), + suffix: text.substring(offset + source.length).trim() }; - - if (source) { - result.prefix = sentence.text.substring(0, sentence.offset).trim(); - result.body = sentence.text.substring(sentence.offset, sentence.offset + source.length); - result.suffix = sentence.text.substring(sentence.offset + source.length).trim(); - } - - return result; } entryIndexFind(element) { -- cgit v1.2.3 From 4110a848f5107c697e09c014d3488360fc8219ef Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 18:52:05 -0500 Subject: Move additional utility functions to DOM --- ext/bg/js/search-query-parser.js | 8 ++++---- ext/fg/js/frontend.js | 35 ++--------------------------------- ext/mixed/js/display.js | 4 ++-- ext/mixed/js/dom.js | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 39 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 42e53989..1a43347c 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -38,7 +38,7 @@ class QueryParser { } onMouseDown(e) { - if (Frontend.isMouseButton('primary', e)) { + if (DOM.isMouseButtonPressed(e, 'primary')) { this.clickScanPrevent = false; } } @@ -47,7 +47,7 @@ class QueryParser { if ( this.search.options.scanning.clickGlossary && !this.clickScanPrevent && - Frontend.isMouseButton('primary', e) + DOM.isMouseButtonPressed(e, 'primary') ) { const selectText = this.search.options.scanning.selectText; this.onTermLookup(e, {disableScroll: true, selectText}); @@ -55,7 +55,7 @@ class QueryParser { } onMouseMove(e) { - if (this.pendingLookup || Frontend.isMouseButton('primary', e)) { + if (this.pendingLookup || DOM.isMouseButtonDown(e, 'primary')) { return; } @@ -63,7 +63,7 @@ class QueryParser { const scanningModifier = scanningOptions.modifier; if (!( Frontend.isScanningModifierPressed(scanningModifier, e) || - (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e)) + (scanningOptions.middleMouse && DOM.isMouseButtonDown(e, 'auxiliary')) )) { return; } diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 81c159db..ee653d78 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -80,7 +80,7 @@ class Frontend { onMouseMove(e) { this.popupTimerClear(); - if (this.pendingLookup || Frontend.isMouseButtonDown('primary', e)) { + if (this.pendingLookup || DOM.isMouseButtonDown(e, 'primary')) { return; } @@ -88,7 +88,7 @@ class Frontend { const scanningModifier = scanningOptions.modifier; if (!( Frontend.isScanningModifierPressed(scanningModifier, e) || - (scanningOptions.middleMouse && Frontend.isMouseButtonDown('auxiliary', e)) + (scanningOptions.middleMouse && DOM.isMouseButtonDown(e, 'auxiliary')) )) { return; } @@ -487,37 +487,6 @@ class Frontend { default: return false; } } - - static isMouseButton(button, mouseEvent) { - switch (mouseEvent.type) { - case 'mouseup': - case 'mousedown': - case 'click': - return Frontend.isMouseButtonPressed(button, mouseEvent); - default: - return Frontend.isMouseButtonDown(button, mouseEvent); - } - } - - static isMouseButtonPressed(button, mouseEvent) { - const mouseEventButton = mouseEvent.button; - switch (button) { - case 'primary': return mouseEventButton === 0; - case 'secondary': return mouseEventButton === 2; - case 'auxiliary': return mouseEventButton === 1; - default: return false; - } - } - - static isMouseButtonDown(button, mouseEvent) { - const mouseEventButtons = mouseEvent.buttons; - switch (button) { - case 'primary': return (mouseEventButtons & 0x1) !== 0x0; - case 'secondary': return (mouseEventButtons & 0x2) !== 0x0; - case 'auxiliary': return (mouseEventButtons & 0x4) !== 0x0; - default: return false; - } - } } Frontend.windowMessageHandlers = { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cbf8efb7..854418f4 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -85,7 +85,7 @@ class Display { } onGlossaryMouseDown(e) { - if (Frontend.isMouseButtonPressed('primary', e)) { + if (DOM.isMouseButtonPressed(e, 'primary')) { this.clickScanPrevent = false; } } @@ -95,7 +95,7 @@ class Display { } onGlossaryMouseUp(e) { - if (!this.clickScanPrevent && Frontend.isMouseButtonPressed('primary', e)) { + if (!this.clickScanPrevent && DOM.isMouseButtonPressed(e, 'primary')) { this.onTermLookup(e); } } diff --git a/ext/mixed/js/dom.js b/ext/mixed/js/dom.js index 4525dace..4e4d49e3 100644 --- a/ext/mixed/js/dom.js +++ b/ext/mixed/js/dom.js @@ -43,4 +43,24 @@ class DOM { } return false; } + + static isMouseButtonPressed(mouseEvent, button) { + const mouseEventButton = mouseEvent.button; + switch (button) { + case 'primary': return mouseEventButton === 0; + case 'secondary': return mouseEventButton === 2; + case 'auxiliary': return mouseEventButton === 1; + default: return false; + } + } + + static isMouseButtonDown(mouseEvent, button) { + const mouseEventButtons = mouseEvent.buttons; + switch (button) { + case 'primary': return (mouseEventButtons & 0x1) !== 0x0; + case 'secondary': return (mouseEventButtons & 0x2) !== 0x0; + case 'auxiliary': return (mouseEventButtons & 0x4) !== 0x0; + default: return false; + } + } } -- cgit v1.2.3 From 0aed27b66d9c496e4cd57ef95d982c4e634a8666 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 25 Nov 2019 14:19:18 -0500 Subject: Replace hasOwnProperty with simplified hasOwn function --- ext/bg/js/api.js | 4 ++-- ext/bg/js/audio.js | 6 +++--- ext/bg/js/backend.js | 2 +- ext/bg/js/conditions-ui.js | 20 ++++++++++---------- ext/bg/js/conditions.js | 30 +++++++++++++++--------------- ext/bg/js/database.js | 2 +- ext/bg/js/dictionary.js | 4 ++-- ext/bg/js/mecab.js | 2 +- ext/bg/js/options.js | 2 +- ext/bg/js/search.js | 2 +- ext/bg/js/settings-dictionaries.js | 4 ++-- ext/bg/js/settings-popup-preview.js | 2 +- ext/bg/js/translator.js | 12 ++++++------ ext/fg/js/float.js | 4 ++-- ext/fg/js/frontend-api-receiver.js | 2 +- ext/fg/js/frontend-api-sender.js | 6 +++--- ext/fg/js/frontend.js | 4 ++-- ext/fg/js/popup-proxy-host.js | 4 ++-- ext/mixed/js/audio.js | 2 +- ext/mixed/js/core.js | 4 ++++ ext/mixed/js/display.js | 4 ++-- 21 files changed, 63 insertions(+), 59 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 766fb0ed..12257e92 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -45,7 +45,7 @@ async function apiOptionsSet(changedOptions, optionsContext, source) { function modifyOption(path, value, options) { let pivot = options; for (const key of path.slice(0, -1)) { - if (!pivot.hasOwnProperty(key)) { + if (!hasOwn(pivot, key)) { return false; } pivot = pivot[key]; @@ -236,7 +236,7 @@ async function apiTemplateRender(template, data, dynamic) { async function apiCommandExec(command, params) { const handlers = apiCommandExec.handlers; - if (handlers.hasOwnProperty(command)) { + if (hasOwn(handlers, command)) { const handler = handlers[command]; handler(params); } diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index cd42a158..9bbbf902 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -107,12 +107,12 @@ const audioUrlBuilders = { 'custom': async (definition, optionsContext) => { const options = await apiOptionsGet(optionsContext); const customSourceUrl = options.audio.customSourceUrl; - return customSourceUrl.replace(/\{([^\}]*)\}/g, (m0, m1) => (definition.hasOwnProperty(m1) ? `${definition[m1]}` : m0)); + return customSourceUrl.replace(/\{([^\}]*)\}/g, (m0, m1) => (hasOwn(definition, m1) ? `${definition[m1]}` : m0)); } }; async function audioGetUrl(definition, mode, optionsContext, download) { - if (audioUrlBuilders.hasOwnProperty(mode)) { + if (hasOwn(audioUrlBuilders, mode)) { const handler = audioUrlBuilders[mode]; try { return await handler(definition, optionsContext, download); @@ -171,7 +171,7 @@ async function audioInject(definition, fields, sources, optionsContext) { try { let audioSourceDefinition = definition; - if (definition.hasOwnProperty('expressions')) { + if (hasOwn(definition, 'expressions')) { audioSourceDefinition = definition.expressions[0]; } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 45db9660..4190116b 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -73,7 +73,7 @@ class Backend { onMessage({action, params}, sender, callback) { const handlers = Backend.messageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; const promise = handler(params, sender); promise.then( diff --git a/ext/bg/js/conditions-ui.js b/ext/bg/js/conditions-ui.js index 43c6dc08..cc9db087 100644 --- a/ext/bg/js/conditions-ui.js +++ b/ext/bg/js/conditions-ui.js @@ -84,7 +84,7 @@ ConditionsUI.Container = class Container { createDefaultCondition(type) { let operator = ''; let value = ''; - if (this.conditionDescriptors.hasOwnProperty(type)) { + if (hasOwn(this.conditionDescriptors, type)) { const conditionDescriptor = this.conditionDescriptors[type]; operator = conditionDescriptor.defaultOperator; ({value} = this.getOperatorDefaultValue(type, operator)); @@ -96,15 +96,15 @@ ConditionsUI.Container = class Container { } getOperatorDefaultValue(type, operator) { - if (this.conditionDescriptors.hasOwnProperty(type)) { + if (hasOwn(this.conditionDescriptors, type)) { const conditionDescriptor = this.conditionDescriptors[type]; - if (conditionDescriptor.operators.hasOwnProperty(operator)) { + if (hasOwn(conditionDescriptor.operators, operator)) { const operatorDescriptor = conditionDescriptor.operators[operator]; - if (operatorDescriptor.hasOwnProperty('defaultValue')) { + if (hasOwn(operatorDescriptor, 'defaultValue')) { return {value: operatorDescriptor.defaultValue, fromOperator: true}; } } - if (conditionDescriptor.hasOwnProperty('defaultValue')) { + if (hasOwn(conditionDescriptor, 'defaultValue')) { return {value: conditionDescriptor.defaultValue, fromOperator: false}; } } @@ -219,7 +219,7 @@ ConditionsUI.Condition = class Condition { optionGroup.empty(); const type = this.condition.type; - if (conditionDescriptors.hasOwnProperty(type)) { + if (hasOwn(conditionDescriptors, type)) { const conditionDescriptor = conditionDescriptors[type]; const operators = conditionDescriptor.operators; for (const operatorName of Object.keys(operators)) { @@ -240,23 +240,23 @@ ConditionsUI.Condition = class Condition { }; const objects = []; - if (conditionDescriptors.hasOwnProperty(type)) { + if (hasOwn(conditionDescriptors, type)) { const conditionDescriptor = conditionDescriptors[type]; objects.push(conditionDescriptor); - if (conditionDescriptor.operators.hasOwnProperty(operator)) { + if (hasOwn(conditionDescriptor.operators, operator)) { const operatorDescriptor = conditionDescriptor.operators[operator]; objects.push(operatorDescriptor); } } for (const object of objects) { - if (object.hasOwnProperty('placeholder')) { + if (hasOwn(object, 'placeholder')) { props.placeholder = object.placeholder; } if (object.type === 'number') { props.type = 'number'; for (const prop of ['step', 'min', 'max']) { - if (object.hasOwnProperty(prop)) { + if (hasOwn(object, prop)) { props[prop] = object[prop]; } } diff --git a/ext/bg/js/conditions.js b/ext/bg/js/conditions.js index ed4b14f5..c0f0f301 100644 --- a/ext/bg/js/conditions.js +++ b/ext/bg/js/conditions.js @@ -18,14 +18,14 @@ function conditionsValidateOptionValue(object, value) { - if (object.hasOwnProperty('validate') && !object.validate(value)) { + if (hasOwn(object, 'validate') && !object.validate(value)) { throw new Error('Invalid value for condition'); } - if (object.hasOwnProperty('transform')) { + if (hasOwn(object, 'transform')) { value = object.transform(value); - if (object.hasOwnProperty('validateTransformed') && !object.validateTransformed(value)) { + if (hasOwn(object, 'validateTransformed') && !object.validateTransformed(value)) { throw new Error('Invalid value for condition'); } } @@ -34,12 +34,12 @@ function conditionsValidateOptionValue(object, value) { } function conditionsNormalizeOptionValue(descriptors, type, operator, optionValue) { - if (!descriptors.hasOwnProperty(type)) { + if (!hasOwn(descriptors, type)) { throw new Error('Invalid type'); } const conditionDescriptor = descriptors[type]; - if (!conditionDescriptor.operators.hasOwnProperty(operator)) { + if (!hasOwn(conditionDescriptor.operators, operator)) { throw new Error('Invalid operator'); } @@ -48,28 +48,28 @@ function conditionsNormalizeOptionValue(descriptors, type, operator, optionValue let transformedValue = conditionsValidateOptionValue(conditionDescriptor, optionValue); transformedValue = conditionsValidateOptionValue(operatorDescriptor, transformedValue); - if (operatorDescriptor.hasOwnProperty('transformReverse')) { + if (hasOwn(operatorDescriptor, 'transformReverse')) { transformedValue = operatorDescriptor.transformReverse(transformedValue); } return transformedValue; } function conditionsTestValueThrowing(descriptors, type, operator, optionValue, value) { - if (!descriptors.hasOwnProperty(type)) { + if (!hasOwn(descriptors, type)) { throw new Error('Invalid type'); } const conditionDescriptor = descriptors[type]; - if (!conditionDescriptor.operators.hasOwnProperty(operator)) { + if (!hasOwn(conditionDescriptor.operators, operator)) { throw new Error('Invalid operator'); } const operatorDescriptor = conditionDescriptor.operators[operator]; - if (operatorDescriptor.hasOwnProperty('transform')) { - if (operatorDescriptor.hasOwnProperty('transformCache')) { + if (hasOwn(operatorDescriptor, 'transform')) { + if (hasOwn(operatorDescriptor, 'transformCache')) { const key = `${optionValue}`; const transformCache = operatorDescriptor.transformCache; - if (transformCache.hasOwnProperty(key)) { + if (hasOwn(transformCache, key)) { optionValue = transformCache[key]; } else { optionValue = operatorDescriptor.transform(optionValue); @@ -93,23 +93,23 @@ function conditionsTestValue(descriptors, type, operator, optionValue, value) { function conditionsClearCaches(descriptors) { for (const type in descriptors) { - if (!descriptors.hasOwnProperty(type)) { + if (!hasOwn(descriptors, type)) { continue; } const conditionDescriptor = descriptors[type]; - if (conditionDescriptor.hasOwnProperty('transformCache')) { + if (hasOwn(conditionDescriptor, 'transformCache')) { conditionDescriptor.transformCache = {}; } const operatorDescriptors = conditionDescriptor.operators; for (const operator in operatorDescriptors) { - if (!operatorDescriptors.hasOwnProperty(operator)) { + if (!hasOwn(operatorDescriptors, operator)) { continue; } const operatorDescriptor = operatorDescriptors[operator]; - if (operatorDescriptor.hasOwnProperty('transformCache')) { + if (hasOwn(operatorDescriptor, 'transformCache')) { operatorDescriptor.transformCache = {}; } } diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 9b560f78..c53c9f77 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -137,7 +137,7 @@ class Database { const visited = {}; const results = []; const processRow = (row, index) => { - if (titles.includes(row.dictionary) && !visited.hasOwnProperty(row.id)) { + if (titles.includes(row.dictionary) && !hasOwn(visited, row.id)) { visited[row.id] = true; results.push(Database.createTerm(row, index)); } diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 9aa0af9c..affce9e9 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -81,7 +81,7 @@ function dictTermsUndupe(definitions) { const definitionGroups = {}; for (const definition of definitions) { const definitionExisting = definitionGroups[definition.id]; - if (!definitionGroups.hasOwnProperty(definition.id) || definition.expression.length > definitionExisting.expression.length) { + if (!hasOwn(definitionGroups, definition.id) || definition.expression.length > definitionExisting.expression.length) { definitionGroups[definition.id] = definition; } } @@ -131,7 +131,7 @@ function dictTermsGroup(definitions, dictionaries) { } const keyString = key.toString(); - if (groups.hasOwnProperty(keyString)) { + if (hasOwn(groups, keyString)) { groups[keyString].push(definition); } else { groups[keyString] = [definition]; diff --git a/ext/bg/js/mecab.js b/ext/bg/js/mecab.js index 246f8bba..297432e2 100644 --- a/ext/bg/js/mecab.js +++ b/ext/bg/js/mecab.js @@ -60,7 +60,7 @@ class Mecab { } onNativeMessage({sequence, data}) { - if (this.listeners.hasOwnProperty(sequence)) { + if (hasOwn(this.listeners, sequence)) { const {callback, timer} = this.listeners[sequence]; clearTimeout(timer); callback(data); diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 63d88789..358a6b45 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -336,7 +336,7 @@ function profileOptionsSetDefaults(options) { const combine = (target, source) => { for (const key in source) { - if (!target.hasOwnProperty(key)) { + if (!hasOwn(target, key)) { target[key] = source[key]; } } diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 0922d938..16cbfbbd 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -234,7 +234,7 @@ class DisplaySearch extends Display { onRuntimeMessage({action, params}, sender, callback) { const handlers = DisplaySearch.runtimeMessageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; const result = handler(this, params); callback(result); diff --git a/ext/bg/js/settings-dictionaries.js b/ext/bg/js/settings-dictionaries.js index ebd380ac..177379b0 100644 --- a/ext/bg/js/settings-dictionaries.js +++ b/ext/bg/js/settings-dictionaries.js @@ -81,7 +81,7 @@ class SettingsDictionaryListUI { let changed = false; let optionsDictionary; const optionsDictionaries = this.optionsDictionaries; - if (optionsDictionaries.hasOwnProperty(title)) { + if (hasOwn(optionsDictionaries, title)) { optionsDictionary = optionsDictionaries[title]; } else { optionsDictionary = SettingsDictionaryListUI.createDictionaryOptions(); @@ -466,7 +466,7 @@ function dictionaryErrorsShow(errors) { for (let e of errors) { console.error(e); e = dictionaryErrorToString(e); - uniqueErrors[e] = uniqueErrors.hasOwnProperty(e) ? uniqueErrors[e] + 1 : 1; + uniqueErrors[e] = hasOwn(uniqueErrors, e) ? uniqueErrors[e] + 1 : 1; } for (const e in uniqueErrors) { diff --git a/ext/bg/js/settings-popup-preview.js b/ext/bg/js/settings-popup-preview.js index 7d641c46..49409968 100644 --- a/ext/bg/js/settings-popup-preview.js +++ b/ext/bg/js/settings-popup-preview.js @@ -106,7 +106,7 @@ class SettingsPopupPreview { onMessage(e) { const {action, params} = e.data; const handlers = SettingsPopupPreview.messageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; handler(this, params); } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index e27cbdff..0a0ce663 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -297,7 +297,7 @@ class Translator { for (const deinflection of deinflections) { const term = deinflection.term; let deinflectionArray; - if (uniqueDeinflectionsMap.hasOwnProperty(term)) { + if (hasOwn(uniqueDeinflectionsMap, term)) { deinflectionArray = uniqueDeinflectionsMap[term]; } else { deinflectionArray = []; @@ -355,7 +355,7 @@ class Translator { const kanjiUnique = {}; const kanjiList = []; for (const c of text) { - if (!kanjiUnique.hasOwnProperty(c)) { + if (!hasOwn(kanjiUnique, c)) { kanjiList.push(c); kanjiUnique[c] = true; } @@ -417,7 +417,7 @@ class Translator { const expression = term.expression; term.frequencies = []; - if (termsUniqueMap.hasOwnProperty(expression)) { + if (hasOwn(termsUniqueMap, expression)) { termsUniqueMap[expression].push(term); } else { const termList = [term]; @@ -464,7 +464,7 @@ class Translator { const category = meta.category; const group = ( - stats.hasOwnProperty(category) ? + hasOwn(stats, category) ? stats[category] : (stats[category] = []) ); @@ -484,7 +484,7 @@ class Translator { async getTagMetaList(names, title) { const tagMetaList = []; const cache = ( - this.tagCache.hasOwnProperty(title) ? + hasOwn(this.tagCache, title) ? this.tagCache[title] : (this.tagCache[title] = {}) ); @@ -492,7 +492,7 @@ class Translator { for (const name of names) { const base = Translator.getNameBase(name); - if (cache.hasOwnProperty(base)) { + if (hasOwn(cache, base)) { tagMetaList.push(cache[base]); } else { const tagMeta = await this.database.findTagForTitle(base, title); diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 089c9422..ae54be00 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -49,7 +49,7 @@ class DisplayFloat extends Display { onMessage(e) { const {action, params} = e.data; const handlers = DisplayFloat.messageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; handler(this, params); } @@ -58,7 +58,7 @@ class DisplayFloat extends Display { onKeyDown(e) { const key = Display.getKeyFromEvent(e); const handlers = DisplayFloat.onKeyDownHandlers; - if (handlers.hasOwnProperty(key)) { + if (hasOwn(handlers, key)) { const handler = handlers[key]; if (handler(this, e)) { e.preventDefault(); diff --git a/ext/fg/js/frontend-api-receiver.js b/ext/fg/js/frontend-api-receiver.js index fbfb3ab0..bde14646 100644 --- a/ext/fg/js/frontend-api-receiver.js +++ b/ext/fg/js/frontend-api-receiver.js @@ -34,7 +34,7 @@ class FrontendApiReceiver { onMessage(port, {id, action, params, target, senderId}) { if ( target !== this.source || - !this.handlers.hasOwnProperty(action) + !hasOwn(this.handlers, action) ) { return; } diff --git a/ext/fg/js/frontend-api-sender.js b/ext/fg/js/frontend-api-sender.js index c6eeaeb2..af998a8f 100644 --- a/ext/fg/js/frontend-api-sender.js +++ b/ext/fg/js/frontend-api-sender.js @@ -78,7 +78,7 @@ class FrontendApiSender { } onAck(id) { - if (!this.callbacks.hasOwnProperty(id)) { + if (!hasOwn(this.callbacks, id)) { console.warn(`ID ${id} not found for ack`); return; } @@ -95,7 +95,7 @@ class FrontendApiSender { } onResult(id, data) { - if (!this.callbacks.hasOwnProperty(id)) { + if (!hasOwn(this.callbacks, id)) { console.warn(`ID ${id} not found`); return; } @@ -118,7 +118,7 @@ class FrontendApiSender { } onError(id, reason) { - if (!this.callbacks.hasOwnProperty(id)) { return; } + if (!hasOwn(this.callbacks, id)) { return; } const info = this.callbacks[id]; delete this.callbacks[id]; info.timer = null; diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index ee653d78..16302e82 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -237,7 +237,7 @@ class Frontend { onWindowMessage(e) { const action = e.data; const handlers = Frontend.windowMessageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; handler(this); } @@ -245,7 +245,7 @@ class Frontend { onRuntimeMessage({action, params}, sender, callback) { const handlers = Frontend.runtimeMessageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; const result = handler(this, params); callback(result); diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index d8dec4df..b2f18b97 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -50,7 +50,7 @@ class PopupProxyHost { } createPopup(parentId, depth) { - const parent = (typeof parentId === 'string' && this.popups.hasOwnProperty(parentId) ? this.popups[parentId] : null); + const parent = (typeof parentId === 'string' && hasOwn(this.popups, parentId) ? this.popups[parentId] : null); const id = `${this.nextId}`; if (parent !== null) { depth = parent.depth + 1; @@ -70,7 +70,7 @@ class PopupProxyHost { } getPopup(id) { - if (!this.popups.hasOwnProperty(id)) { + if (!hasOwn(this.popups, id)) { throw new Error('Invalid popup ID'); } diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js index 4e9d04fa..7d5ffedd 100644 --- a/ext/mixed/js/audio.js +++ b/ext/mixed/js/audio.js @@ -113,7 +113,7 @@ function audioGetFromUrl(url, willDownload) { async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) { const key = `${expression.expression}:${expression.reading}`; - if (cache !== null && cache.hasOwnProperty(expression)) { + if (cache !== null && hasOwn(cache, expression)) { return cache[key]; } diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js index 8a8a2368..d82b9b4b 100644 --- a/ext/mixed/js/core.js +++ b/ext/mixed/js/core.js @@ -94,6 +94,10 @@ function isObject(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); } +function hasOwn(object, property) { + return Object.prototype.hasOwnProperty.call(object, property); +} + // toIterable is required on Edge for cross-window origin objects. function toIterable(value) { if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 854418f4..ce43b22c 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -194,7 +194,7 @@ class Display { onKeyDown(e) { const key = Display.getKeyFromEvent(e); const handlers = Display.onKeyDownHandlers; - if (handlers.hasOwnProperty(key)) { + if (hasOwn(handlers, key)) { const handler = handlers[key]; if (handler(this, e)) { e.preventDefault(); @@ -216,7 +216,7 @@ class Display { onRuntimeMessage({action, params}, sender, callback) { const handlers = Display.runtimeMessageHandlers; - if (handlers.hasOwnProperty(action)) { + if (hasOwn(handlers, action)) { const handler = handlers[action]; const result = handler(this, params); callback(result); -- cgit v1.2.3 From 943350a1f66b3576e98c58539cbff277b0069977 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 25 Nov 2019 14:21:19 -0500 Subject: Use single quotes --- ext/bg/js/search.js | 2 +- ext/fg/js/popup.js | 2 +- ext/fg/js/source.js | 4 ++-- ext/mixed/js/display.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 16cbfbbd..ae76c23b 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -324,7 +324,7 @@ class DisplaySearch extends Display { this.intro.style.transition = ''; this.intro.style.height = ''; const size = this.intro.getBoundingClientRect(); - this.intro.style.height = `0px`; + this.intro.style.height = '0px'; this.intro.style.transition = `height ${duration}s ease-in-out 0s`; window.getComputedStyle(this.intro).getPropertyValue('height'); // Commits height so next line can start animation this.intro.style.height = `${size.height}px`; diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index ac96f9e8..df784029 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -401,7 +401,7 @@ class Popup { if (Popup.outerStylesheet === null) { if (!css) { return; } Popup.outerStylesheet = document.createElement('style'); - Popup.outerStylesheet.id = "yomichan-popup-outer-stylesheet"; + Popup.outerStylesheet.id = 'yomichan-popup-outer-stylesheet'; } const outerStylesheet = Popup.outerStylesheet; diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 5be521fa..886093d7 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -99,9 +99,9 @@ class TextSourceRange { static getRubyElement(node) { node = TextSourceRange.getParentElement(node); - if (node !== null && node.nodeName.toUpperCase() === "RT") { + if (node !== null && node.nodeName.toUpperCase() === 'RT') { node = node.parentNode; - return (node !== null && node.nodeName.toUpperCase() === "RUBY") ? node : null; + return (node !== null && node.nodeName.toUpperCase() === 'RUBY') ? node : null; } return null; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index ce43b22c..b454bf59 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -574,7 +574,7 @@ class Display { if (button !== null) { let titleDefault = button.dataset.titleDefault; if (!titleDefault) { - titleDefault = button.title || ""; + titleDefault = button.title || ''; button.dataset.titleDefault = titleDefault; } button.title = `${titleDefault}\n${info}`; -- cgit v1.2.3 From acb70f126cd87234b442fd599061f1b7539c846b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 25 Nov 2019 14:35:53 -0500 Subject: Update unused arguments --- ext/bg/js/anki.js | 10 +++++----- ext/bg/js/backend.js | 2 +- ext/bg/js/search.js | 4 ++-- ext/fg/js/api.js | 2 +- ext/fg/js/frontend.js | 4 ++-- ext/fg/js/source.js | 2 +- ext/mixed/js/display.js | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 9f851f13..ac45784b 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -108,11 +108,11 @@ class AnkiConnect { */ class AnkiNull { - async addNote(note) { + async addNote() { return null; } - async canAddNotes(notes) { + async canAddNotes() { return []; } @@ -124,15 +124,15 @@ class AnkiNull { return []; } - async getModelFieldNames(modelName) { + async getModelFieldNames() { return []; } - async guiBrowse(query) { + async guiBrowse() { return []; } - async findNoteIds(notes) { + async findNoteIds() { return []; } } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 4190116b..73df7cf5 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -177,7 +177,7 @@ class Backend { } } - checkLastError(e) { + checkLastError() { // NOP } } diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index e5cdf272..a98d7a9a 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -167,7 +167,7 @@ class DisplaySearch extends Display { this.onSearchQueryUpdated(query, true); } - onPopState(e) { + onPopState() { const query = DisplaySearch.getSearchQueryFromLocation(window.location.href) || ''; if (this.query !== null) { if (this.isWanakanaEnabled()) { @@ -245,7 +245,7 @@ class DisplaySearch extends Display { initClipboardMonitor() { // ignore copy from search page - window.addEventListener('copy', (e) => { + window.addEventListener('copy', () => { this.clipboardPrevText = document.getSelection().toString().trim(); }); } diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index f881b23d..0e100b59 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -113,6 +113,6 @@ function _apiInvoke(action, params={}) { }); } -function _apiCheckLastError(e) { +function _apiCheckLastError() { // NOP } diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 8297f54d..bcdfd152 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -122,7 +122,7 @@ class Frontend { } } - onMouseOut(e) { + onMouseOut() { this.popupTimerClear(); } @@ -135,7 +135,7 @@ class Frontend { } } - onAuxClick(e) { + onAuxClick() { this.preventNextContextMenu = false; } diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index e6b991c4..a84feed4 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -375,7 +375,7 @@ class TextSourceElement { return this.content.length; } - setStartOffset(length) { + setStartOffset() { return 0; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index b454bf59..2396805a 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -42,7 +42,7 @@ class Display { this.setInteractive(true); } - onError(error) { + onError(_error) { throw new Error('Override me'); } @@ -90,7 +90,7 @@ class Display { } } - onGlossaryMouseMove(e) { + onGlossaryMouseMove() { this.clickScanPrevent = true; } -- cgit v1.2.3 From e37ffb6cf5796fc45787046830d84b9d316c0186 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 12:38:25 +0200 Subject: fix scroll issues in Display.entryScrollIntoView - Save scroll context before scrolling to top - Explicit null check for scroll param to handle scrolling to y=0 correctly --- ext/mixed/js/display.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2396805a..27100fd2 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -61,7 +61,6 @@ class Display { if (!this.context) { return; } const link = e.target; - this.windowScroll.toY(0); const context = { source: { type: 'terms', @@ -77,6 +76,8 @@ class Display { url: this.context.url }; + this.windowScroll.toY(0); + const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -110,10 +111,6 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); - if (!disableScroll) { - this.windowScroll.toY(0); - } - const context = { source: disableHistory ? this.context.source : { type: 'terms', @@ -132,6 +129,10 @@ class Display { this.setContentTerms(definitions, context); + if (!disableScroll) { + this.windowScroll.toY(0); + } + if (selectText) { textSource.select(); } @@ -481,7 +482,7 @@ class Display { this.windowScroll.stop(); let target; - if (scroll) { + if (scroll !== null) { target = scroll; } else { target = index === 0 || entry === null ? 0 : Display.getElementTop(entry); -- cgit v1.2.3 From 4e7d08ff2c184a361622a6efaf00e21af51428a9 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 13:22:47 +0200 Subject: set current entry even when disableScroll is true --- ext/mixed/js/display.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 27100fd2..ed3d9adc 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -360,6 +360,8 @@ class Display { const {index, scroll, disableScroll} = context; if (!disableScroll) { this.entryScrollIntoView(index || 0, scroll); + } else { + this.entrySetCurrent(index || 0); } if (options.audio.enabled && options.audio.autoPlay) { @@ -465,7 +467,7 @@ class Display { } } - entryScrollIntoView(index, scroll, smooth) { + entrySetCurrent(index) { index = Math.min(index, this.definitions.length - 1); index = Math.max(index, 0); @@ -479,9 +481,16 @@ class Display { entry.classList.add('entry-current'); } + this.index = index; + + return entry; + } + + entryScrollIntoView(index, scroll, smooth) { this.windowScroll.stop(); - let target; + const entry = this.entrySetCurrent(index); + let target; if (scroll !== null) { target = scroll; } else { @@ -493,8 +502,6 @@ class Display { } else { this.windowScroll.toY(target); } - - this.index = index; } sourceTermView() { -- cgit v1.2.3 From beea89a421736ec157e196ffca6b3720a811635d Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 15:20:18 +0200 Subject: store popped context history in Display --- ext/bg/js/templates.js | 178 +++++++++++++++++++++++++----------------------- ext/mixed/js/display.js | 54 ++++++++++++++- tmpl/kanji.html | 5 +- tmpl/terms.html | 5 +- 4 files changed, 151 insertions(+), 91 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 6e377957..1f551c3f 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -34,18 +34,19 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia return "
\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.history : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n
\n\n
" + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + "
\n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
GlossaryReadingsStatistics
\n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(24, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(23, data, 0),"inverse":container.program(26, data, 0),"data":data})) != null ? stack1 : "") + " \n " - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n " - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.misc : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
Classifications
" @@ -55,19 +56,21 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + "
Dictionary Indices
" + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
\n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(33, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; },"11":function(container,depth0,helpers,partials,data) { return " \n \n"; },"13":function(container,depth0,helpers,partials,data) { return " \n"; },"15":function(container,depth0,helpers,partials,data) { + return " \n"; +},"17":function(container,depth0,helpers,partials,data) { var stack1; return "
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; -},"16":function(container,depth0,helpers,partials,data) { +},"18":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " @@ -75,13 +78,13 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ":" + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + "\n"; -},"18":function(container,depth0,helpers,partials,data) { +},"20":function(container,depth0,helpers,partials,data) { var stack1; return "
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(21, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; -},"19":function(container,depth0,helpers,partials,data) { +},"21":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; -},"21":function(container,depth0,helpers,partials,data) { +},"23":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; -},"22":function(container,depth0,helpers,partials,data) { +},"24":function(container,depth0,helpers,partials,data) { return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) + "
  • "; -},"24":function(container,depth0,helpers,partials,data) { +},"26":function(container,depth0,helpers,partials,data) { var stack1; return " " + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; -},"26":function(container,depth0,helpers,partials,data) { +},"28":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"27":function(container,depth0,helpers,partials,data) { +},"29":function(container,depth0,helpers,partials,data) { return "
    " + container.escapeExpression(container.lambda(depth0, depth0)) + "
    "; -},"29":function(container,depth0,helpers,partials,data) { +},"31":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"31":function(container,depth0,helpers,partials,data) { +},"33":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(32, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"32":function(container,depth0,helpers,partials,data) { +},"34":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"36":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"37":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(38, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"36":function(container,depth0,helpers,partials,data) { - return "
    "; + + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"history":(depths[1] != null ? depths[1].history : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"38":function(container,depth0,helpers,partials,data) { + return "
    "; +},"40":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.program(40, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; @@ -307,16 +310,17 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(25, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.merged : depth0),{"name":"unless","hash":{},"fn":container.program(27, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.history : depth0),{"name":"if","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.merged : depth0),{"name":"if","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.program(47, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.merged : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(49, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(50, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(52, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(54, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(56, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(57, data, 0, blockParams, depths),"inverse":container.program(63, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(59, data, 0, blockParams, depths),"inverse":container.program(65, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(66, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(68, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"25":function(container,depth0,helpers,partials,data) { return " \n \n \n"; @@ -328,45 +332,47 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia return " \n"; },"30":function(container,depth0,helpers,partials,data) { return " \n"; -},"32":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"32":function(container,depth0,helpers,partials,data) { + return " \n"; +},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.expressions : depth0),{"name":"each","hash":{},"fn":container.program(33, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"33":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.expressions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer = "
    "; - stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper)); + stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper)); if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { buffer += stack1; } return buffer + "
    " - + ((stack1 = helpers["if"].call(alias1,(depths[1] != null ? depths[1].playback : depths[1]),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.termTags : depth0),{"name":"if","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(42, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depths[1] != null ? depths[1].playback : depths[1]),{"name":"if","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.termTags : depth0),{"name":"if","hash":{},"fn":container.program(41, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(44, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"34":function(container,depth0,helpers,partials,data) { +},"36":function(container,depth0,helpers,partials,data) { var stack1, helper, options; - stack1 = ((helper = (helper = helpers.furigana || (depth0 != null ? depth0.furigana : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"furigana","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper)); + stack1 = ((helper = (helper = helpers.furigana || (depth0 != null ? depth0.furigana : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"furigana","hash":{},"fn":container.program(37, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper)); if (!helpers.furigana) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { return stack1; } else { return ''; } -},"35":function(container,depth0,helpers,partials,data) { +},"37":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"37":function(container,depth0,helpers,partials,data) { - return ""; },"39":function(container,depth0,helpers,partials,data) { + return ""; +},"41":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.termTags : depth0),{"name":"each","hash":{},"fn":container.program(40, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.termTags : depth0),{"name":"each","hash":{},"fn":container.program(42, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"40":function(container,depth0,helpers,partials,data) { +},"42":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; -},"42":function(container,depth0,helpers,partials,data) { +},"44":function(container,depth0,helpers,partials,data) { var stack1; return "
    " - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(43, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(45, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    "; -},"43":function(container,depth0,helpers,partials,data) { +},"45":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " @@ -390,45 +396,45 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ":" + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + "\n"; -},"45":function(container,depth0,helpers,partials,data) { - return "invisible"; },"47":function(container,depth0,helpers,partials,data) { + return "invisible"; +},"49":function(container,depth0,helpers,partials,data) { var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), buffer = "
    "; - stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(alias1,options) : helper)); + stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(36, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(alias1,options) : helper)); if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { buffer += stack1; } return buffer + "
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.termTags : depth0),{"name":"if","hash":{},"fn":container.program(48, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"48":function(container,depth0,helpers,partials,data) { + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.termTags : depth0),{"name":"if","hash":{},"fn":container.program(50, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"50":function(container,depth0,helpers,partials,data) { var stack1; return "
    \n" + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.termTags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"50":function(container,depth0,helpers,partials,data) { +},"52":function(container,depth0,helpers,partials,data) { var stack1; return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.reasons : depth0),{"name":"each","hash":{},"fn":container.program(51, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.reasons : depth0),{"name":"each","hash":{},"fn":container.program(53, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"51":function(container,depth0,helpers,partials,data) { +},"53":function(container,depth0,helpers,partials,data) { var stack1; return " " + container.escapeExpression(container.lambda(depth0, depth0)) + " " - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(52, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(54, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; -},"52":function(container,depth0,helpers,partials,data) { - return "«"; },"54":function(container,depth0,helpers,partials,data) { + return "«"; +},"56":function(container,depth0,helpers,partials,data) { var stack1; return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(55, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(57, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"55":function(container,depth0,helpers,partials,data) { +},"57":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " @@ -436,61 +442,61 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ":" + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + "\n"; -},"57":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"59":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(58, data, 0, blockParams, depths),"inverse":container.program(61, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); -},"58":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(60, data, 0, blockParams, depths),"inverse":container.program(63, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"60":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "
      \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(59, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(61, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"59":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"61":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "
  • " + ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","hash":{"compactGlossaries":(depths[1] != null ? depths[1].compactGlossaries : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
  • \n"; -},"61":function(container,depth0,helpers,partials,data) { +},"63":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.invokePartial(partials.definition,((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["0"] : stack1),{"name":"definition","hash":{"compactGlossaries":(depth0 != null ? depth0.compactGlossaries : depth0)},"data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"63":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"65":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.merged : depth0),{"name":"if","hash":{},"fn":container.program(57, data, 0, blockParams, depths),"inverse":container.program(64, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); -},"64":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.merged : depth0),{"name":"if","hash":{},"fn":container.program(59, data, 0, blockParams, depths),"inverse":container.program(66, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); +},"66":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","hash":{"compactGlossaries":(depth0 != null ? depth0.compactGlossaries : depth0)},"data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + " "; -},"66":function(container,depth0,helpers,partials,data) { +},"68":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(37, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"68":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"70":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(69, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"69":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(71, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"71":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(70, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(72, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"source":(depths[1] != null ? depths[1].source : depths[1]),"compactGlossaries":(depths[1] != null ? depths[1].compactGlossaries : depths[1]),"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"merged":(depths[1] != null ? depths[1].merged : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"70":function(container,depth0,helpers,partials,data) { - return "
    "; + + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"history":(depths[1] != null ? depths[1].history : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"compactGlossaries":(depths[1] != null ? depths[1].compactGlossaries : depths[1]),"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"merged":(depths[1] != null ? depths[1].merged : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); },"72":function(container,depth0,helpers,partials,data) { + return "
    "; +},"74":function(container,depth0,helpers,partials,data) { return "

    No results found.

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(68, data, 0, blockParams, depths),"inverse":container.program(72, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(70, data, 0, blockParams, depths),"inverse":container.program(74, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index ed3d9adc..bd4b13d1 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -37,6 +37,8 @@ class Display { this.eventListenersActive = false; this.clickScanPrevent = false; + this.poppedContextHistory = []; + this.windowScroll = new WindowScroll(); this.setInteractive(true); @@ -55,10 +57,16 @@ class Display { this.sourceTermView(); } + onHistoryTermView(e) { + e.preventDefault(); + this.poppedTermView(); + } + async onKanjiLookup(e) { try { e.preventDefault(); if (!this.context) { return; } + this.poppedContextHistory = []; const link = e.target; const context = { @@ -72,6 +80,7 @@ class Display { }) } }, + type: 'kanji', sentence: this.context.sentence, url: this.context.url }; @@ -104,6 +113,7 @@ class Display { async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { try { if (!this.context) { return; } + this.poppedContextHistory = []; const termLookupResults = await this.termLookup(e); if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; @@ -122,6 +132,7 @@ class Display { }) } }, + type: 'terms', disableScroll, sentence, url: this.context.url @@ -207,12 +218,20 @@ class Display { onWheel(e) { if (e.altKey) { - const delta = e.deltaY; - if (delta !== 0) { - this.entryScrollIntoView(this.index + (delta > 0 ? 1 : -1), null, true); + if (e.deltaY !== 0) { + this.entryScrollIntoView(this.index + (e.deltaY > 0 ? 1 : -1), null, true); e.preventDefault(); } } + if (e.shiftKey) { + const delta = e.deltaX || e.deltaY; + if (delta > 0) { + this.sourceTermView(); + e.preventDefault(); + } else if (delta < 0) { + this.poppedTermView(); + } + } } onRuntimeMessage({action, params}, sender, callback) { @@ -293,6 +312,7 @@ class Display { this.addEventListeners('.action-play-audio', 'click', this.onAudioPlay.bind(this)); this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this)); this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this)); + this.addEventListeners('.history-term', 'click', this.onHistoryTermView.bind(this)); if (this.options.scanning.enablePopupSearch) { this.addEventListeners('.glossary-item', 'mouseup', this.onGlossaryMouseUp.bind(this)); this.addEventListeners('.glossary-item', 'mousedown', this.onGlossaryMouseDown.bind(this)); @@ -342,6 +362,7 @@ class Display { const params = { definitions, source: context.source, + history: this.poppedContextHistory.length > 0, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -396,6 +417,7 @@ class Display { const params = { definitions, source: context.source, + history: this.poppedContextHistory.length > 0, addable: options.anki.enable, debug: options.general.debugInfo }; @@ -506,10 +528,28 @@ class Display { sourceTermView() { if (!this.context || !this.context.source) { return; } + this.poppedContextHistory.push({ + type: this.context.type, + details: { + definitions: this.definitions, + context: Object.assign({}, this.context, { + index: this.index, + scroll: this.windowScroll.y + }) + } + }); const {type, details} = this.context.source; this.setContent(type, details); } + poppedTermView() { + if (this.poppedContextHistory.length === 0) { return; } + this.context.index = this.index; + this.context.scroll = this.windowScroll.y; + const {type, details} = this.poppedContextHistory.pop(); + this.setContent(type, details); + } + noteTryAdd(mode) { const button = this.adderButtonFind(this.index, mode); if (button !== null && !button.classList.contains('disabled')) { @@ -783,6 +823,14 @@ Display.onKeyDownHandlers = { return false; }, + 'F': (self, e) => { + if (e.altKey) { + self.poppedTermView(); + return true; + } + return false; + }, + 'E': (self, e) => { if (e.altKey) { self.noteTryAdd('term-kanji'); diff --git a/tmpl/kanji.html b/tmpl/kanji.html index c3064526..35f997dc 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -23,6 +23,9 @@ No data found {{#if source}} {{/if}} + {{#if history}} + + {{/if}} @@ -93,7 +96,7 @@ No data found {{#if definitions}} {{#each definitions}} {{#unless @first}}
    {{/unless}} -{{> kanji debug=../debug addable=../addable source=../source root=../root}} +{{> kanji debug=../debug addable=../addable source=../source history=../history root=../root}} {{/each}} {{else}}

    No results found

    diff --git a/tmpl/terms.html b/tmpl/terms.html index 993b5aa0..5e4e694a 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -44,6 +44,9 @@ {{#if source}} {{/if}} + {{#if history}} + + {{/if}} @@ -131,7 +134,7 @@ {{#if definitions}} {{#each definitions}} {{#unless @first}}
    {{/unless}} -{{> term debug=../debug grouped=../grouped merged=../merged addable=../addable playback=../playback compactGlossaries=../compactGlossaries source=../source}} +{{> term debug=../debug grouped=../grouped merged=../merged addable=../addable playback=../playback compactGlossaries=../compactGlossaries source=../source history=../history}} {{/each}} {{else}}

    No results found.

    -- cgit v1.2.3 From 86ff831600254329bd52e90eb141a1c2c8e3d031 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 15:24:00 +0200 Subject: preventDefault correctly --- ext/mixed/js/display.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index bd4b13d1..f81ea7ee 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -222,14 +222,14 @@ class Display { this.entryScrollIntoView(this.index + (e.deltaY > 0 ? 1 : -1), null, true); e.preventDefault(); } - } - if (e.shiftKey) { + } else if (e.shiftKey) { const delta = e.deltaX || e.deltaY; if (delta > 0) { this.sourceTermView(); e.preventDefault(); } else if (delta < 0) { this.poppedTermView(); + e.preventDefault(); } } } -- cgit v1.2.3 From f1ecb4cd397ae047917582a5fc056a9151eb937d Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 15:54:55 +0200 Subject: correct X scroll direction for history navigation --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f81ea7ee..bd4dc0d0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -223,7 +223,7 @@ class Display { e.preventDefault(); } } else if (e.shiftKey) { - const delta = e.deltaX || e.deltaY; + const delta = -e.deltaX || e.deltaY; if (delta > 0) { this.sourceTermView(); e.preventDefault(); -- cgit v1.2.3 From 1dd88763de8e4ad2728d87dd33defb9cf1a71a42 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 28 Nov 2019 18:24:24 +0200 Subject: clear Display history on new lookup --- ext/fg/js/frontend.js | 2 +- ext/mixed/js/display.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index bcdfd152..b19e44d2 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -398,7 +398,7 @@ class Frontend { textSource.getRect(), textSource.getWritingMode(), type, - {definitions, context: {sentence, url, focus}} + {definitions, context: {sentence, url, focus, clearHistoryOnce: true}} ); this.textSourceCurrent = textSource; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index bd4dc0d0..d83efc13 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -351,6 +351,11 @@ class Display { this.setEventListenersActive(false); + if (context.clearHistoryOnce) { + delete context.clearHistoryOnce; + this.poppedContextHistory = []; + } + if (context.focus !== false) { window.focus(); } @@ -406,6 +411,11 @@ class Display { this.setEventListenersActive(false); + if (context.clearHistoryOnce) { + delete context.clearHistoryOnce; + this.poppedContextHistory = []; + } + if (context.focus !== false) { window.focus(); } -- cgit v1.2.3 From 8a94d186c33e3b4c8bf5caf14d2d7aad20e347cc Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 29 Nov 2019 01:36:14 +0200 Subject: fix context type inconsistencies --- ext/mixed/js/display.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index d83efc13..dc8766b4 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -80,7 +80,6 @@ class Display { }) } }, - type: 'kanji', sentence: this.context.sentence, url: this.context.url }; @@ -132,7 +131,6 @@ class Display { }) } }, - type: 'terms', disableScroll, sentence, url: this.context.url @@ -361,6 +359,7 @@ class Display { } this.definitions = definitions; + context.type = 'terms'; this.context = context; const sequence = ++this.sequence; @@ -421,6 +420,7 @@ class Display { } this.definitions = definitions; + context.type = 'kanji'; this.context = context; const sequence = ++this.sequence; @@ -548,16 +548,16 @@ class Display { }) } }); - const {type, details} = this.context.source; - this.setContent(type, details); + const {details} = this.context.source; + this.setContent(details.context.type, details); } poppedTermView() { if (this.poppedContextHistory.length === 0) { return; } this.context.index = this.index; this.context.scroll = this.windowScroll.y; - const {type, details} = this.poppedContextHistory.pop(); - this.setContent(type, details); + const {details} = this.poppedContextHistory.pop(); + this.setContent(details.context.type, details); } noteTryAdd(mode) { -- cgit v1.2.3 From ff9510356e61f9548c5c773ac0f9d85f153ad714 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 30 Nov 2019 04:49:37 +0200 Subject: rewrite history as a doubly linked list --- ext/bg/js/templates.js | 16 +++++----- ext/mixed/js/display.js | 85 +++++++++++++++++++++++++++---------------------- tmpl/kanji.html | 2 +- tmpl/terms.html | 2 +- 4 files changed, 57 insertions(+), 48 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index e9ef7de1..9320477f 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -137,17 +137,17 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia return "
    \n \n \n
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.next : depth0),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.program(39, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + + ">\n\n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(41, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"33":function(container,depth0,helpers,partials,data) { return "class=\"source-term\""; },"35":function(container,depth0,helpers,partials,data) { return "class=\"source-term term-button-fade\""; },"37":function(container,depth0,helpers,partials,data) { - return "class=\"history-term\""; + return "class=\"next-term\""; },"39":function(container,depth0,helpers,partials,data) { - return "class=\"history-term term-button-fade\""; + return "class=\"next-term term-button-fade\""; },"41":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; @@ -485,17 +485,17 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia return "
    \n \n \n
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.next : depth0),{"name":"if","hash":{},"fn":container.program(71, data, 0, blockParams, depths),"inverse":container.program(73, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "") + + ">\n\n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(75, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"67":function(container,depth0,helpers,partials,data) { return "class=\"source-term\""; },"69":function(container,depth0,helpers,partials,data) { return "class=\"source-term term-button-fade\""; },"71":function(container,depth0,helpers,partials,data) { - return "class=\"history-term\""; + return "class=\"next-term\""; },"73":function(container,depth0,helpers,partials,data) { - return "class=\"history-term term-button-fade\""; + return "class=\"next-term term-button-fade\""; },"75":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index dc8766b4..86780764 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -37,8 +37,6 @@ class Display { this.eventListenersActive = false; this.clickScanPrevent = false; - this.poppedContextHistory = []; - this.windowScroll = new WindowScroll(); this.setInteractive(true); @@ -57,31 +55,32 @@ class Display { this.sourceTermView(); } - onHistoryTermView(e) { + onNextTermView(e) { e.preventDefault(); - this.poppedTermView(); + this.nextTermView(); } async onKanjiLookup(e) { try { e.preventDefault(); if (!this.context) { return; } - this.poppedContextHistory = []; + this.context.details.context.next = null; const link = e.target; + const {type, details} = this.context; const context = { source: { - type: 'terms', + type, details: { definitions: this.definitions, - context: Object.assign({}, this.context, { + context: Object.assign({}, details.context, { index: this.entryIndexFind(link), scroll: this.windowScroll.y }) } }, - sentence: this.context.sentence, - url: this.context.url + sentence: details.context.sentence, + url: details.context.url }; this.windowScroll.toY(0); @@ -112,7 +111,7 @@ class Display { async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { try { if (!this.context) { return; } - this.poppedContextHistory = []; + this.context.details.context.next = null; const termLookupResults = await this.termLookup(e); if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; @@ -120,12 +119,13 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + const {type, details} = this.context; const context = { - source: disableHistory ? this.context.source : { - type: 'terms', + source: disableHistory ? details.context.source : { + type, details: { definitions: this.definitions, - context: Object.assign({}, this.context, { + context: Object.assign({}, details.context, { index: this.entryIndexFind(scannedElement), scroll: this.windowScroll.y }) @@ -133,7 +133,7 @@ class Display { }, disableScroll, sentence, - url: this.context.url + url: details.context.url }; this.setContentTerms(definitions, context); @@ -226,7 +226,7 @@ class Display { this.sourceTermView(); e.preventDefault(); } else if (delta < 0) { - this.poppedTermView(); + this.nextTermView(); e.preventDefault(); } } @@ -310,7 +310,7 @@ class Display { this.addEventListeners('.action-play-audio', 'click', this.onAudioPlay.bind(this)); this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this)); this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this)); - this.addEventListeners('.history-term', 'click', this.onHistoryTermView.bind(this)); + this.addEventListeners('.next-term', 'click', this.onNextTermView.bind(this)); if (this.options.scanning.enablePopupSearch) { this.addEventListeners('.glossary-item', 'mouseup', this.onGlossaryMouseUp.bind(this)); this.addEventListeners('.glossary-item', 'mousedown', this.onGlossaryMouseDown.bind(this)); @@ -351,7 +351,9 @@ class Display { if (context.clearHistoryOnce) { delete context.clearHistoryOnce; - this.poppedContextHistory = []; + if (this.context !== null) { + this.context.details.context.next = null; + } } if (context.focus !== false) { @@ -359,14 +361,16 @@ class Display { } this.definitions = definitions; - context.type = 'terms'; - this.context = context; + this.context = { + type: 'terms', + details: {definitions, context} + }; const sequence = ++this.sequence; const params = { definitions, source: context.source, - history: this.poppedContextHistory.length > 0, + next: context.next, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -412,7 +416,9 @@ class Display { if (context.clearHistoryOnce) { delete context.clearHistoryOnce; - this.poppedContextHistory = []; + if (this.context !== null) { + this.context.details.context.next = null; + } } if (context.focus !== false) { @@ -420,14 +426,16 @@ class Display { } this.definitions = definitions; - context.type = 'kanji'; - this.context = context; + this.context = { + type: 'kanji', + details: {definitions, context} + }; const sequence = ++this.sequence; const params = { definitions, source: context.source, - history: this.poppedContextHistory.length > 0, + next: context.next, addable: options.anki.enable, debug: options.general.debugInfo }; @@ -537,27 +545,28 @@ class Display { } sourceTermView() { - if (!this.context || !this.context.source) { return; } - this.poppedContextHistory.push({ - type: this.context.type, + if (!this.context || !this.context.details.context.source) { return; } + const {type, details} = this.context; + const sourceContext = details.context.source; + sourceContext.details.context.next = { + type, details: { definitions: this.definitions, - context: Object.assign({}, this.context, { + context: Object.assign({}, details.context, { index: this.index, scroll: this.windowScroll.y }) } - }); - const {details} = this.context.source; - this.setContent(details.context.type, details); + }; + this.setContent(sourceContext.type, sourceContext.details); } - poppedTermView() { - if (this.poppedContextHistory.length === 0) { return; } - this.context.index = this.index; - this.context.scroll = this.windowScroll.y; - const {details} = this.poppedContextHistory.pop(); - this.setContent(details.context.type, details); + nextTermView() { + if (!this.context.details.context.next) { return; } + this.context.details.context.index = this.index; + this.context.details.context.scroll = this.windowScroll.y; + const {type, details} = this.context.details.context.next; + this.setContent(type, details); } noteTryAdd(mode) { @@ -835,7 +844,7 @@ Display.onKeyDownHandlers = { 'F': (self, e) => { if (e.altKey) { - self.poppedTermView(); + self.nextTermView(); return true; } return false; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 8c79e9dd..bbc0fc9d 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -90,7 +90,7 @@ No data found {{#if definitions}}
    - +
    {{#each definitions}} {{#unless @first}}
    {{/unless}} diff --git a/tmpl/terms.html b/tmpl/terms.html index 2f727365..9cfabc58 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -128,7 +128,7 @@ {{#if definitions}}
    - +
    {{#each definitions}} {{#unless @first}}
    {{/unless}} -- cgit v1.2.3 From be23ad7213477500534a2546ca6ef139b23f0af9 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 30 Nov 2019 04:59:36 +0200 Subject: remove dead code --- ext/bg/js/search.js | 3 +-- ext/fg/js/frontend.js | 2 +- ext/mixed/js/display.js | 14 -------------- 3 files changed, 2 insertions(+), 17 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index a5b5fb25..a98d7a9a 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -221,8 +221,7 @@ class DisplaySearch extends Display { this.setContentTerms(definitions, { focus: false, sentence: {text: query, offset: 0}, - url: window.location.href, - clearHistoryOnce: true + url: window.location.href }); } else { this.container.textContent = ''; diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index b19e44d2..bcdfd152 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -398,7 +398,7 @@ class Frontend { textSource.getRect(), textSource.getWritingMode(), type, - {definitions, context: {sentence, url, focus, clearHistoryOnce: true}} + {definitions, context: {sentence, url, focus}} ); this.textSourceCurrent = textSource; diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 86780764..4d32377f 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -349,13 +349,6 @@ class Display { this.setEventListenersActive(false); - if (context.clearHistoryOnce) { - delete context.clearHistoryOnce; - if (this.context !== null) { - this.context.details.context.next = null; - } - } - if (context.focus !== false) { window.focus(); } @@ -414,13 +407,6 @@ class Display { this.setEventListenersActive(false); - if (context.clearHistoryOnce) { - delete context.clearHistoryOnce; - if (this.context !== null) { - this.context.details.context.next = null; - } - } - if (context.focus !== false) { window.focus(); } -- cgit v1.2.3 From 5929018facf792c203e18d3ec690478ee44388e0 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 1 Dec 2019 05:38:23 +0200 Subject: move Display context to a new class --- ext/bg/js/search.js | 1 + ext/bg/search.html | 1 + ext/fg/float.html | 1 + ext/mixed/js/display-context.js | 55 ++++++++++++++++++ ext/mixed/js/display.js | 126 ++++++++++++++++++++-------------------- 5 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 ext/mixed/js/display-context.js (limited to 'ext/mixed/js/display.js') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index a98d7a9a..00b7ca4b 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -220,6 +220,7 @@ class DisplaySearch extends Display { const {definitions} = await apiTermsFind(query, details, this.optionsContext); this.setContentTerms(definitions, { focus: false, + disableHistory: true, sentence: {text: query, offset: 0}, url: window.location.href }); diff --git a/ext/bg/search.html b/ext/bg/search.html index bac7f01c..fef30456 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -71,6 +71,7 @@ + diff --git a/ext/fg/float.html b/ext/fg/float.html index 38439c79..8cc5a129 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -39,6 +39,7 @@ + diff --git a/ext/mixed/js/display-context.js b/ext/mixed/js/display-context.js new file mode 100644 index 00000000..4b399881 --- /dev/null +++ b/ext/mixed/js/display-context.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +class DisplayContext { + constructor(type, definitions, context) { + this.type = type; + this.definitions = definitions; + this.context = context; + } + + get(key) { + return this.context[key]; + } + + set(key, value) { + this.context[key] = value; + } + + update(data) { + Object.assign(this.context, data); + } + + get previous() { + return this.context.previous; + } + + get next() { + return this.context.next; + } + + static push(self, type, definitions, context) { + const newContext = new DisplayContext(type, definitions, context); + if (self !== null) { + newContext.update({previous: self}); + self.update({next: newContext}); + } + return newContext; + } +} diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 4d32377f..ab50aac0 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -64,27 +64,17 @@ class Display { try { e.preventDefault(); if (!this.context) { return; } - this.context.details.context.next = null; const link = e.target; - const {type, details} = this.context; + this.context.update({ + index: this.entryIndexFind(link), + scroll: this.windowScroll.y + }); const context = { - source: { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.entryIndexFind(link), - scroll: this.windowScroll.y - }) - } - }, - sentence: details.context.sentence, - url: details.context.url + sentence: this.context.get('sentence'), + url: this.context.get('url') }; - this.windowScroll.toY(0); - const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); this.setContentKanji(definitions, context); } catch (error) { @@ -111,7 +101,7 @@ class Display { async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { try { if (!this.context) { return; } - this.context.details.context.next = null; + const termLookupResults = await this.termLookup(e); if (!termLookupResults) { return; } const {textSource, definitions} = termLookupResults; @@ -119,29 +109,29 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); - const {type, details} = this.context; const context = { - source: disableHistory ? details.context.source : { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.entryIndexFind(scannedElement), - scroll: this.windowScroll.y - }) - } - }, disableScroll, + disableHistory, sentence, - url: details.context.url + url: this.context.get('url') }; + if (disableHistory) { + Object.assign(context, { + previous: this.context.previous, + next: this.context.next + }); + } else { + this.context.update({ + index: this.entryIndexFind(scannedElement), + scroll: this.windowScroll.y + }); + Object.assign(context, { + previous: this.context + }); + } this.setContentTerms(definitions, context); - if (!disableScroll) { - this.windowScroll.toY(0); - } - if (selectText) { textSource.select(); } @@ -354,16 +344,18 @@ class Display { } this.definitions = definitions; - this.context = { - type: 'terms', - details: {definitions, context} - }; + if (context.disableHistory) { + delete context.disableHistory; + this.context = new DisplayContext('terms', definitions, context); + } else { + this.context = DisplayContext.push(this.context, 'terms', definitions, context); + } const sequence = ++this.sequence; const params = { definitions, - source: context.source, - next: context.next, + source: this.context.previous, + next: this.context.next, addable: options.anki.enable, grouped: options.general.resultOutputMode === 'group', merged: options.general.resultOutputMode === 'merge', @@ -383,6 +375,7 @@ class Display { if (!disableScroll) { this.entryScrollIntoView(index || 0, scroll); } else { + delete context.disableScroll; this.entrySetCurrent(index || 0); } @@ -412,16 +405,18 @@ class Display { } this.definitions = definitions; - this.context = { - type: 'kanji', - details: {definitions, context} - }; + if (context.disableHistory) { + delete context.disableHistory; + this.context = new DisplayContext('kanji', definitions, context); + } else { + this.context = DisplayContext.push(this.context, 'kanji', definitions, context); + } const sequence = ++this.sequence; const params = { definitions, - source: context.source, - next: context.next, + source: this.context.previous, + next: this.context.next, addable: options.anki.enable, debug: options.general.debugInfo }; @@ -531,28 +526,33 @@ class Display { } sourceTermView() { - if (!this.context || !this.context.details.context.source) { return; } - const {type, details} = this.context; - const sourceContext = details.context.source; - sourceContext.details.context.next = { - type, - details: { - definitions: this.definitions, - context: Object.assign({}, details.context, { - index: this.index, - scroll: this.windowScroll.y - }) - } + if (!this.context || !this.context.previous) { return; } + this.context.update({ + index: this.index, + scroll: this.windowScroll.y + }); + const previousContext = this.context.previous; + previousContext.set('disableHistory', true); + const details = { + definitions: previousContext.definitions, + context: previousContext.context }; - this.setContent(sourceContext.type, sourceContext.details); + this.setContent(previousContext.type, details); } nextTermView() { - if (!this.context.details.context.next) { return; } - this.context.details.context.index = this.index; - this.context.details.context.scroll = this.windowScroll.y; - const {type, details} = this.context.details.context.next; - this.setContent(type, details); + if (!this.context || !this.context.next) { return; } + this.context.update({ + index: this.index, + scroll: this.windowScroll.y + }); + const nextContext = this.context.next; + nextContext.set('disableHistory', true); + const details = { + definitions: nextContext.definitions, + context: nextContext.context + }; + this.setContent(nextContext.type, details); } noteTryAdd(mode) { -- cgit v1.2.3 From abe70e3b8c9fe8fb59cfbdad7b0e6f242971a4c5 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 1 Dec 2019 06:08:05 +0200 Subject: always update current position on term lookup --- ext/mixed/js/display.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index ab50aac0..303023be 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -109,6 +109,10 @@ class Display { const scannedElement = e.target; const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + this.context.update({ + index: this.entryIndexFind(scannedElement), + scroll: this.windowScroll.y + }); const context = { disableScroll, disableHistory, @@ -121,10 +125,6 @@ class Display { next: this.context.next }); } else { - this.context.update({ - index: this.entryIndexFind(scannedElement), - scroll: this.windowScroll.y - }); Object.assign(context, { previous: this.context }); -- cgit v1.2.3 From 403b86675d288a8082125475f87f9b1740e3480a Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 1 Dec 2019 15:03:37 +0200 Subject: fix entry scroll index 0 bug Introduced in 4e7d08ff2c184a361622a6efaf00e21af51428a9 because the range-limited index value isn't kept in the same scope. --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mixed/js/display.js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 303023be..f1829198 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -515,7 +515,7 @@ class Display { if (scroll !== null) { target = scroll; } else { - target = index === 0 || entry === null ? 0 : Display.getElementTop(entry); + target = this.index === 0 || entry === null ? 0 : Display.getElementTop(entry); } if (smooth) { -- cgit v1.2.3