Newer
Older
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
class MobileMenu {
static selector() {
return '.js-mobile-menu-toggle';
}
constructor(node, openCb = () => {}, closeCb = () => {}) {
this.node = node;
// Any callbacks to be called on open or close.
this.openCb = openCb;
this.closeCb = closeCb;
this.state = {
open: false,
};
this.bindEventListeners();
}
bindEventListeners() {
this.node.click(this.toggle.bind(this));
}
toggle() {
this.state.open ? this.close() : this.open();
}
open() {
this.node.addClass('is-open');
this.openCb();
this.state.open = true;
}
close() {
this.node.removeClass('is-open');
this.closeCb();
this.state.open = false;
}
}
export default MobileMenu;