Better output

This commit is contained in:
Alex Yatskov 2016-03-27 18:24:04 -07:00
parent 70faa9e87f
commit 2bdb576378
2 changed files with 29 additions and 1 deletions

View File

@ -48,8 +48,16 @@ class Client {
return;
}
findTerm(range.toString(), ({results, length}) => {
if (length === 0) {
this.hidePopup();
} else {
range.setEnd(range.endContainer, range.startOffset + length);
this.popup.html(renderDefs(results.slice(0, 5)));
this.showPopup(range);
}
});
}
onMessage(request, sender, callback) {
this.setEnabled(request === 'enabled');

View File

@ -68,3 +68,23 @@ function getPopupPositionForRange(popup, range, offset) {
return {x: posX, y: posY};
}
function renderDefs(terms) {
const outputs = [];
for (let term of terms) {
outputs.push(renderDef(term));
}
return outputs.join('');
}
function renderDef(term) {
return `
<div class="yomichan-def">
<span class="yomichan-def-expression">${term.expression}</span>
<span class="yomichan-def-rules">${term.rules.join('&nbsp;&lt;&nbsp;')}</span>
<span class="yomichan-def-reading">${term.reading}</span>
<span class="yomichan-def-glossary">${term.glossary}</span>
</div>
`;
}