| OLD | NEW |
| 1 (function() { | 1 (function() { |
| 2 'use strict'; | 2 'use strict'; |
| 3 | 3 |
| 4 var PaperMenuButton = Polymer({ | 4 var PaperMenuButton = Polymer({ |
| 5 is: 'paper-menu-button', | 5 is: 'paper-menu-button', |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Fired when the dropdown opens. | 8 * Fired when the dropdown opens. |
| 9 * | 9 * |
| 10 * @event paper-dropdown-open | 10 * @event paper-dropdown-open |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Fired when the dropdown closes. | 14 * Fired when the dropdown closes. |
| 15 * | 15 * |
| 16 * @event paper-dropdown-close | 16 * @event paper-dropdown-close |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 behaviors: [ | 19 behaviors: [ |
| 20 Polymer.IronA11yKeysBehavior, | 20 Polymer.IronA11yKeysBehavior, |
| 21 Polymer.IronControlState | 21 Polymer.IronControlState |
| 22 ], | 22 ], |
| 23 | 23 |
| 24 properties: { | 24 properties: { |
| 25 | 25 /** |
| 26 /** | 26 * True if the content is currently displayed. |
| 27 * True if the content is currently displayed. | 27 */ |
| 28 */ | 28 opened: { |
| 29 opened: { | 29 type: Boolean, |
| 30 type: Boolean, | 30 value: false, |
| 31 value: false, | 31 notify: true, |
| 32 notify: true, | 32 observer: '_openedChanged' |
| 33 observer: '_openedChanged' | 33 }, |
| 34 }, | 34 |
| 35 | 35 /** |
| 36 /** | 36 * The orientation against which to align the menu dropdown |
| 37 * The orientation against which to align the menu dropdown | 37 * horizontally relative to the dropdown trigger. |
| 38 * horizontally relative to the dropdown trigger. | 38 */ |
| 39 */ | 39 horizontalAlign: { |
| 40 horizontalAlign: { | 40 type: String, |
| 41 type: String, | 41 value: 'left', |
| 42 value: 'left', | 42 reflectToAttribute: true |
| 43 reflectToAttribute: true | 43 }, |
| 44 }, | 44 |
| 45 | 45 /** |
| 46 /** | 46 * The orientation against which to align the menu dropdown |
| 47 * The orientation against which to align the menu dropdown | 47 * vertically relative to the dropdown trigger. |
| 48 * vertically relative to the dropdown trigger. | 48 */ |
| 49 */ | 49 verticalAlign: { |
| 50 verticalAlign: { | 50 type: String, |
| 51 type: String, | 51 value: 'top', |
| 52 value: 'top', | 52 reflectToAttribute: true |
| 53 reflectToAttribute: true | 53 }, |
| 54 }, | 54 |
| 55 | 55 /** |
| 56 /** | 56 * A pixel value that will be added to the position calculated for the |
| 57 * A pixel value that will be added to the position calculated for the | 57 * given `horizontalAlign`. Use a negative value to offset to the |
| 58 * given `horizontalAlign`. Use a negative value to offset to the | 58 * left, or a positive value to offset to the right. |
| 59 * left, or a positive value to offset to the right. | 59 */ |
| 60 */ | 60 horizontalOffset: { |
| 61 horizontalOffset: { | 61 type: Number, |
| 62 type: Number, | 62 value: 0, |
| 63 value: 0, | 63 notify: true |
| 64 notify: true | 64 }, |
| 65 }, | 65 |
| 66 | 66 /** |
| 67 /** | 67 * A pixel value that will be added to the position calculated for the |
| 68 * A pixel value that will be added to the position calculated for the | 68 * given `verticalAlign`. Use a negative value to offset towards the |
| 69 * given `verticalAlign`. Use a negative value to offset towards the | 69 * top, or a positive value to offset towards the bottom. |
| 70 * top, or a positive value to offset towards the bottom. | 70 */ |
| 71 */ | 71 verticalOffset: { |
| 72 verticalOffset: { | 72 type: Number, |
| 73 type: Number, | 73 value: 0, |
| 74 value: 0, | 74 notify: true |
| 75 notify: true | 75 }, |
| 76 }, | 76 |
| 77 | 77 /** |
| 78 /** | 78 * Set to true to disable animations when opening and closing the |
| 79 * Set to true to disable animations when opening and closing the | 79 * dropdown. |
| 80 */ |
| 81 noAnimations: { |
| 82 type: Boolean, |
| 83 value: false |
| 84 }, |
| 85 |
| 86 /** |
| 87 * Set to true to disable automatically closing the dropdown after |
| 88 * a selection has been made. |
| 89 */ |
| 90 ignoreSelect: { |
| 91 type: Boolean, |
| 92 value: false |
| 93 }, |
| 94 |
| 95 /** |
| 96 * An animation config. If provided, this will be used to animate the |
| 97 * opening of the dropdown. |
| 98 */ |
| 99 openAnimationConfig: { |
| 100 type: Object, |
| 101 value: function() { |
| 102 return [{ |
| 103 name: 'fade-in-animation', |
| 104 timing: { |
| 105 delay: 100, |
| 106 duration: 200 |
| 107 } |
| 108 }, { |
| 109 name: 'paper-menu-grow-width-animation', |
| 110 timing: { |
| 111 delay: 100, |
| 112 duration: 150, |
| 113 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER |
| 114 } |
| 115 }, { |
| 116 name: 'paper-menu-grow-height-animation', |
| 117 timing: { |
| 118 delay: 100, |
| 119 duration: 275, |
| 120 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER |
| 121 } |
| 122 }]; |
| 123 } |
| 124 }, |
| 125 |
| 126 /** |
| 127 * An animation config. If provided, this will be used to animate the |
| 128 * closing of the dropdown. |
| 129 */ |
| 130 closeAnimationConfig: { |
| 131 type: Object, |
| 132 value: function() { |
| 133 return [{ |
| 134 name: 'fade-out-animation', |
| 135 timing: { |
| 136 duration: 150 |
| 137 } |
| 138 }, { |
| 139 name: 'paper-menu-shrink-width-animation', |
| 140 timing: { |
| 141 delay: 100, |
| 142 duration: 50, |
| 143 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER |
| 144 } |
| 145 }, { |
| 146 name: 'paper-menu-shrink-height-animation', |
| 147 timing: { |
| 148 duration: 200, |
| 149 easing: 'ease-in' |
| 150 } |
| 151 }]; |
| 152 } |
| 153 }, |
| 154 |
| 155 /** |
| 156 * This is the element intended to be bound as the focus target |
| 157 * for the `iron-dropdown` contained by `paper-menu-button`. |
| 158 */ |
| 159 _dropdownContent: { |
| 160 type: Object |
| 161 } |
| 162 }, |
| 163 |
| 164 hostAttributes: { |
| 165 role: 'group', |
| 166 'aria-haspopup': 'true' |
| 167 }, |
| 168 |
| 169 listeners: { |
| 170 'iron-select': '_onIronSelect' |
| 171 }, |
| 172 |
| 173 /** |
| 174 * The content element that is contained by the menu button, if any. |
| 175 */ |
| 176 get contentElement() { |
| 177 return Polymer.dom(this.$.content).getDistributedNodes()[0]; |
| 178 }, |
| 179 |
| 180 /** |
| 181 * Toggles the drowpdown content between opened and closed. |
| 182 */ |
| 183 toggle: function() { |
| 184 if (this.opened) { |
| 185 this.close(); |
| 186 } else { |
| 187 this.open(); |
| 188 } |
| 189 }, |
| 190 |
| 191 /** |
| 192 * Make the dropdown content appear as an overlay positioned relative |
| 193 * to the dropdown trigger. |
| 194 */ |
| 195 open: function() { |
| 196 if (this.disabled) { |
| 197 return; |
| 198 } |
| 199 |
| 200 this.$.dropdown.open(); |
| 201 }, |
| 202 |
| 203 /** |
| 204 * Hide the dropdown content. |
| 205 */ |
| 206 close: function() { |
| 207 this.$.dropdown.close(); |
| 208 }, |
| 209 |
| 210 /** |
| 211 * When an `iron-select` event is received, the dropdown should |
| 212 * automatically close on the assumption that a value has been chosen. |
| 213 * |
| 214 * @param {CustomEvent} event A CustomEvent instance with type |
| 215 * set to `"iron-select"`. |
| 216 */ |
| 217 _onIronSelect: function(event) { |
| 218 if (!this.ignoreSelect) { |
| 219 this.close(); |
| 220 } |
| 221 }, |
| 222 |
| 223 /** |
| 224 * When the dropdown opens, the `paper-menu-button` fires `paper-open`. |
| 225 * When the dropdown closes, the `paper-menu-button` fires `paper-close`
. |
| 226 * |
| 227 * @param {boolean} opened True if the dropdown is opened, otherwise fal
se. |
| 228 * @param {boolean} oldOpened The previous value of `opened`. |
| 229 */ |
| 230 _openedChanged: function(opened, oldOpened) { |
| 231 if (opened) { |
| 232 // TODO(cdata): Update this when we can measure changes in distribut
ed |
| 233 // children in an idiomatic way. |
| 234 // We poke this property in case the element has changed. This will |
| 235 // cause the focus target for the `iron-dropdown` to be updated as |
| 236 // necessary: |
| 237 this._dropdownContent = this.contentElement; |
| 238 this.fire('paper-dropdown-open'); |
| 239 } else if (oldOpened != null) { |
| 240 this.fire('paper-dropdown-close'); |
| 241 } |
| 242 }, |
| 243 |
| 244 /** |
| 245 * If the dropdown is open when disabled becomes true, close the |
| 80 * dropdown. | 246 * dropdown. |
| 81 */ | 247 * |
| 82 noAnimations: { | 248 * @param {boolean} disabled True if disabled, otherwise false. |
| 83 type: Boolean, | 249 */ |
| 84 value: false | 250 _disabledChanged: function(disabled) { |
| 85 }, | 251 Polymer.IronControlState._disabledChanged.apply(this, arguments); |
| 86 | 252 if (disabled && this.opened) { |
| 87 /** | 253 this.close(); |
| 88 * Set to true to disable automatically closing the dropdown after | 254 } |
| 89 * a selection has been made. | 255 }, |
| 90 */ | 256 |
| 91 ignoreSelect: { | 257 __onIronOverlayCanceled: function(event) { |
| 92 type: Boolean, | 258 var uiEvent = event.detail; |
| 93 value: false | 259 var target = Polymer.dom(uiEvent).rootTarget; |
| 94 }, | 260 var trigger = this.$.trigger; |
| 95 | 261 var path = Polymer.dom(uiEvent).path; |
| 96 /** | 262 |
| 97 * An animation config. If provided, this will be used to animate the | 263 if (path.indexOf(trigger) > -1) { |
| 98 * opening of the dropdown. | 264 event.preventDefault(); |
| 99 */ | 265 } |
| 100 openAnimationConfig: { | |
| 101 type: Object, | |
| 102 value: function() { | |
| 103 return [{ | |
| 104 name: 'fade-in-animation', | |
| 105 timing: { | |
| 106 delay: 100, | |
| 107 duration: 200 | |
| 108 } | |
| 109 }, { | |
| 110 name: 'paper-menu-grow-width-animation', | |
| 111 timing: { | |
| 112 delay: 100, | |
| 113 duration: 150, | |
| 114 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER | |
| 115 } | |
| 116 }, { | |
| 117 name: 'paper-menu-grow-height-animation', | |
| 118 timing: { | |
| 119 delay: 100, | |
| 120 duration: 275, | |
| 121 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER | |
| 122 } | |
| 123 }]; | |
| 124 } | |
| 125 }, | |
| 126 | |
| 127 /** | |
| 128 * An animation config. If provided, this will be used to animate the | |
| 129 * closing of the dropdown. | |
| 130 */ | |
| 131 closeAnimationConfig: { | |
| 132 type: Object, | |
| 133 value: function() { | |
| 134 return [{ | |
| 135 name: 'fade-out-animation', | |
| 136 timing: { | |
| 137 duration: 150 | |
| 138 } | |
| 139 }, { | |
| 140 name: 'paper-menu-shrink-width-animation', | |
| 141 timing: { | |
| 142 delay: 100, | |
| 143 duration: 50, | |
| 144 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER | |
| 145 } | |
| 146 }, { | |
| 147 name: 'paper-menu-shrink-height-animation', | |
| 148 timing: { | |
| 149 duration: 200, | |
| 150 easing: 'ease-in' | |
| 151 } | |
| 152 }]; | |
| 153 } | |
| 154 }, | |
| 155 | |
| 156 /** | |
| 157 * This is the element intended to be bound as the focus target | |
| 158 * for the `iron-dropdown` contained by `paper-menu-button`. | |
| 159 */ | |
| 160 _dropdownContent: { | |
| 161 type: Object | |
| 162 } | 266 } |
| 163 }, | 267 }); |
| 164 | 268 |
| 165 hostAttributes: { | 269 PaperMenuButton.ANIMATION_CUBIC_BEZIER = 'cubic-bezier(.3,.95,.5,1)'; |
| 166 role: 'group', | 270 PaperMenuButton.MAX_ANIMATION_TIME_MS = 400; |
| 167 'aria-haspopup': 'true' | 271 |
| 168 }, | 272 Polymer.PaperMenuButton = PaperMenuButton; |
| 169 | 273 })(); |
| 170 listeners: { | |
| 171 'iron-select': '_onIronSelect' | |
| 172 }, | |
| 173 | |
| 174 /** | |
| 175 * The content element that is contained by the menu button, if any. | |
| 176 */ | |
| 177 get contentElement() { | |
| 178 return Polymer.dom(this.$.content).getDistributedNodes()[0]; | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * Make the dropdown content appear as an overlay positioned relative | |
| 183 * to the dropdown trigger. | |
| 184 */ | |
| 185 open: function() { | |
| 186 if (this.disabled) { | |
| 187 return; | |
| 188 } | |
| 189 | |
| 190 this.$.dropdown.open(); | |
| 191 }, | |
| 192 | |
| 193 /** | |
| 194 * Hide the dropdown content. | |
| 195 */ | |
| 196 close: function() { | |
| 197 this.$.dropdown.close(); | |
| 198 }, | |
| 199 | |
| 200 /** | |
| 201 * When an `iron-select` event is received, the dropdown should | |
| 202 * automatically close on the assumption that a value has been chosen. | |
| 203 * | |
| 204 * @param {CustomEvent} event A CustomEvent instance with type | |
| 205 * set to `"iron-select"`. | |
| 206 */ | |
| 207 _onIronSelect: function(event) { | |
| 208 if (!this.ignoreSelect) { | |
| 209 this.close(); | |
| 210 } | |
| 211 }, | |
| 212 | |
| 213 /** | |
| 214 * When the dropdown opens, the `paper-menu-button` fires `paper-open`. | |
| 215 * When the dropdown closes, the `paper-menu-button` fires `paper-close`. | |
| 216 * | |
| 217 * @param {boolean} opened True if the dropdown is opened, otherwise false
. | |
| 218 * @param {boolean} oldOpened The previous value of `opened`. | |
| 219 */ | |
| 220 _openedChanged: function(opened, oldOpened) { | |
| 221 if (opened) { | |
| 222 // TODO(cdata): Update this when we can measure changes in distributed | |
| 223 // children in an idiomatic way. | |
| 224 // We poke this property in case the element has changed. This will | |
| 225 // cause the focus target for the `iron-dropdown` to be updated as | |
| 226 // necessary: | |
| 227 this._dropdownContent = this.contentElement; | |
| 228 this.fire('paper-dropdown-open'); | |
| 229 } else if (oldOpened != null) { | |
| 230 this.fire('paper-dropdown-close'); | |
| 231 } | |
| 232 }, | |
| 233 | |
| 234 /** | |
| 235 * If the dropdown is open when disabled becomes true, close the | |
| 236 * dropdown. | |
| 237 * | |
| 238 * @param {boolean} disabled True if disabled, otherwise false. | |
| 239 */ | |
| 240 _disabledChanged: function(disabled) { | |
| 241 Polymer.IronControlState._disabledChanged.apply(this, arguments); | |
| 242 if (disabled && this.opened) { | |
| 243 this.close(); | |
| 244 } | |
| 245 } | |
| 246 }); | |
| 247 | |
| 248 PaperMenuButton.ANIMATION_CUBIC_BEZIER = 'cubic-bezier(.3,.95,.5,1)'; | |
| 249 PaperMenuButton.MAX_ANIMATION_TIME_MS = 400; | |
| 250 | |
| 251 Polymer.PaperMenuButton = PaperMenuButton; | |
| 252 })(); | |
| OLD | NEW |