OLD | NEW |
1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 // found in the LICENSE file. |
4 */ | |
5 | 4 |
6 Polymer('gaia-button', { | 5 Polymer({ |
7 ready: function() { | 6 is: 'gaia-button', |
8 this.typeChanged(); | |
9 }, | |
10 | 7 |
11 onKeyDown: function(e) { | 8 properties: { |
12 if (!this.disabled && (e.keyCode == 13 || e.keyCode == 32)) { | 9 disabled: { |
13 this.fire('tap'); | 10 type: Boolean, |
14 this.fire('click'); | 11 value: false, |
15 e.stopPropagation(); | 12 reflectToAttribute: true |
| 13 }, |
| 14 |
| 15 type: { |
| 16 type: String, |
| 17 value: '', |
| 18 reflectToAttribute: true, |
| 19 observer: 'typeChanged_' |
16 } | 20 } |
17 }, | 21 }, |
18 | 22 |
19 onFocus: function() { | 23 focusedChanged_: function() { |
20 if (this.type == 'link' || this.type == 'dialog') | 24 if (this.type == 'link' || this.type == 'dialog') |
21 return; | 25 return; |
22 this.raised = true; | 26 this.$.button.raised = this.$.button.focused; |
23 }, | 27 }, |
24 | 28 |
25 onBlur: function() { | 29 typeChanged_: function() { |
26 if (this.type == 'link' || this.type == 'dialog') | 30 if (this.type == 'link') |
27 return; | 31 this.$.button.setAttribute('noink', ''); |
28 this.raised = false; | 32 else |
| 33 this.$.button.removeAttribute('noink'); |
29 }, | 34 }, |
30 | 35 |
31 typeChanged: function() { | 36 onClick_: function(e) { |
32 if (this.type == 'link') | 37 if (this.disabled) |
33 this.setAttribute('noink', ''); | 38 e.stopPropagation(); |
34 else | 39 } |
35 this.removeAttribute('noink'); | |
36 }, | |
37 }); | 40 }); |
38 | 41 |
39 Polymer('gaia-icon-button', { | 42 Polymer({ |
40 ready: function() { | 43 is: 'gaia-icon-button', |
41 this.classList.add('custom-appearance'); | 44 |
| 45 properties: { |
| 46 disabled: { |
| 47 type: Boolean, |
| 48 value: false, |
| 49 observer: 'disabledChanged_', |
| 50 reflectToAttribute: true |
| 51 }, |
| 52 |
| 53 icon: String, |
| 54 |
| 55 ariaLabel: String |
42 }, | 56 }, |
43 | 57 |
44 onMouseDown: function(e) { | 58 onClick_: function(e) { |
45 /* Prevents button focusing after mouse click. */ | 59 if (this.disabled) |
46 e.preventDefault(); | 60 e.stopPropagation(); |
| 61 }, |
| 62 |
| 63 disabledChanged_: function(disabled) { |
| 64 // TODO(dzhioev): remove after |
| 65 // https://github.com/PolymerElements/paper-icon-button/issues/20 is fixed. |
| 66 if (!disabled) { |
| 67 this.async(function() { |
| 68 this.$.iconButton.tabIndex = '0'; |
| 69 }); |
| 70 } |
47 } | 71 } |
48 }); | 72 }); |
| 73 |
OLD | NEW |