-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-avatar-behavior.html
68 lines (51 loc) · 1.67 KB
/
paper-avatar-behavior.html
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
<link rel="import" href="../iron-image/iron-image.html">
<script src="../js-md5/build/md5.min.js"></script>
<script>
AvatarBehavior = {
properties: {
colors: {
type: Array,
value: ['#FFA726', '#FF7043', '#26A69A', '#26C6DA', '#5C6BC0', '#7E57C2', '#AB47BC', '#66BB6A']
},
userName: {
type: String,
value: 'Average Joe',
observer: '_updateBg',
},
userId: {
type: String,
observer: '_updateBg',
},
image: {
type: String,
observer: '_updateBg',
},
color: {
type: String,
readOnly: true,
notify: true,
},
initial: {
type: String,
},
_imageVisible: {
type: Boolean,
}
},
_updateBg: function() {
if(this.image !== void(0)) {
// Hide placeholder in favor of user picture
this._imageVisible = true;
} else {
// Calculate hash from userId
var hash = md5.array('' + this.userId)[0];
// Save color to variable and set the initial character
this._setColor(this.colors[hash % this.colors.length]);
this.initial = this.userName.charAt(0).toUpperCase();
this.colorChanged(this.color);
// Hide user picture in favor of placeholder
this._imageVisible = false;
}
}
};
</script>