-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.js
144 lines (112 loc) · 3.87 KB
/
results.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var image_prefix = "/images/";
if (window.location.href.indexOf('localhost') === -1) {
image_prefix = "http://www.bpulse.co.uk/emoji/images/";
}
var unicode_value = window.location.pathname.split('/')[2];
var emoji_array = [];
$(document).ready(function() {
$(".vote_link").attr("href", "/emoji/" + unicode_value);
$.get('/reset-glyph-stats/' + unicode_value, function(data) {
getData();
});
});
$( window ).resize(function() {
$("#glyph_rows").empty()
renderGlyphScoreRows();
});
function like_comparison(a, b) {
if (a.like_count > b.like_count) return -1;
if (a.like_count < b.like_count) return 1;
else return 0;
}
function hate_comparison(a, b) {
if (a.hate_count > b.hate_count) return -1;
if (a.hate_count < b.hate_count) return 1;
else return 0;
}
function glyph_score_comparison(a, b) {
if (a.glyph_score > b.glyph_score) return -1;
if (a.glyph_score < b.glyph_score) return 1;
else return 0;
}
function getGlyphBox(emoji) {
var box = $("<div class='glyph'>");
box.attr("vendor", emoji.vendor_name);
var img = $("<img>");
img.attr("width", "72");
img.attr("src", image_prefix + emoji.unicode_value + "_" + emoji.vendor_name + ".png");
box.append(img);
return box;
}
function getData() {
$.get("/get-emoji/" + unicode_value, function(data) {
$("#emoji_name").html(data[0].emoji_name);
document.title = "EmojiRank: " + data[0].emoji_name;
var has_votes = false;
for (i in data) {
var emoji = data[i];
if (! emoji.like_count) emoji.like_count = 0;
if (! emoji.hate_count) emoji.hate_count = 0;
emoji_array.push(emoji);
if (emoji.like_count > 0 || emoji.hate_count > 0) {
has_votes = true;
}
}
if (!has_votes) {
$("#no_votes_warning").show();
$("#glyph_rows").hide();
}
renderGlyphScoreRows();
return;
emoji_array.sort(like_comparison);
for (i in emoji_array) {
var tr = $("<tr>");
tr.append($("<td>").text(parseInt(i, 10) + 1));
tr.append($("<td>").append(getGlyphBox(emoji_array[i])));
tr.append($("<td>").text(emoji_array[i].vendor_name));
tr.append($("<td>").text(emoji_array[i].like_count));
$("#table_by_like").append(tr);
}
emoji_array.sort(hate_comparison);
for (i in emoji_array) {
var tr = $("<tr>");
tr.append($("<td>").text(parseInt(i, 10) + 1));
tr.append($("<td>").append(getGlyphBox(emoji_array[i])));
tr.append($("<td>").text(emoji_array[i].vendor_name));
tr.append($("<td>").text(emoji_array[i].hate_count));
$("#table_by_hate").append(tr);
}
});
}
function renderGlyphScoreRows() {
emoji_array.sort(glyph_score_comparison);
var barWidth = ($("#glyph_rows").width() / 2) - 40;
var header = $("<tr><th>Negative</th><th>Vendor</th><th>Positive</th></tr>");
$("#glyph_rows").append(header);
for (i in emoji_array) {
var emoji = emoji_array[i];
console.log(emoji.vendor_name + " " + emoji.glyph_score);
var glyph_bar = $("<div>");
glyph_bar.addClass("crisp");
glyph_bar.css("width", Math.abs(emoji.glyph_score) * barWidth/100);
glyph_bar.css("height", 36);
glyph_bar.css("background-image", 'url(' + image_prefix + emoji.unicode_value + "_" + emoji.vendor_name + ".png)");
glyph_bar.css("background-repeat", "repeat-x");
glyph_bar.css("background-size", "36px 36px");
var glyph_row = $("<tr>");
glyph_row.addClass("glyph_row");
var negative_column = $("<td>");
if (emoji.glyph_score < 0) {
glyph_bar.addClass("negative_bar");
negative_column.append(glyph_bar);
}
glyph_row.append(negative_column);
glyph_row.append($("<td style=\"text-align: center;\">").text(emoji.vendor_name));
var positive_column = $("<td>");
if (emoji.glyph_score > 0) {
positive_column.append(glyph_bar);
}
glyph_row.append(positive_column);
$("#glyph_rows").append(glyph_row);
}
}