summaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/display-generator.js35
-rw-r--r--ext/mixed/js/display.js9
2 files changed, 21 insertions, 23 deletions
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js
index 53d68162..9daf2e91 100644
--- a/ext/mixed/js/display-generator.js
+++ b/ext/mixed/js/display-generator.js
@@ -49,42 +49,31 @@ class DisplayGenerator {
const pitchesContainer = node.querySelector('.term-pitch-accent-group-list');
const frequenciesContainer = node.querySelector('.frequencies');
const definitionsContainer = node.querySelector('.term-definition-list');
- const debugInfoContainer = node.querySelector('.debug-info');
const bodyContainer = node.querySelector('.term-entry-body');
- const {termTags, expressions, definitions, type} = details;
-
+ const {termTags, expressions, type, reasons, frequencies} = details;
+ const definitions = (type === 'term' ? [details] : details.definitions);
+ const merged = (type === 'termMerged' || type === 'termMergedByGlossary');
const pitches = DictionaryDataUtil.getPitchAccentInfos(details);
const pitchCount = pitches.reduce((i, v) => i + v.pitches.length, 0);
- const expressionMulti = (type === 'termMerged' || type === 'termMergedByGlossary');
- const definitionMulti = Array.isArray(definitions);
- const expressionCount = expressionMulti ? expressions.length : 1;
- const definitionCount = definitionMulti ? definitions.length : 1;
- const uniqueExpressionCount = Array.isArray(details.expression) ? new Set(details.expression).size : 1;
-
- node.dataset.expressionMulti = `${expressionMulti}`;
- node.dataset.definitionMulti = `${definitionMulti}`;
- node.dataset.expressionCount = `${expressionCount}`;
- node.dataset.definitionCount = `${definitionCount}`;
- node.dataset.uniqueExpressionCount = `${uniqueExpressionCount}`;
+ node.dataset.format = type;
+ node.dataset.expressionMulti = `${merged}`;
+ node.dataset.expressionCount = `${expressions.length}`;
+ node.dataset.definitionCount = `${definitions.length}`;
node.dataset.pitchAccentDictionaryCount = `${pitches.length}`;
node.dataset.pitchAccentCount = `${pitchCount}`;
bodyContainer.dataset.sectionCount = `${
- (definitionCount > 0 ? 1 : 0) +
+ (definitions.length > 0 ? 1 : 0) +
(pitches.length > 0 ? 1 : 0)
}`;
- this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressionMulti ? expressions : [details], termTags);
- this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), details.reasons);
- this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), details.frequencies);
+ this._appendMultiple(expressionsContainer, this._createTermExpression.bind(this), expressions, termTags);
+ this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), reasons);
+ this._appendMultiple(frequenciesContainer, this._createFrequencyTag.bind(this), frequencies);
this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches);
- this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitionMulti ? definitions : [details]);
-
- if (debugInfoContainer !== null) {
- debugInfoContainer.textContent = JSON.stringify(details, null, 4);
- }
+ this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitions);
return node;
}
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 69d94603..92020b51 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -721,6 +721,14 @@ class Display extends EventDispatcher {
}
}
+ _onDebugLogClick(e) {
+ const link = e.currentTarget;
+ const index = this._entryIndexFind(link);
+ if (index < 0 || index >= this._definitions.length) { return; }
+ const definition = this._definitions[index];
+ console.log(definition);
+ }
+
_updateDocumentOptions(options) {
const data = document.documentElement.dataset;
data.ankiEnabled = `${options.anki.enable}`;
@@ -771,6 +779,7 @@ class Display extends EventDispatcher {
this.addMultipleEventListeners('.action-view-note', 'click', this._onNoteView.bind(this));
this.addMultipleEventListeners('.action-play-audio', 'click', this._onAudioPlay.bind(this));
this.addMultipleEventListeners('.kanji-link', 'click', this._onKanjiLookup.bind(this));
+ this.addMultipleEventListeners('.debug-log-link', 'click', this._onDebugLogClick.bind(this));
if (this._options !== null && this._options.scanning.enablePopupSearch) {
this.addMultipleEventListeners('.term-glossary-item, .tag', 'mouseup', this._onGlossaryMouseUp.bind(this));
this.addMultipleEventListeners('.term-glossary-item, .tag', 'mousedown', this._onGlossaryMouseDown.bind(this));