Sha256: 53a6bf4b2340aae821ffe4c6e623d68875325738ff36f930d9457aba0fec9f7b

Contents?: true

Size: 1.34 KB

Versions: 22

Compression:

Stored size: 1.34 KB

Contents

import { Controller } from "@hotwired/stimulus";
import { ConsentCategory } from "../consent";

export default class extends Controller {
  static targets = ["check"];
  declare checkTargets: HTMLInputElement[];

  connect(): void {
    this.checkTargets.forEach((input) => {
      input.checked =
        window.ui?.consent.permitted.includes(input.name as ConsentCategory) ||
        input.name === "essential";
    });
  }

  permitAll(event: Event): void {
    event.preventDefault();
    window.ui?.consent.permitAll();
    this.closeAll();
  }

  denyAll(event: Event): void {
    event.preventDefault();
    window.ui?.consent.denyAll();
    this.closeAll();
  }

  save(event: Event): void {
    event.preventDefault();
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    window.ui!.consent.permitted = this.checkTargets
      .filter((e) => e.checked)
      .map((e) => e.name) as ConsentCategory[];
    this.closeAll();
  }

  manage(event: Event): void {
    event.preventDefault();
    const div = document.body.querySelector(
      "#personalization-settings"
    ) as HTMLDivElement;
    if (!div) return;
    (this.element as HTMLElement).hidden = true;
    div.hidden = false;
  }

  closeAll(): void {
    document
      .querySelectorAll("[data-controller='consent']")
      .forEach((e: HTMLElement) => (e.hidden = true));
  }
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shimmer-0.0.41 src/controllers/consent.ts
shimmer-0.0.40 src/controllers/consent.ts
shimmer-0.0.39 src/controllers/consent.ts
shimmer-0.0.38 src/controllers/consent.ts
shimmer-0.0.37 src/controllers/consent.ts
shimmer-0.0.36 src/controllers/consent.ts
shimmer-0.0.35 src/controllers/consent.ts
shimmer-0.0.34 src/controllers/consent.ts
shimmer-0.0.33 src/controllers/consent.ts
shimmer-0.0.32 src/controllers/consent.ts
shimmer-0.0.31 src/controllers/consent.ts
shimmer-0.0.30 src/controllers/consent.ts
shimmer-0.0.29 src/controllers/consent.ts
shimmer-0.0.28 src/controllers/consent.ts
shimmer-0.0.27 src/controllers/consent.ts
shimmer-0.0.26 src/controllers/consent.ts
shimmer-0.0.25 src/controllers/consent.ts
shimmer-0.0.24 src/controllers/consent.ts
shimmer-0.0.23 src/controllers/consent.ts
shimmer-0.0.22 src/controllers/consent.ts