summaryrefslogtreecommitdiffstats
path: root/comm/mail/base/content/widgets/statuspanel.js
blob: 8d30ea4697faab865f401c3c5cd63a519bf4b12f (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
71
72
73
74
75
76
77
78
/**
 * 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/. */

/* global MozXULElement */

// Wrap in a block to prevent leaking to window scope.
{
  class MozStatuspanel extends MozXULElement {
    static get observedAttributes() {
      return ["label", "mirror"];
    }

    connectedCallback() {
      const hbox = document.createXULElement("hbox");
      hbox.classList.add("statuspanel-inner");

      const label = document.createXULElement("label");
      label.classList.add("statuspanel-label");
      label.setAttribute("flex", "1");
      label.setAttribute("crop", "end");

      hbox.appendChild(label);
      this.appendChild(hbox);

      this._labelElement = label;

      this._updateAttributes();
      this._setupEventListeners();
    }

    attributeChangedCallback() {
      this._updateAttributes();
    }

    set label(val) {
      if (!this.label) {
        this.removeAttribute("mirror");
      }
      this.setAttribute("label", val);
    }

    get label() {
      return this.getAttribute("label");
    }

    _updateAttributes() {
      if (!this._labelElement) {
        return;
      }

      if (this.hasAttribute("label")) {
        this._labelElement.setAttribute("value", this.getAttribute("label"));
      } else {
        this._labelElement.removeAttribute("value");
      }

      if (this.hasAttribute("mirror")) {
        this._labelElement.setAttribute("mirror", this.getAttribute("mirror"));
      } else {
        this._labelElement.removeAttribute("mirror");
      }
    }

    _setupEventListeners() {
      this.addEventListener("mouseover", event => {
        if (this.hasAttribute("mirror")) {
          this.removeAttribute("mirror");
        } else {
          this.setAttribute("mirror", "true");
        }
      });
    }
  }

  customElements.define("statuspanel", MozStatuspanel);
}