From 88e71f82232781a1bc16701ce4719d770222ec4c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 11 Sep 2021 12:51:51 -0400 Subject: Add data-is-primary attribute to headwords (#1946) --- ext/js/display/display-generator.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ext/js') diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 95b4224b..fe899e53 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -232,12 +232,21 @@ class DisplayGenerator { // Private _createTermHeadword(headword, headwordIndex, pronunciations) { - const {term, reading, tags} = headword; + const {term, reading, tags, sources} = headword; + + let isPrimaryAny = false; + for (const {isPrimary} of sources) { + if (isPrimary) { + isPrimaryAny = true; + break; + } + } const node = this._templates.instantiate('headword'); const termContainer = node.querySelector('.headword-term'); + node.dataset.isPrimary = `${isPrimaryAny}`; node.dataset.readingIsSame = `${reading === term}`; node.dataset.frequency = DictionaryDataUtil.getTermFrequency(tags); -- cgit v1.2.3