-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccordion.js
39 lines (32 loc) · 1.18 KB
/
accordion.js
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
S.accordion = {
load: function (options) {
let opts = {
container: '.accordion',
target: '.accordion > .title',
ontoggle: null,
opened: false,
};
if (options && options.container) { opts.container = options.container; }
if (options && options.target) { opts.target = options.target; }
if (options && options.ontoggle) { opts.ontoggle = options.ontoggle; }
if (options && options.opened) { opts.opened = options.opened; }
function open(e) {
if (typeof opts.ontoggle == 'function') {
opts.ontoggle(e, $(e.target).hasClass('expanded'), opts);
} else {
S.accordion.toggle(e, opts);
}
}
$(opts.target).off('click').on('click', open);
if (opts.opened == true) {
$(opts.target).each((i, e) => {
open({ target: $(e)[0] });
});
}
},
toggle: function (e, options) {
$(e.target).parents(options.container).first().toggleClass('expanded');
$(e.target).parents(options.target).first().toggleClass('expanded');
}
};
S.accordion.load();