blob: def96faf2729210a0288ac0ec15d9748b14ba6e1 (
plain)
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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* globals MozXULElement */
// Wrap in a block to prevent leaking to window scope.
{
/**
* The MozBadgebutton widget is used to display a chat toolbar button in
* the main Toolbox in the messenger window. It displays icon and label
* for the button. It also shows a badge on top of the chat icon with a number.
* That number is the count of unread messages in the chat.
*
* @augments MozToolbarbutton
*/
class MozBadgebutton extends customElements.get("toolbarbutton") {
static get inheritedAttributes() {
return {
".toolbarbutton-icon": "src=image",
".toolbarbutton-text": "value=label,accesskey,crop",
};
}
static get markup() {
return `
<stack>
<html:img class="toolbarbutton-icon" alt="" />
<html:span class="badgeButton-badge" hidden="hidden"></html:span>
</stack>
<label class="toolbarbutton-text" crop="end" flex="1"></label>
`;
}
/**
* toolbarbutton overwrites the fragment getter from MozXULElement.
*/
static get fragment() {
return Reflect.get(MozXULElement, "fragment", this);
}
connectedCallback() {
if (this.delayConnectedCallback() || this.hasChildNodes()) {
return;
}
this.setAttribute("is", "toolbarbutton-badge-button");
this.appendChild(this.constructor.fragment);
this._badgeCount = 0;
this.initializeAttributeInheritance();
}
set badgeCount(count) {
this._badgeCount = count;
let badge = this.querySelector(".badgeButton-badge");
badge.textContent = count;
badge.hidden = count == 0;
}
get badgeCount() {
return this._badgeCount;
}
}
customElements.define("toolbarbutton-badge-button", MozBadgebutton, {
extends: "toolbarbutton",
});
}
|