e619a3b0
Luigi Serra
Controllet cross ...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-menu-behavior/iron-menu-behavior.html">
<link rel="import" href="../iron-behaviors/iron-control-state.html">
<link rel="import" href="../iron-collapse/iron-collapse.html">
|
a1a3bc73
Luigi Serra
graphs updates
|
15
16
17
18
|
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-styles/default-theme.html">
<link rel="import" href="../paper-styles/color.html">
<link rel="import" href="paper-menu-shared-styles.html">
|
e619a3b0
Luigi Serra
Controllet cross ...
|
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
|
<!--
`<paper-submenu>` is a nested menu inside of a parent `<paper-menu>`. It
consists of a trigger that expands or collapses another `<paper-menu>`:
<paper-menu>
<paper-submenu>
<paper-item class="menu-trigger">Topics</paper-item>
<paper-menu class="menu-content">
<paper-item>Topic 1</paper-item>
<paper-item>Topic 2</paper-item>
<paper-item>Topic 3</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu>
<paper-item class="menu-trigger">Faves</paper-item>
<paper-menu class="menu-content">
<paper-item>Fave 1</paper-item>
<paper-item>Fave 2</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu disabled>
<paper-item class="menu-trigger">Unavailable</paper-item>
<paper-menu class="menu-content">
<paper-item>Disabled 1</paper-item>
<paper-item>Disabled 2</paper-item>
</paper-menu>
</paper-submenu>
</paper-menu>
Just like in `<paper-menu>`, the focused item is highlighted, and the selected
item has bolded text. Please see the `<paper-menu>` docs for which attributes
(such as `multi` and `selected`), and styling options are available for the
`menu-content` menu.
@group Paper Elements
@element paper-submenu
@hero hero.svg
@demo demo/index.html
-->
<dom-module id="paper-submenu">
|
e619a3b0
Luigi Serra
Controllet cross ...
|
61
|
<template>
|
a1a3bc73
Luigi Serra
graphs updates
|
62
63
|
<style include="paper-menu-shared-styles"></style>
|
e619a3b0
Luigi Serra
Controllet cross ...
|
64
65
66
67
|
<div class="selectable-content" on-tap="_onTap">
<content id="trigger" select=".menu-trigger"></content>
</div>
<iron-collapse id="collapse" opened="{{opened}}">
|
a1a3bc73
Luigi Serra
graphs updates
|
68
|
<content id="content" select=".menu-content"></content>
|
e619a3b0
Luigi Serra
Controllet cross ...
|
69
70
71
|
</iron-collapse>
</template>
|
a1a3bc73
Luigi Serra
graphs updates
|
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
103
104
|
<script>
(function() {
Polymer({
is: 'paper-submenu',
properties: {
/**
* Fired when the submenu is opened.
*
* @event paper-submenu-open
*/
/**
* Fired when the submenu is closed.
*
* @event paper-submenu-close
*/
/**
* Set opened to true to show the collapse element and to false to hide it.
*
* @attribute opened
*/
opened: {
type: Boolean,
value: false,
notify: true,
observer: '_openedChanged'
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
105
|
|
a1a3bc73
Luigi Serra
graphs updates
|
106
107
108
|
behaviors: [
Polymer.IronControlState
],
|
e619a3b0
Luigi Serra
Controllet cross ...
|
109
|
|
a1a3bc73
Luigi Serra
graphs updates
|
110
111
112
|
listeners: {
'focus': '_onFocus'
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
113
|
|
a1a3bc73
Luigi Serra
graphs updates
|
114
115
116
|
get __parent() {
return Polymer.dom(this).parentNode;
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
117
|
|
a1a3bc73
Luigi Serra
graphs updates
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
get __trigger() {
return Polymer.dom(this.$.trigger).getDistributedNodes()[0];
},
get __content() {
return Polymer.dom(this.$.content).getDistributedNodes()[0];
},
attached: function() {
this.listen(this.__parent, 'iron-activate', '_onParentIronActivate');
},
dettached: function() {
this.unlisten(this.__parent, 'iron-activate', '_onParentIronActivate');
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
133
|
|
e619a3b0
Luigi Serra
Controllet cross ...
|
134
|
/**
|
a1a3bc73
Luigi Serra
graphs updates
|
135
|
* Expand the submenu content.
|
e619a3b0
Luigi Serra
Controllet cross ...
|
136
|
*/
|
a1a3bc73
Luigi Serra
graphs updates
|
137
138
139
140
141
142
143
144
|
open: function() {
if (!this.disabled && !this._active) {
this.$.collapse.show();
this._active = true;
this.__trigger && this.__trigger.classList.add('iron-selected');
this.__content && this.__content.focus();
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
145
146
|
/**
|
a1a3bc73
Luigi Serra
graphs updates
|
147
|
* Collapse the submenu content.
|
e619a3b0
Luigi Serra
Controllet cross ...
|
148
|
*/
|
a1a3bc73
Luigi Serra
graphs updates
|
149
150
151
152
153
154
155
|
close: function() {
if (this._active) {
this.$.collapse.hide();
this._active = false;
this.__trigger && this.__trigger.classList.remove('iron-selected');
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
156
157
|
/**
|
a1a3bc73
Luigi Serra
graphs updates
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
* Toggle the submenu.
*/
toggle: function() {
if (this._active) {
this.close();
} else {
this.open();
}
},
/**
* A handler that is called when the trigger is tapped.
*/
_onTap: function(e) {
if (!this.disabled) {
this.toggle();
}
},
/**
* Toggles the submenu content when the trigger is tapped.
*/
_openedChanged: function(opened, oldOpened) {
if (opened) {
this.fire('paper-submenu-open');
} else if (oldOpened != null) {
this.fire('paper-submenu-close');
}
},
/**
* A handler that is called when `iron-activate` is fired.
|
e619a3b0
Luigi Serra
Controllet cross ...
|
190
|
*
|
a1a3bc73
Luigi Serra
graphs updates
|
191
|
* @param {CustomEvent} event An `iron-activate` event.
|
e619a3b0
Luigi Serra
Controllet cross ...
|
192
|
*/
|
a1a3bc73
Luigi Serra
graphs updates
|
193
194
195
196
197
198
199
200
201
202
203
|
_onParentIronActivate: function(event) {
var parent = this.__parent;
if (Polymer.dom(event).localTarget === parent) {
// The activated item can either be this submenu, in which case it
// should be expanded, or any of the other sibling submenus, in which
// case this submenu should be collapsed.
if (event.detail.item !== this && !parent.multi) {
this.close();
}
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
204
|
|
a1a3bc73
Luigi Serra
graphs updates
|
205
206
207
208
209
210
211
212
213
214
215
216
|
/**
* If the dropdown is open when disabled becomes true, close the
* dropdown.
*
* @param {boolean} disabled True if disabled, otherwise false.
*/
_disabledChanged: function(disabled) {
Polymer.IronControlState._disabledChanged.apply(this, arguments);
if (disabled && this._active) {
this.close();
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
217
|
|
a1a3bc73
Luigi Serra
graphs updates
|
218
219
220
221
222
223
224
|
/**
* Handler that is called when the menu receives focus.
*
* @param {FocusEvent} event A focus event.
*/
_onFocus: function(event) {
this.__trigger && this.__trigger.focus();
|
e619a3b0
Luigi Serra
Controllet cross ...
|
225
|
}
|
e619a3b0
Luigi Serra
Controllet cross ...
|
226
|
|
a1a3bc73
Luigi Serra
graphs updates
|
227
|
});
|
e619a3b0
Luigi Serra
Controllet cross ...
|
228
|
|
a1a3bc73
Luigi Serra
graphs updates
|
229
|
})();
|
e619a3b0
Luigi Serra
Controllet cross ...
|
230
|
</script>
|
a1a3bc73
Luigi Serra
graphs updates
|
231
|
</dom-module>
|