| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 6 Code distributed by Google as part of the polymer project is also | |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 8 --> | |
| 9 <!-- | |
| 10 @module Polymer Core Elements | |
| 11 | |
| 12 `core-menu-button` is a `core-icon-button` that opens a drop-down menu | |
| 13 that allows the user to select an option. You can position the drop-down | |
| 14 menu with the `halign` and `valign` properties, or use CSS if more control | |
| 15 over positioning is desired. | |
| 16 | |
| 17 Example: | |
| 18 | |
| 19 <core-menu-button id="btn"> | |
| 20 <core-item icon="settings" label="Settings"></core-item> | |
| 21 <core-item icon="dialog" label="Dialog"></core-item> | |
| 22 <core-item icon="search" label="Search"></core-item> | |
| 23 </core-menu-button> | |
| 24 | |
| 25 Style the drop-down by using the `core-menu-button::shadow #dropdown` selector: | |
| 26 | |
| 27 /* position this drop-down below the button, and style it white on black. */ | |
| 28 #btn::shadow #dropdown { | |
| 29 top: 38px; | |
| 30 color: #fff; | |
| 31 background: #000; | |
| 32 } | |
| 33 | |
| 34 @class core-menu-button | |
| 35 @status beta | |
| 36 @homepage github.io | |
| 37 --> | |
| 38 | |
| 39 <!-- | |
| 40 Fired when an item's selection state is changed. This event is fired both | |
| 41 when an item is selected or deselected. The `isSelected` detail property | |
| 42 contains the selection state. | |
| 43 | |
| 44 @event core-select | |
| 45 @param {Object} detail | |
| 46 @param {boolean} detail.isSelected true for selection and false for deselectio
n | |
| 47 @param {Object} detail.item the item element | |
| 48 --> | |
| 49 <!-- | |
| 50 Fired when an item element is tapped. | |
| 51 | |
| 52 @event core-activate | |
| 53 @param {Object} detail | |
| 54 @param {Object} detail.item the item element | |
| 55 --> | |
| 56 <link href="../polymer/polymer.html" rel="import"> | |
| 57 <link href="../core-dropdown/core-dropdown.html" rel="import"> | |
| 58 <link href="../core-icon-button/core-icon-button.html" rel="import"> | |
| 59 <link href="../core-menu/core-menu.html" rel="import"> | |
| 60 | |
| 61 <polymer-element name="core-menu-button" attributes="icon label src selected ope
ned halign valign valueattr multi inlineMenu"> | |
| 62 <template> | |
| 63 <link rel="stylesheet" href="core-menu-button.css"> | |
| 64 <core-icon-button id="button" on-tap="{{toggle}}" src="{{src}}" icon="{{icon
}}" active="{{opened}}"><span>{{label}}</span></core-icon-button> | |
| 65 <core-dropdown id="dropdown" relatedTarget="{{$.button}}" opened="{{opened}}
" halign="{{halign}}" valign="{{valign}}"> | |
| 66 <core-menu | |
| 67 selected="{{selected}}" | |
| 68 valueattr="{{valueattr}}" | |
| 69 selectedClass="{{selectedClass}}" | |
| 70 selectedProperty="{{selectedProperty}}" | |
| 71 selectedAttribute="{{selectedAttribute}}" | |
| 72 selectedItem="{{selectedItem}}" | |
| 73 selectedModel="{{selectedModel}}" | |
| 74 selectedIndex="{{selectedIndex}}" | |
| 75 excludedLocalNames="{{excludedLocalNames}}" | |
| 76 on-core-activate="{{closeAction}}"> | |
| 77 <content select="*"></content> | |
| 78 </core-menu> | |
| 79 </core-dropdown> | |
| 80 </template> | |
| 81 <script> | |
| 82 Polymer('core-menu-button', { | |
| 83 | |
| 84 publish: { | |
| 85 | |
| 86 /** | |
| 87 * The icon to display. | |
| 88 * @attribute icon | |
| 89 * @type string | |
| 90 */ | |
| 91 icon: 'dots', | |
| 92 | |
| 93 src: '', | |
| 94 | |
| 95 /** | |
| 96 * Set to true to open the menu. | |
| 97 * @attribute opened | |
| 98 * @type boolean | |
| 99 */ | |
| 100 opened: false, | |
| 101 | |
| 102 /** | |
| 103 * Set to true to cause the menu popup to be displayed inline rather | |
| 104 * than in its own layer. | |
| 105 * @attribute inlineMenu | |
| 106 * @type boolean | |
| 107 */ | |
| 108 inlineMenu: false, | |
| 109 | |
| 110 /** | |
| 111 * Horizontally align the overlay with the button. | |
| 112 * @attribute halign | |
| 113 * @type string | |
| 114 */ | |
| 115 halign: 'left', | |
| 116 | |
| 117 /** | |
| 118 * Display the overlay on top or below the button. | |
| 119 * @attribute valign | |
| 120 * @type string | |
| 121 */ | |
| 122 valign: 'top', | |
| 123 | |
| 124 /** | |
| 125 * If true, the selection will persist when the menu is opened | |
| 126 * and closed multiple times. | |
| 127 * | |
| 128 * @attribute stickySelection | |
| 129 * @type boolean | |
| 130 * @default false | |
| 131 */ | |
| 132 stickySelection: false, | |
| 133 | |
| 134 /** | |
| 135 * The index of the selected menu item. | |
| 136 * @attribute selected | |
| 137 * @type number | |
| 138 */ | |
| 139 selected: '', | |
| 140 | |
| 141 /** | |
| 142 * Specifies the attribute to be used for "selected" attribute. | |
| 143 * | |
| 144 * @attribute valueattr | |
| 145 * @type string | |
| 146 * @default 'name' | |
| 147 */ | |
| 148 valueattr: 'name', | |
| 149 | |
| 150 /** | |
| 151 * Specifies the CSS class to be used to add to the selected element. | |
| 152 * | |
| 153 * @attribute selectedClass | |
| 154 * @type string | |
| 155 * @default 'core-selected' | |
| 156 */ | |
| 157 selectedClass: 'core-selected', | |
| 158 | |
| 159 /** | |
| 160 * Specifies the property to be used to set on the selected element | |
| 161 * to indicate its active state. | |
| 162 * | |
| 163 * @attribute selectedProperty | |
| 164 * @type string | |
| 165 * @default '' | |
| 166 */ | |
| 167 selectedProperty: '', | |
| 168 | |
| 169 /** | |
| 170 * Specifies the attribute to set on the selected element to indicate | |
| 171 * its active state. | |
| 172 * | |
| 173 * @attribute selectedAttribute | |
| 174 * @type string | |
| 175 * @default 'active' | |
| 176 */ | |
| 177 selectedAttribute: 'active', | |
| 178 | |
| 179 /** | |
| 180 * Returns the currently selected element. In multi-selection this retur
ns | |
| 181 * an array of selected elements. | |
| 182 * Note that you should not use this to set the selection. Instead use | |
| 183 * `selected`. | |
| 184 * | |
| 185 * @attribute selectedItem | |
| 186 * @type Object | |
| 187 * @default null | |
| 188 */ | |
| 189 selectedItem: null, | |
| 190 | |
| 191 /** | |
| 192 * In single selection, this returns the model associated with the | |
| 193 * selected element. | |
| 194 * Note that you should not use this to set the selection. Instead use | |
| 195 * `selected`. | |
| 196 * | |
| 197 * @attribute selectedModel | |
| 198 * @type Object | |
| 199 * @default null | |
| 200 */ | |
| 201 selectedModel: null, | |
| 202 | |
| 203 /** | |
| 204 * In single selection, this returns the selected index. | |
| 205 * Note that you should not use this to set the selection. Instead use | |
| 206 * `selected`. | |
| 207 * | |
| 208 * @attribute selectedIndex | |
| 209 * @type number | |
| 210 * @default -1 | |
| 211 */ | |
| 212 selectedIndex: -1, | |
| 213 | |
| 214 /** | |
| 215 * Nodes with local name that are in the list will not be included | |
| 216 * in the selection items. | |
| 217 * | |
| 218 * @attribute excludedLocalNames | |
| 219 * @type string | |
| 220 * @default '' | |
| 221 */ | |
| 222 excludedLocalNames: '' | |
| 223 | |
| 224 }, | |
| 225 | |
| 226 closeAction: function() { | |
| 227 this.opened = false; | |
| 228 }, | |
| 229 | |
| 230 /** | |
| 231 * Toggle the opened state of the dropdown. | |
| 232 * @method toggle | |
| 233 */ | |
| 234 toggle: function() { | |
| 235 this.opened = !this.opened; | |
| 236 }, | |
| 237 | |
| 238 /** | |
| 239 * The selected menu item. | |
| 240 * @property selection | |
| 241 * @type Node | |
| 242 */ | |
| 243 get selection() { | |
| 244 return this.$.menu.selection; | |
| 245 }, | |
| 246 | |
| 247 openedChanged: function() { | |
| 248 if (this.opened && !this.stickySelection) { | |
| 249 this.selected = null; | |
| 250 } | |
| 251 } | |
| 252 | |
| 253 }); | |
| 254 </script> | |
| 255 </polymer-element> | |
| OLD | NEW |