forked from ethereum/meteor-package-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identicon.js
90 lines (79 loc) · 1.76 KB
/
identicon.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
/**
Template Controllers
@module Templates
*/
/**
Return the user identity icon
@class [template] dapp_identicon
@constructor
*/
/**
The cached identicons
@property cache
*/
var cache = {};
Template["dapp_identicon"].helpers({
/**
Make sure the identity is lowercased
@method (identity)
*/
identity: function(identity) {
return _.isString(this.identity)
? this.identity.toLowerCase()
: this.identity;
},
/**
Return the cached or generated identicon
@method (identiconData)
*/
identiconData: function(identity) {
// remove items if the cache is larger than 50 entries
if (_.size(cache) > 100) {
delete cache[Object.keys(cache)[0]];
}
return (
cache["ID_" + identity] ||
(cache["ID_" + identity] = hqx(
hqx(
blockies.create({
seed: identity,
size: 8,
scale: 1
}),
4
),
4
).toDataURL())
);
},
/**
Return the cached or generated identicon
@method (identiconDataPixel)
*/
identiconDataPixel: function(identity) {
return (
cache["IDP_" + identity] ||
(cache["IDP_" + identity] = blockies
.create({
seed: identity,
size: 8,
scale: 8
})
.toDataURL())
);
},
/**
Get the correct text, if TAPi18n is available.
@method i18nText
*/
i18nTextIcon: function() {
if (
typeof TAPi18n === "undefined" ||
TAPi18n.__("elements.identiconHelper") == "elements.identiconHelper"
) {
return "This is a security icon, if there's any change on the address the resulting icon should be a completelly different one";
} else {
return TAPi18n.__("elements.identiconHelper");
}
}
});