summaryrefslogtreecommitdiff
path: root/ext/js/display/display-generator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-25 20:54:39 -0400
committerGitHub <noreply@github.com>2021-03-25 20:54:39 -0400
commit6af0ee26b943d87e25b5d7ff9b8cade6999b3660 (patch)
treef2f2438dc1ae34d802bd3a6c5a991d750eadb59a /ext/js/display/display-generator.js
parent4be5c8fd9f7860e701d0b7d3c8c0ee934bc60a4f (diff)
Fix tag disambiguation (#1556)
* Update display generator to use new data format for tag disambiguation * Add separator for multiple disambiguations
Diffstat (limited to 'ext/js/display/display-generator.js')
-rw-r--r--ext/js/display/display-generator.js53
1 files changed, 28 insertions, 25 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js
index be5d5e66..19e88b8a 100644
--- a/ext/js/display/display-generator.js
+++ b/ext/js/display/display-generator.js
@@ -163,7 +163,7 @@ class DisplayGenerator {
return this._templates.instantiate('footer-notification');
}
- createTagFooterNotificationDetails(tagNode) {
+ createTagFooterNotificationDetails(tagNode, dictionaryEntry) {
const node = this._templates.instantiateFragment('footer-notification-tag-details');
let details = tagNode.dataset.details;
@@ -173,32 +173,35 @@ class DisplayGenerator {
}
this._setTextContent(node.querySelector('.tag-details'), details);
- let disambiguation = null;
- try {
- let a = tagNode.dataset.disambiguation;
- if (typeof a !== 'undefined') {
- a = JSON.parse(a);
- if (Array.isArray(a)) { disambiguation = a; }
+ if (dictionaryEntry !== null) {
+ const {headwords} = dictionaryEntry;
+ const disambiguationHeadwords = [];
+ const {headwords: headwordIndices} = tagNode.dataset;
+ if (typeof headwordIndices === 'string' && headwordIndices.length > 0) {
+ for (let headwordIndex of headwordIndices.split(' ')) {
+ headwordIndex = Number.parseInt(headwordIndex, 10);
+ if (!Number.isNaN(headwordIndex) && headwordIndex >= 0 && headwordIndex < headwords.length) {
+ disambiguationHeadwords.push(headwords[headwordIndex]);
+ }
+ }
}
- } catch (e) {
- // NOP
- }
- if (disambiguation !== null) {
- const disambiguationContainer = node.querySelector('.tag-details-disambiguation-list');
- const copyAttributes = ['totalExpressionCount', 'matchedExpressionCount', 'unmatchedExpressionCount'];
- for (const attribute of copyAttributes) {
- const value = tagNode.dataset[attribute];
- if (typeof value === 'undefined') { continue; }
- disambiguationContainer.dataset[attribute] = value;
- }
- for (const {expression, reading} of disambiguation) {
- const disambiguationItem = document.createElement('span');
- disambiguationItem.className = 'tag-details-disambiguation';
- this._appendFurigana(disambiguationItem, expression, reading, (container, text) => {
- container.appendChild(document.createTextNode(text));
- });
- disambiguationContainer.appendChild(disambiguationItem);
+ if (disambiguationHeadwords.length > 0 && disambiguationHeadwords.length < headwords.length) {
+ const disambiguationContainer = node.querySelector('.tag-details-disambiguation-list');
+ const copyAttributes = ['totalExpressionCount', 'matchedExpressionCount', 'unmatchedExpressionCount'];
+ for (const attribute of copyAttributes) {
+ const value = tagNode.dataset[attribute];
+ if (typeof value === 'undefined') { continue; }
+ disambiguationContainer.dataset[attribute] = value;
+ }
+ for (const {term, reading} of disambiguationHeadwords) {
+ const disambiguationItem = document.createElement('span');
+ disambiguationItem.className = 'tag-details-disambiguation';
+ this._appendFurigana(disambiguationItem, term, reading, (container, text) => {
+ container.appendChild(document.createTextNode(text));
+ });
+ disambiguationContainer.appendChild(disambiguationItem);
+ }
}
}