-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
foundation.util.nest.js
65 lines (55 loc) · 1.93 KB
/
foundation.util.nest.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import $ from 'jquery';
const Nest = {
Feather(menu, type = 'zf') {
menu.attr('role', 'menubar');
menu.find('a').attr({'role': 'menuitem'});
var items = menu.find('li').attr({'role': 'none'}),
subMenuClass = `is-${type}-submenu`,
subItemClass = `${subMenuClass}-item`,
hasSubClass = `is-${type}-submenu-parent`,
applyAria = (type !== 'accordion'); // Accordions handle their own ARIA attriutes.
items.each(function() {
var $item = $(this),
$sub = $item.children('ul');
if ($sub.length) {
$item.addClass(hasSubClass);
if(applyAria) {
$item.children('a:first').attr({
'aria-haspopup': true,
'aria-label': $item.children('a:first').text()
});
// Note: Drilldowns behave differently in how they hide, and so need
// additional attributes. We should look if this possibly over-generalized
// utility (Nest) is appropriate when we rework menus in 6.4
if(type === 'drilldown') {
$item.attr({'aria-expanded': false});
}
}
$sub
.addClass(`submenu ${subMenuClass}`)
.attr({
'data-submenu': '',
'role': 'menubar'
});
if(type === 'drilldown') {
$sub.attr({'aria-hidden': true});
}
}
if ($item.parent('[data-submenu]').length) {
$item.addClass(`is-submenu-item ${subItemClass}`);
}
});
return;
},
Burn(menu, type) {
var //items = menu.find('li'),
subMenuClass = `is-${type}-submenu`,
subItemClass = `${subMenuClass}-item`,
hasSubClass = `is-${type}-submenu-parent`;
menu
.find('>li, > li > ul, .menu, .menu > li, [data-submenu] > li')
.removeClass(`${subMenuClass} ${subItemClass} ${hasSubClass} is-submenu-item submenu is-active`)
.removeAttr('data-submenu').css('display', '');
}
}
export {Nest};