1
|
|
|
"use strict"; |
2
|
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
3
|
|
|
const globals_1 = require("../globals/globals"); |
4
|
|
|
(function (root, factory) { |
5
|
|
|
if (typeof globals_1.define === 'function' && globals_1.define.amd) { |
6
|
|
|
globals_1.define([], factory); |
7
|
|
|
} |
8
|
|
|
else if (typeof module === 'object' && module.exports) { |
9
|
|
|
module.exports = factory(); |
10
|
|
|
} |
11
|
|
|
else { |
12
|
|
|
root.Accordion = factory(); |
13
|
|
|
} |
14
|
|
|
}(typeof self !== 'undefined' ? self : this, function () { |
|
|
|
|
15
|
|
|
class Accordion { |
16
|
|
|
constructor(options = {}) { |
17
|
|
|
this.options = options; |
18
|
|
|
this.options.el = typeof options.el === 'string' ? document.querySelectorAll(options.el) : options.el || document.querySelectorAll('.accordion'); |
19
|
|
|
this.onInit(); |
20
|
|
|
} |
21
|
|
|
onInit() { |
22
|
|
|
this.addClasses(); |
23
|
|
|
this.initToggleIcon(); |
24
|
|
|
this.toggleState(); |
25
|
|
|
} |
26
|
|
|
static closeAll(accordions) { |
27
|
|
|
accordions.forEach(function (accordion) { |
28
|
|
|
accordion.classList.remove('active'); |
29
|
|
|
}); |
30
|
|
|
} |
31
|
|
|
initToggleIcon() { |
32
|
|
|
let that = this; |
33
|
|
|
if (this.options.toggleIcon) { |
34
|
|
|
this.options.el.forEach(function (element) { |
35
|
|
|
let accordionToggler = document.createElement('div'); |
36
|
|
|
accordionToggler.classList.add('accordion-toggler__icon'); |
37
|
|
|
accordionToggler.innerHTML = that.options.toggleIcon; |
38
|
|
|
element.firstElementChild.appendChild(accordionToggler); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
addClasses() { |
43
|
|
|
this.options.el.forEach(function (element) { |
44
|
|
|
element.classList.add('accordion'); |
45
|
|
|
element.firstElementChild.classList.add('accordion-toggler'); |
46
|
|
|
element.firstElementChild.nextElementSibling.classList.add('accordion-collapse'); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
toggleState() { |
50
|
|
|
let that = this; |
51
|
|
|
that.options.el.forEach(function (element) { |
52
|
|
|
element.firstElementChild.addEventListener('click', function () { |
53
|
|
|
if (that.options.openOneCloseAll) { |
54
|
|
|
Accordion.closeAll(that.options.el); |
55
|
|
|
this.parentElement.classList.toggle('active'); |
56
|
|
|
} |
57
|
|
|
else { |
58
|
|
|
element.classList.toggle('active'); |
59
|
|
|
} |
60
|
|
|
}); |
61
|
|
|
}); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
return Accordion; |
65
|
|
|
})); |
66
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.