forked from Collaborne/paper-collapse-item
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper-collapse-group.html
102 lines (85 loc) · 1.96 KB
/
paper-collapse-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
98
99
100
101
102
<link rel="import" href="../polymer/polymer.html">
<!--
An element which is able to group a set of paper-collapse-items , where only one
item can be opened.
### Example
```html
<paper-collapse-group>
<paper-collapse-item icon="icons:favorite" header="Item 1" opened>
Only on item will be opened inside groups
</paper-collapse-item>
<paper-collapse-item icon="icons:info" header="Item 2">
Only on item will be opened inside groups
</paper-collapse-item>
<paper-collapse-item icon="icons:help" header="<b>Header <u>with</u> HTML</b>">
Only on item will be opened inside groups
</paper-collapse-item>
</paper-collapse-group>
```
@demo demo/index.html
-->
<dom-module id="paper-collapse-group">
<template>
<slot id="content"></slot>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'paper-collapse-group',
properties: {
/**
* Array of observed paper-collapse-items
*
* @type {Array}
*/
_items: {
type: Array,
notify: true,
value: []
}
},
listeners: {
'toggle': '_onToggle'
},
/**
* Setup content observer
*/
ready: function(){
this._observeItems();
},
/**
* Observe Items
*
* Setup an observer for newly added items
*/
_observeItems: function() {
Polymer.dom(this.$.content).observeNodes(function(info) {
var addedItems = info.addedNodes.filter(function(node) {
return node.nodeName.toLowerCase() === 'paper-collapse-item';
});
if (addedItems.length > 0) {
this._items = this._items.concat(addedItems);
this.fire('update');
}
}.bind(this));
},
/**
* On Toggle
*
* Listen to fired toggle events from items and update the groups
*
* @param {Event} e
*/
_onToggle: function(e){
this._items.forEach(function(item) {
// Force all other items (aside the one triggering the event) to
// get closed
if (item !== e.target && e.target.opened === true) {
item.opened = false;
}
});
}
});
})();
</script>