aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/display-generator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-10-14 21:26:53 -0400
committerGitHub <noreply@github.com>2021-10-14 21:26:53 -0400
commit75aabd983da29023b8423bd44d565202aad6b664 (patch)
tree754fbe5457747cd72fcf13767fc3176fc0d8f280 /ext/js/display/display-generator.js
parent11f7591a7f5fcbfc3a3e631eaac0addb228c988a (diff)
String frequency support (#1989)
* Restore support for string frequency values * Add support for {value, displayValue} frequencies * Update test data * Improve number parsing of string frequencies * Improve reading detection * Expose a displayValue property for frequency information * Update docs * Expose displayValue to Anki note data * Fix translator * Update display generation * Update test data * Update counts
Diffstat (limited to 'ext/js/display/display-generator.js')
-rw-r--r--ext/js/display/display-generator.js44
1 files changed, 36 insertions, 8 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js
index fe899e53..fc377df1 100644
--- a/ext/js/display/display-generator.js
+++ b/ext/js/display/display-generator.js
@@ -548,18 +548,15 @@ class DisplayGenerator {
this._setTextContent(node.querySelector('.tag-label-content'), dictionary);
- const frequency = values.join(', ');
-
this._setTextContent(node.querySelector('.frequency-disambiguation-term'), term, 'ja');
this._setTextContent(node.querySelector('.frequency-disambiguation-reading'), (reading !== null ? reading : ''), 'ja');
- this._setTextContent(node.querySelector('.frequency-value'), frequency, 'ja');
+ this._populateFrequencyValueList(node.querySelector('.frequency-value-list'), values);
node.dataset.term = term;
node.dataset.reading = reading;
node.dataset.hasReading = `${reading !== null}`;
node.dataset.readingIsSame = `${reading === term}`;
node.dataset.dictionary = dictionary;
- node.dataset.frequency = `${frequency}`;
node.dataset.details = dictionary;
return node;
@@ -569,19 +566,50 @@ class DisplayGenerator {
const {character, values} = details;
const node = this._templates.instantiate('kanji-frequency-item');
- const frequency = values.join(', ');
-
this._setTextContent(node.querySelector('.tag-label-content'), dictionary);
- this._setTextContent(node.querySelector('.frequency-value'), frequency, 'ja');
+ this._populateFrequencyValueList(node.querySelector('.frequency-value-list'), values);
node.dataset.character = character;
node.dataset.dictionary = dictionary;
- node.dataset.frequency = `${frequency}`;
node.dataset.details = dictionary;
return node;
}
+ _populateFrequencyValueList(node, values) {
+ let fullFrequency = '';
+ for (let i = 0, ii = values.length; i < ii; ++i) {
+ const {frequency, displayValue} = values[i];
+ const frequencyString = `${frequency}`;
+ const text = displayValue !== null ? displayValue : frequency;
+
+ if (i > 0) {
+ const node2 = document.createElement('span');
+ node2.className = 'frequency-value';
+ node2.dataset.frequency = `${frequency}`;
+ node2.textContent = ', ';
+ node.appendChild(node2);
+ fullFrequency += ', ';
+ }
+
+ const node2 = document.createElement('span');
+ node2.className = 'frequency-value';
+ node2.dataset.frequency = frequencyString;
+ if (displayValue !== null) {
+ node2.dataset.displayValue = `${displayValue}`;
+ if (displayValue !== frequencyString) {
+ node2.title = frequencyString;
+ }
+ }
+ this._setTextContent(node2, text, 'ja');
+ node.appendChild(node2);
+
+ fullFrequency += text;
+ }
+
+ node.dataset.frequency = fullFrequency;
+ }
+
_appendKanjiLinks(container, text) {
const jp = this._japaneseUtil;
let part = '';