-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-unread.html
80 lines (75 loc) · 1.92 KB
/
show-unread.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
69
70
71
72
73
74
75
76
77
78
79
80
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="unread-badge.html">
<dom-module id="show-unread" class="empty">
<template>
<style>
:host(.empty) {
display: none !important;
}
:host {
display: inline-block;
}
a {
text-decoration: none;
color: #fff !important;
}
</style>
<iron-ajax
auto
url="/suggest/show-unread"
handle-as="json"
on-response="handleResponse"
on-error="handleError"
debounce-duration="300">
</iron-ajax>
<a id="profileLink" href=[[profileUrl]]>
<unread-badge id="badge" value="[[value]]"></unread-badge>
</a>
</template>
<script>
/**
* `show-unread`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class ShowUnread extends Polymer.Element {
static get is() { return 'show-unread'; }
static get properties() {
return {
profileUrl: {
type: String,
value: ''
},
value: {
type: String,
value: '',
observer: '_valueChanged'
}
};
}
handleResponse(e) {
this.value = e.detail.response.unread;
}
handleError(e) {
this.value = undefined;
}
_valueChanged(newValue, oldValue) {
this.value = newValue;
if (newValue) {
this.classList.remove("empty");
var title = "You have " + newValue + " unread private message";
if (newValue > 1) { title += "s"; }
this.$.profileLink.setAttribute("title", title);
} else {
this.classList.add("empty");
this.$.profileLink.removeAttribute("title");
}
}
}
window.customElements.define(ShowUnread.is, ShowUnread);
</script>
</dom-module>