Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 85 additions & 14 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,24 @@ export class DisplayGenerator {
const glyphContainer = this._querySelector(node, '.kanji-glyph');
const frequencyGroupListContainer = this._querySelector(node, '.frequency-group-list');
const tagContainer = this._querySelector(node, '.kanji-tag-list');
const definitionsContainer = this._querySelector(node, '.kanji-gloss-list');
const chineseReadingsContainer = this._querySelector(node, '.kanji-readings-chinese');
const japaneseReadingsContainer = this._querySelector(node, '.kanji-readings-japanese');

const definitionsContainer = this._querySelector(node, '.kanji-gloss-container');
const definitionsHeader = this._querySelector(node, '.kanji-meaning-header');

const readingsContainer = this._querySelector(node, '.kanji-readings');
const readingsHeader = this._querySelector(node, '.kanji-readings-header');

const statisticsContainer = this._querySelector(node, '.kanji-statistics');
const statisticsHeader = this._querySelector(node, '.kanji-statistics-header');

const classificationsContainer = this._querySelector(node, '.kanji-classifications');
const classificationsHeader = this._querySelector(node, '.kanji-classifications-header');

const codepointsContainer = this._querySelector(node, '.kanji-codepoints');
const codepointsHeader = this._querySelector(node, '.kanji-codepoints-header');

const dictionaryIndicesContainer = this._querySelector(node, '.kanji-dictionary-indices');
const dictionaryIndicesHeader = this._querySelector(node, '.kanji-dictionary-indices-header');

this._setTextContent(glyphContainer, dictionaryEntry.character, this._language);
if (this._language === 'ja') { glyphContainer.style.fontFamily = 'kanji-stroke-orders, sans-serif'; }
Expand Down Expand Up @@ -244,14 +255,75 @@ export class DisplayGenerator {

this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true);
this._appendMultiple(tagContainer, this._createTag.bind(this), [...dictionaryEntry.tags, dictionaryTag]);
this._appendMultiple(definitionsContainer, this._createKanjiDefinition.bind(this), dictionaryEntry.definitions);
this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.onyomi);
this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.kunyomi);

statisticsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.misc));
classificationsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.class));
codepointsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.code));
dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.index));
const definitionElements = [];
if (dictionaryEntry.definitions.length > 0) {
const element = document.createElement('ol');
element.className = 'kanji-gloss-list';
for (const x of dictionaryEntry.definitions) { element.appendChild(this._createKanjiDefinition(x)); }
Comment thread
Kuuuube marked this conversation as resolved.
definitionElements.push(element);
}

const onyomiElements = [];
if (dictionaryEntry.onyomi.length > 0) {
const element = document.createElement('dl');
element.className = 'kanji-readings-chinese';
for (const x of dictionaryEntry.onyomi) { element.appendChild(this._createKanjiReading(x)); }
onyomiElements.push(element);
}

const kunyomiElements = [];
if (dictionaryEntry.kunyomi.length > 0) {
const element = document.createElement('dl');
element.className = 'kanji-readings-japanese';
for (const x of dictionaryEntry.kunyomi) { element.appendChild(this._createKanjiReading(x)); }
kunyomiElements.push(element);
}

const tableMappings = [
{
container: definitionsContainer,
elements: definitionElements,
header: definitionsHeader,
},
{
container: readingsContainer,
elements: [...onyomiElements, ...kunyomiElements],
header: readingsHeader,
},
{
container: statisticsContainer,
elements: this._createKanjiInfoTable(dictionaryEntry.stats.misc),
header: statisticsHeader,
},
{
container: classificationsContainer,
elements: this._createKanjiInfoTable(dictionaryEntry.stats.class),
header: classificationsHeader,
},
{
container: codepointsContainer,
elements: this._createKanjiInfoTable(dictionaryEntry.stats.code),
header: codepointsHeader,
},
{
container: dictionaryIndicesContainer,
elements: this._createKanjiInfoTable(dictionaryEntry.stats.index),
header: dictionaryIndicesHeader,
},
];

for (const tableMapping of tableMappings) {
if (tableMapping.elements.length === 0) {
tableMapping.header.remove();
tableMapping.container.remove();
continue;
}

for (const tableElement of tableMapping.elements) {
tableMapping.container.appendChild(tableElement);
}
}

return node;
}
Expand Down Expand Up @@ -622,19 +694,18 @@ export class DisplayGenerator {

/**
* @param {import('dictionary').KanjiStat[]} details
* @returns {HTMLElement}
* @returns {HTMLElement[]}
*/
_createKanjiInfoTable(details) {
const node = this._instantiate('kanji-info-table');
const container = this._querySelector(node, '.kanji-info-table-body');

const count = this._appendMultiple(container, this._createKanjiInfoTableItem.bind(this), details);
if (count === 0) {
const n = this._createKanjiInfoTableItemEmpty();
container.appendChild(n);
return [];
}

return node;
return [node];
}

/**
Expand Down
16 changes: 8 additions & 8 deletions ext/templates-display.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@
<table class="kanji-glyph-table">
<tbody>
<tr>
<th scope="col">Meaning</th>
<th scope="col">Readings</th>
<th scope="col">Statistics</th>
<th scope="col" class="kanji-meaning-header">Meaning</th>
<th scope="col" class="kanji-readings-header">Readings</th>
<th scope="col" class="kanji-statistics-header">Statistics</th>
</tr>
<tr>
<td class="kanji-gloss-container"><ol class="kanji-gloss-list"></ol></td>
<td class="kanji-readings"><dl class="kanji-readings-chinese"></dl><dl class="kanji-readings-japanese"></dl></td>
<td class="kanji-gloss-container"></td>
<td class="kanji-readings"></td>
<td class="kanji-statistics"></td>
</tr>
<tr><th scope="col" colspan="3">Classifications</th></tr>
<tr><th scope="col" colspan="3" class="kanji-classifications-header">Classifications</th></tr>
<tr><td colspan="3" class="kanji-classifications"></td></tr>
<tr><th scope="col" colspan="3">Codepoints</th></tr>
<tr><th scope="col" colspan="3" class="kanji-codepoints-header">Codepoints</th></tr>
<tr><td colspan="3" class="kanji-codepoints"></td></tr>
<tr><th scope="col" colspan="3">Dictionary Indices</th></tr>
<tr><th scope="col" colspan="3" class="kanji-dictionary-indices-header">Dictionary Indices</th></tr>
<tr><td colspan="3" class="kanji-dictionary-indices"></td></tr>
</tbody>
</table>
Expand Down
Loading