summaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/dictionary-data-util.js9
-rw-r--r--ext/mixed/js/display-generator.js51
2 files changed, 5 insertions, 55 deletions
diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js
index 72c28172..709f4ead 100644
--- a/ext/mixed/js/dictionary-data-util.js
+++ b/ext/mixed/js/dictionary-data-util.js
@@ -17,16 +17,13 @@
class DictionaryDataUtil {
static getPitchAccentInfos(definition) {
- if (typeof definition.character === 'string') {
- // Kanji
- return [];
- }
+ const {type} = definition;
+ if (type === 'kanji') { return []; }
const results = new Map();
const allExpressions = new Set();
const allReadings = new Set();
- const expressions = definition.expressions;
- const sources = Array.isArray(expressions) ? expressions : [definition];
+ const sources = [definition];
for (const {pitches: expressionPitches, expression} of sources) {
allExpressions.add(expression);
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js
index 7f8235e2..926eb25d 100644
--- a/ext/mixed/js/display-generator.js
+++ b/ext/mixed/js/display-generator.js
@@ -45,12 +45,12 @@ class DisplayGenerator {
const debugInfoContainer = node.querySelector('.debug-info');
const bodyContainer = node.querySelector('.term-entry-body');
- const {termTags, expressions, definitions} = details;
+ const {termTags, expressions, definitions, type} = details;
const pitches = DictionaryDataUtil.getPitchAccentInfos(details);
const pitchCount = pitches.reduce((i, v) => i + v.pitches.length, 0);
- const expressionMulti = Array.isArray(expressions);
+ const expressionMulti = (type === 'termMerged' || type === 'termMergedByGlossary');
const definitionMulti = Array.isArray(definitions);
const expressionCount = expressionMulti ? expressions.length : 1;
const definitionCount = definitionMulti ? definitions.length : 1;
@@ -568,51 +568,4 @@ class DisplayGenerator {
container.appendChild(document.createTextNode(parts[i]));
}
}
-
- _getPitchInfos(definition) {
- const results = new Map();
-
- const allExpressions = new Set();
- const allReadings = new Set();
- const expressions = definition.expressions;
- const sources = Array.isArray(expressions) ? expressions : [definition];
- for (const {pitches: expressionPitches, expression} of sources) {
- allExpressions.add(expression);
- for (const {reading, pitches, dictionary} of expressionPitches) {
- allReadings.add(reading);
- let dictionaryResults = results.get(dictionary);
- if (typeof dictionaryResults === 'undefined') {
- dictionaryResults = [];
- results.set(dictionary, dictionaryResults);
- }
-
- for (const {position, tags} of pitches) {
- let pitchInfo = this._findExistingPitchInfo(reading, position, tags, dictionaryResults);
- if (pitchInfo === null) {
- pitchInfo = {expressions: new Set(), reading, position, tags};
- dictionaryResults.push(pitchInfo);
- }
- pitchInfo.expressions.add(expression);
- }
- }
- }
-
- for (const dictionaryResults of results.values()) {
- for (const result of dictionaryResults) {
- const exclusiveExpressions = [];
- const exclusiveReadings = [];
- const resultExpressions = result.expressions;
- if (!areSetsEqual(resultExpressions, allExpressions)) {
- exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions));
- }
- if (allReadings.size > 1) {
- exclusiveReadings.push(result.reading);
- }
- result.exclusiveExpressions = exclusiveExpressions;
- result.exclusiveReadings = exclusiveReadings;
- }
- }
-
- return [...results.entries()];
- }
}