-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathenable-drawer.js
45 lines (40 loc) · 1.3 KB
/
enable-drawer.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
40
41
42
43
44
45
'use strict'
/*******************************************************************************
* enable-drawer.js - UI implementation of an ARIA based drawer.
*
* Written by Zoltan Hawryluk <[email protected]>
* Part of the Enable accessible component library.
* Version 1.0 released Dec. 29, 2021
*
* More information about this script available at:
* https://www.useragentman.com/enable/dropdown.php
*
* Released under the MIT License.
******************************************************************************/
const enableDrawer = new function() {
this.init = function() {
document.body.addEventListener("click", function(e) {
var target = e.target;
if (target.classList.contains('enable-drawer__button') && target.nodeName !== 'SUMMARY') {
if (target.getAttribute('aria-expanded') !== 'true') {
target.setAttribute('aria-expanded', 'true');
target.dispatchEvent(new CustomEvent(
'enable-expanded',
{
bubbles: true
}
));
} else {
target.setAttribute('aria-expanded', 'false');
target.dispatchEvent(new CustomEvent(
'enable-collapsed',
{
bubbles: true
}
));
}
}
});
}
}
export default enableDrawer;