summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/landing.js
blob: 8c0950ad5d5bd0bd60cee7499206db9e2371f804 (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
import Cookies from 'js-cookie';

class Landing {
  constructor(landingElement, dismissButton, cookieName) {
    this.landingElement = landingElement;
    this.cookieName = cookieName;
    this.dismissButton = dismissButton;
    this.eventWrapper = {};
  }

  toggle() {
    const isDismissed = this.isDismissed();

    this.landingElement.classList.toggle('hidden', isDismissed);
    if (!isDismissed) this.addEvents();
  }

  addEvents() {
    this.eventWrapper.dismissLanding = this.dismissLanding.bind(this);
    this.dismissButton.addEventListener('click', this.eventWrapper.dismissLanding);
  }

  removeEvents() {
    this.dismissButton.removeEventListener('click', this.eventWrapper.dismissLanding);
  }

  dismissLanding() {
    this.landingElement.classList.add('hidden');
    Cookies.set(this.cookieName, 'true', { expires: 365 });
  }

  isDismissed() {
    return Cookies.get(this.cookieName) === 'true';
  }
}

export default Landing;