-
Notifications
You must be signed in to change notification settings - Fork 86
/
menu.bemhtml.js
57 lines (51 loc) · 1.88 KB
/
menu.bemhtml.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
block('menu')(
def()(function() {
var ctx = this.ctx,
mods = this.mods,
firstItem,
checkedItems = [];
if(ctx.content) {
var isValDef = typeof ctx.val !== 'undefined',
containsVal = function(val) {
return isValDef &&
(mods.mode === 'check'?
ctx.val.indexOf(val) > -1 :
ctx.val === val);
},
iterateItems = function(content) {
var i = 0, itemOrGroup;
while(itemOrGroup = content[i++]) {
if(itemOrGroup.block === 'menu-item') {
firstItem || (firstItem = itemOrGroup);
if(containsVal(itemOrGroup.val)) {
(itemOrGroup.mods = itemOrGroup.mods || {}).checked = true;
checkedItems.push(itemOrGroup);
}
} else if(itemOrGroup.content) { // menu__group
iterateItems(itemOrGroup.content);
}
}
};
if(!Array.isArray(ctx.content)) throw Error('menu: content must be an array of the menu items');
iterateItems(ctx.content);
}
return applyNext({
_firstItem : firstItem,
_checkedItems : checkedItems,
_menuMods : mods
});
}),
attrs()(function() {
var attrs = { role : 'menu' };
this.mods.disabled?
attrs['aria-disabled'] = 'true' :
attrs.tabindex = 0;
return attrs;
}),
js()(true),
mix()({ elem : 'control' }),
mod('disabled', true)
.js()(function() {
return this.extend(applyNext(), { tabIndex : 0 });
})
);