diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/components/im/content/toolbarbutton-badge-button.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mail/components/im/content/toolbarbutton-badge-button.js')
-rw-r--r-- | comm/mail/components/im/content/toolbarbutton-badge-button.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/comm/mail/components/im/content/toolbarbutton-badge-button.js b/comm/mail/components/im/content/toolbarbutton-badge-button.js new file mode 100644 index 0000000000..def96faf27 --- /dev/null +++ b/comm/mail/components/im/content/toolbarbutton-badge-button.js @@ -0,0 +1,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", + }); +} |