summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/content/components/login-intro.mjs
blob: 682ddb32d8c726a10e1e13b898b3d5e63f925ff8 (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
/* 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/. */

export default class LoginIntro extends HTMLElement {
  connectedCallback() {
    if (this.shadowRoot) {
      return;
    }

    let loginIntroTemplate = document.querySelector("#login-intro-template");
    let shadowRoot = this.attachShadow({ mode: "open" });
    document.l10n.connectRoot(shadowRoot);
    shadowRoot.appendChild(loginIntroTemplate.content.cloneNode(true));
  }

  focus() {
    let helpLink = this.shadowRoot.querySelector(".intro-help-link");
    helpLink.focus();
  }

  handleEvent(event) {
    if (
      event.currentTarget.classList.contains("intro-import-text") &&
      event.target.localName == "a"
    ) {
      let eventName =
        event.target.dataset.l10nName == "import-file-link"
          ? "AboutLoginsImportFromFile"
          : "AboutLoginsImportFromBrowser";
      document.dispatchEvent(
        new CustomEvent(eventName, {
          bubbles: true,
        })
      );
    }
    event.preventDefault();
  }

  updateState(syncState) {
    let l10nId = syncState.loggedIn
      ? "about-logins-login-intro-heading-logged-in"
      : "about-logins-login-intro-heading-logged-out2";
    document.l10n.setAttributes(
      this.shadowRoot.querySelector(".heading"),
      l10nId
    );

    this.shadowRoot
      .querySelector(".illustration")
      .classList.toggle("logged-in", syncState.loggedIn);
    let supportURL =
      window.AboutLoginsUtils.supportBaseURL +
      "password-manager-remember-delete-edit-logins";
    this.shadowRoot
      .querySelector(".intro-help-link")
      .setAttribute("href", supportURL);

    let importClass = window.AboutLoginsUtils.fileImportEnabled
      ? ".intro-import-text.file-import"
      : ".intro-import-text.no-file-import";
    let importText = this.shadowRoot.querySelector(importClass);
    importText.addEventListener("click", this);
    importText.hidden = !window.AboutLoginsUtils.importVisible;
  }
}
customElements.define("login-intro", LoginIntro);