diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-28 21:33:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-28 21:33:30 -0500 |
commit | a81787c55b10b43344a9506b62d90c317b329667 (patch) | |
tree | 9a2ffe10e63efc85f3beacf31d0356ebe58ca606 /ext/mixed/js | |
parent | e610a62ceb07313c581a0bd2d5c8ebbc7c39ba4f (diff) |
Remove the dictionary tag from the definitionTags (#1324)
* Remove dictionary tag from term definitionTags and kanji tags
* Update test data
* Update templates
* Update tests
* Update information
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/display-generator.js | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index e9eaa68f..d7cc5bd4 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -91,9 +91,28 @@ class DisplayGenerator { this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), reasons); this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); - this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitions); this._appendMultiple(termTagsContainer, this._createTermTag.bind(this), termTags, expressions.length); + // Add definitions + const dictionaryTag = this._createDictionaryTag(null); + for (let i = 0, ii = definitions.length; i < ii; ++i) { + const definition = definitions[i]; + const {dictionary} = definition; + + if (dictionaryTag.dictionary === dictionary) { + dictionaryTag.redundant = true; + } else { + dictionaryTag.redundant = false; + dictionaryTag.dictionary = dictionary; + dictionaryTag.name = dictionary; + } + + const node2 = this._createTermDefinitionItem(definition, dictionaryTag); + node2.dataset.index = `${i}`; + definitionsContainer.appendChild(node2); + } + definitionsContainer.dataset.count = `${definitions.length}`; + return node; } @@ -114,8 +133,10 @@ class DisplayGenerator { glyphContainer.textContent = details.character; const groupedFrequencies = DictionaryDataUtil.groupKanjiFrequencies(details.frequencies); + const dictionaryTag = this._createDictionaryTag(details.dictionary); + this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true); - this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags); + this._appendMultiple(tagContainer, this._createTag.bind(this), [...details.tags, dictionaryTag]); this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary); this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi); this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi); @@ -211,17 +232,17 @@ class DisplayGenerator { return fragment; } - _createTermDefinitionItem(details) { + _createTermDefinitionItem(details, dictionaryTag) { const node = this._templates.instantiate('term-definition-item'); const tagListContainer = node.querySelector('.term-definition-tag-list'); const onlyListContainer = node.querySelector('.term-definition-disambiguation-list'); const glossaryContainer = node.querySelector('.term-glossary-list'); - const dictionary = details.dictionary; + const {dictionary, definitionTags} = details; node.dataset.dictionary = dictionary; - this._appendMultiple(tagListContainer, this._createTag.bind(this), details.definitionTags); + this._appendMultiple(tagListContainer, this._createTag.bind(this), [...definitionTags, dictionaryTag]); this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), details.only); this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary, dictionary); @@ -645,4 +666,16 @@ class DisplayGenerator { container.appendChild(document.createTextNode(parts[i])); } } + + _createDictionaryTag(dictionary) { + return { + name: dictionary, + category: 'dictionary', + notes: '', + order: 100, + score: 0, + dictionary, + redundant: false + }; + } } |