aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-18 20:35:40 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-18 20:35:40 -0700
commit0c0271ae34b4861ff5eac8bb3592534876caafb9 (patch)
tree0be1f77036951588961bc6a56ae36d2de11e6436 /ext/bg/js/translator.js
parent24957748918403a387fbae47f593001ce361891a (diff)
Tag sorting and sanitation
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js46
1 files changed, 38 insertions, 8 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index e2d15e46..eeeea540 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -103,8 +103,8 @@ class Translator {
return 1;
}
- const p1 = v1.tags.hasOwnProperty('P');
- const p2 = v2.tags.hasOwnProperty('P');
+ const p1 = v1.popular;
+ const p2 = v2.popular;
if (p1 && !p2) {
return -1;
} else if (!p1 && p2) {
@@ -158,22 +158,52 @@ class Translator {
}
}
- let tagInfo = {};
+ let popular = false;
+ let tagItems = [];
for (const tag of entry.tags) {
- const info = this.tags[tag];
- if (info) {
- tagInfo[tag] = info;
+ const tagItem = this.tags[tag];
+ if (tagItem) {
+ tagItems.push({
+ class: tagItem.class || 'default',
+ order: tagItem.order || Number.MAX_SAFE_INTEGER,
+ name: tag
+ });
+ }
+ if (tag === 'P') {
+ popular = true;
}
}
+ tagItems = tagItems.sort((v1, v2) => {
+ const order1 = v1.order;
+ const order2 = v2.order;
+ if (order1 < order2) {
+ return -1;
+ } else if (order1 > order2) {
+ return 1;
+ }
+
+ const name1 = v1.name;
+ const name2 = v2.name;
+ if (name1 < name2) {
+ return -1;
+ } else if (name1 > name2) {
+ return 1;
+ }
+
+ return 0;
+ });
+
+
if (matched) {
groups[entry.id] = {
expression: entry.expression,
reading: entry.reading,
glossary: entry.glossary,
- tags: tagInfo,
+ tags: tagItems,
source: source,
- rules: rules
+ rules: rules,
+ popular: popular
};
}
}