From c4e35fbf54a9cd80e27d600d47b24b1afdfeca6d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 18 Apr 2016 19:38:03 -0700 Subject: [PATCH] Display tooltips for tags --- ext/bg/js/templates.js | 8 ++++++-- ext/bg/js/translator.js | 25 +++++++++++++++++++------ ext/fg/css/popup.css | 1 + util/tmpl/term.html | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index cacd8808..1609cc97 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -77,8 +77,12 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"11":function(container,depth0,helpers,partials,data) { - return " " - + container.escapeExpression(container.lambda(depth0, depth0)) + var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " " + + alias4(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper))) + "\n"; },"13":function(container,depth0,helpers,partials,data) { return "
  • " diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1a024a40..e2d15e46 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -19,14 +19,16 @@ class Translator { constructor() { - this.loaded = false; - this.paths = { + this.paths = { rules: 'bg/data/rules.json', + tags: 'bg/data/tags.json', edict: 'bg/data/edict.json', enamdict: 'bg/data/enamdict.json', kanjidic: 'bg/data/kanjidic.json' }; + this.loaded = false; + this.tags = null; this.dictionary = new Dictionary(); this.deinflector = new Deinflector(); } @@ -38,13 +40,16 @@ class Translator { } const pendingLoads = []; - for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) { + for (const key of ['rules', 'tags', 'edict', 'enamdict', 'kanjidic']) { pendingLoads.push(key); Translator.loadData(this.paths[key], (response) => { switch (key) { case 'rules': this.deinflector.setRules(JSON.parse(response)); break; + case 'tags': + this.tags = JSON.parse(response); + break; case 'kanjidic': this.dictionary.addKanjiDict(key, JSON.parse(response)); break; @@ -98,8 +103,8 @@ class Translator { return 1; } - const p1 = v1.tags.indexOf('P') >= 0; - const p2 = v2.tags.indexOf('P') >= 0; + const p1 = v1.tags.hasOwnProperty('P'); + const p2 = v2.tags.hasOwnProperty('P'); if (p1 && !p2) { return -1; } else if (!p1 && p2) { @@ -153,12 +158,20 @@ class Translator { } } + let tagInfo = {}; + for (const tag of entry.tags) { + const info = this.tags[tag]; + if (info) { + tagInfo[tag] = info; + } + } + if (matched) { groups[entry.id] = { expression: entry.expression, reading: entry.reading, glossary: entry.glossary, - tags: entry.tags, + tags: tagInfo, source: source, rules: rules }; diff --git a/ext/fg/css/popup.css b/ext/fg/css/popup.css index 2e694b42..1c40bdfd 100644 --- a/ext/fg/css/popup.css +++ b/ext/fg/css/popup.css @@ -46,6 +46,7 @@ body { background-color: #777; border-radius: 0.25em; color: #fff; + cursor: default; display: inline; font-size: 75%; font-weight: 700; diff --git a/util/tmpl/term.html b/util/tmpl/term.html index 8c0e54ca..abcbb215 100644 --- a/util/tmpl/term.html +++ b/util/tmpl/term.html @@ -15,7 +15,7 @@ {{#if tags}}
    {{#each tags}} - {{.}} + {{@key}} {{/each}}
    {{/if}}