forked from omsmith/navigation-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem-group.html
97 lines (95 loc) · 2.64 KB
/
item-group.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../d2l-dropdown/d2l-dropdown.html">
<link rel="import" href="../d2l-dropdown/d2l-dropdown-menu.html">
<link rel="import" href="../d2l-menu/d2l-menu.html">
<link rel="import" href="../d2l-menu/d2l-menu-item.html">
<link rel="import" href="../d2l-menu/d2l-menu-item-link.html">
<link rel="import" href="../d2l-icons/tier1-icons.html">
<link rel="import" href="../d2l-offscreen/d2l-offscreen-shared-styles.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="item-link-behavior.html">
<link rel="import" href="group-button.html">
<dom-module id="d2l-navigation-item-group">
<style include="d2l-navigation-shared-styles d2l-offscreen-shared-styles">
:host {
@apply(--d2l-navigation-item);
}
:host([hide]) {
@apply(--d2l-offscreen);
}
:host-context([dir='rtl']) {
@apply(--d2l-navigation-item-rtl);
}
</style>
<template>
<d2l-dropdown>
<button is="d2l-navigation-group" class="d2l-dropdown-opener" tabindex$="{{tabIndex}}">[[groupText]]</button>
<d2l-dropdown-menu>
<d2l-menu>
<template is="dom-repeat" items="{{links}}">
<template is="dom-if" if="{{isLink(item)}}">
<d2l-menu-item-link
text="[[getText(item)]]"
href="[[getHref(item)]]"></d2l-menu-item-link>
</template>
<template is="dom-if" if="{{!isLink(item)}}">
<d2l-menu-item
text="[[getText(item)]]"
item="[[item]]"
on-d2l-menu-item-select="_handleItemSelect"></d2l-menu-item>
</template>
</template>
</d2l-menu>
</d2l-dropdown-menu>
</d2l-dropdown>
</template>
</dom-module>
<script>
Polymer({
is: 'd2l-navigation-item-group',
behaviors: [window.D2L.PolymerBehaviors.Navigation.ItemLinkBehavior],
properties: {
item: Object,
groupText: {
type: String,
computed: '_computeGroupText(item)'
},
links: {
type: String,
computed: '_computeLinks(item)'
}
},
hostAttributes: {
role: 'listitem'
},
focus: function() {
this.$$('button').focus();
},
isFocused: function() {
return (document.activeElement === this.$$('button'));
},
_computeGroupText: function(item) {
if (item.properties.text) {
return item.properties.text;
}
return '';
},
_computeLinks: function(item) {
var links = [];
if (item.entities.length > 0) {
item.entities.forEach(function(entity) {
if (
(entity.class.indexOf('link') > -1) ||
(entity.class.indexOf('popup') > -1)
) {
links.push(entity);
}
});
}
return links;
},
_handleItemSelect: function(e) {
this._onPopupOrActionSelect(e.target.item);
}
});
</script>