summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/new_sidebar.js
blob: ccf45fd7c9791ff09fcb2f15c5ec24b6db1bfeaa (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
export default class NewNavSidebar {
  constructor() {
    this.initDomElements();
    this.bindEvents();
  }

  initDomElements() {
    this.$sidebar = $('.nav-sidebar');
    this.$overlay = $('.mobile-overlay');
    this.$openSidebar = $('.toggle-mobile-nav');
    this.$closeSidebar = $('.close-nav-button');
  }

  bindEvents() {
    this.$openSidebar.on('click', e => this.toggleSidebarNav(e, true));
    this.$closeSidebar.on('click', e => this.toggleSidebarNav(e, false));
    this.$overlay.on('click', e => this.toggleSidebarNav(e, false));
  }

  toggleSidebarNav(show) {
    this.$sidebar.toggleClass('nav-sidebar-expanded', show);
    this.$overlay.toggleClass('mobile-nav-open', show);
  }
}