| OLD | NEW |
| 1 | 1 /** |
| 2 | |
| 3 /** | |
| 4 * @demo demo/index.html | 2 * @demo demo/index.html |
| 5 * @polymerBehavior Polymer.IronButtonState | 3 * @polymerBehavior Polymer.IronButtonState |
| 6 */ | 4 */ |
| 7 Polymer.IronButtonStateImpl = { | 5 Polymer.IronButtonStateImpl = { |
| 8 | 6 |
| 9 properties: { | 7 properties: { |
| 10 | 8 |
| 11 /** | 9 /** |
| 12 * If true, the user is currently holding down the button. | 10 * If true, the user is currently holding down the button. |
| 13 */ | 11 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 29 reflectToAttribute: true | 27 reflectToAttribute: true |
| 30 }, | 28 }, |
| 31 | 29 |
| 32 /** | 30 /** |
| 33 * If true, the button is a toggle and is currently in the active state. | 31 * If true, the button is a toggle and is currently in the active state. |
| 34 */ | 32 */ |
| 35 active: { | 33 active: { |
| 36 type: Boolean, | 34 type: Boolean, |
| 37 value: false, | 35 value: false, |
| 38 notify: true, | 36 notify: true, |
| 39 reflectToAttribute: true, | 37 reflectToAttribute: true |
| 40 observer: '_activeChanged' | |
| 41 }, | 38 }, |
| 42 | 39 |
| 43 /** | 40 /** |
| 44 * True if the element is currently being pressed by a "pointer," which | 41 * True if the element is currently being pressed by a "pointer," which |
| 45 * is loosely defined as mouse or touch input (but specifically excluding | 42 * is loosely defined as mouse or touch input (but specifically excluding |
| 46 * keyboard input). | 43 * keyboard input). |
| 47 */ | 44 */ |
| 48 pointerDown: { | 45 pointerDown: { |
| 49 type: Boolean, | 46 type: Boolean, |
| 50 readOnly: true, | 47 readOnly: true, |
| 51 value: false | 48 value: false |
| 52 }, | 49 }, |
| 53 | 50 |
| 54 /** | 51 /** |
| 55 * True if the input device that caused the element to receive focus | 52 * True if the input device that caused the element to receive focus |
| 56 * was a keyboard. | 53 * was a keyboard. |
| 57 */ | 54 */ |
| 58 receivedFocusFromKeyboard: { | 55 receivedFocusFromKeyboard: { |
| 59 type: Boolean, | 56 type: Boolean, |
| 60 readOnly: true | 57 readOnly: true |
| 58 }, |
| 59 |
| 60 /** |
| 61 * The aria attribute to be set if the button is a toggle and in the |
| 62 * active state. |
| 63 */ |
| 64 ariaActiveAttribute: { |
| 65 type: String, |
| 66 value: 'aria-pressed', |
| 67 observer: '_ariaActiveAttributeChanged' |
| 61 } | 68 } |
| 62 }, | 69 }, |
| 63 | 70 |
| 64 listeners: { | 71 listeners: { |
| 65 down: '_downHandler', | 72 down: '_downHandler', |
| 66 up: '_upHandler', | 73 up: '_upHandler', |
| 67 tap: '_tapHandler' | 74 tap: '_tapHandler' |
| 68 }, | 75 }, |
| 69 | 76 |
| 70 observers: [ | 77 observers: [ |
| 71 '_detectKeyboardFocus(focused)' | 78 '_detectKeyboardFocus(focused)', |
| 79 '_activeChanged(active, ariaActiveAttribute)' |
| 72 ], | 80 ], |
| 73 | 81 |
| 74 keyBindings: { | 82 keyBindings: { |
| 75 'enter:keydown': '_asyncClick', | 83 'enter:keydown': '_asyncClick', |
| 76 'space:keydown': '_spaceKeyDownHandler', | 84 'space:keydown': '_spaceKeyDownHandler', |
| 77 'space:keyup': '_spaceKeyUpHandler', | 85 'space:keyup': '_spaceKeyUpHandler', |
| 78 }, | 86 }, |
| 79 | 87 |
| 80 _mouseEventRe: /^mouse/, | 88 _mouseEventRe: /^mouse/, |
| 81 | 89 |
| 82 _tapHandler: function() { | 90 _tapHandler: function() { |
| 83 if (this.toggles) { | 91 if (this.toggles) { |
| 84 // a tap is needed to toggle the active state | 92 // a tap is needed to toggle the active state |
| 85 this._userActivate(!this.active); | 93 this._userActivate(!this.active); |
| 86 } else { | 94 } else { |
| 87 this.active = false; | 95 this.active = false; |
| 88 } | 96 } |
| 89 }, | 97 }, |
| 90 | 98 |
| 91 _detectKeyboardFocus: function(focused) { | 99 _detectKeyboardFocus: function(focused) { |
| 92 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); | 100 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); |
| 93 }, | 101 }, |
| 94 | 102 |
| 95 // to emulate native checkbox, (de-)activations from a user interaction fire | 103 // to emulate native checkbox, (de-)activations from a user interaction fire |
| 96 // 'change' events | 104 // 'change' events |
| 97 _userActivate: function(active) { | 105 _userActivate: function(active) { |
| 98 this.active = active; | 106 if (this.active !== active) { |
| 99 this.fire('change'); | 107 this.active = active; |
| 108 this.fire('change'); |
| 109 } |
| 100 }, | 110 }, |
| 101 | 111 |
| 102 _eventSourceIsPrimaryInput: function(event) { | 112 _eventSourceIsPrimaryInput: function(event) { |
| 103 event = event.detail.sourceEvent || event; | 113 event = event.detail.sourceEvent || event; |
| 104 | 114 |
| 105 // Always true for non-mouse events.... | 115 // Always true for non-mouse events.... |
| 106 if (!this._mouseEventRe.test(event.type)) { | 116 if (!this._mouseEventRe.test(event.type)) { |
| 107 return true; | 117 return true; |
| 108 } | 118 } |
| 109 | 119 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 this.click(); | 167 this.click(); |
| 158 }, 1); | 168 }, 1); |
| 159 }, | 169 }, |
| 160 | 170 |
| 161 // any of these changes are considered a change to button state | 171 // any of these changes are considered a change to button state |
| 162 | 172 |
| 163 _pressedChanged: function(pressed) { | 173 _pressedChanged: function(pressed) { |
| 164 this._changedButtonState(); | 174 this._changedButtonState(); |
| 165 }, | 175 }, |
| 166 | 176 |
| 167 _activeChanged: function(active) { | 177 _ariaActiveAttributeChanged: function(value, oldValue) { |
| 178 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { |
| 179 this.removeAttribute(oldValue); |
| 180 } |
| 181 }, |
| 182 |
| 183 _activeChanged: function(active, ariaActiveAttribute) { |
| 168 if (this.toggles) { | 184 if (this.toggles) { |
| 169 this.setAttribute('aria-pressed', active ? 'true' : 'false'); | 185 this.setAttribute(this.ariaActiveAttribute, |
| 186 active ? 'true' : 'false'); |
| 170 } else { | 187 } else { |
| 171 this.removeAttribute('aria-pressed'); | 188 this.removeAttribute(this.ariaActiveAttribute); |
| 172 } | 189 } |
| 173 this._changedButtonState(); | 190 this._changedButtonState(); |
| 174 }, | 191 }, |
| 175 | 192 |
| 176 _controlStateChanged: function() { | 193 _controlStateChanged: function() { |
| 177 if (this.disabled) { | 194 if (this.disabled) { |
| 178 this._setPressed(false); | 195 this._setPressed(false); |
| 179 } else { | 196 } else { |
| 180 this._changedButtonState(); | 197 this._changedButtonState(); |
| 181 } | 198 } |
| 182 }, | 199 }, |
| 183 | 200 |
| 184 // provide hook for follow-on behaviors to react to button-state | 201 // provide hook for follow-on behaviors to react to button-state |
| 185 | 202 |
| 186 _changedButtonState: function() { | 203 _changedButtonState: function() { |
| 187 if (this._buttonStateChanged) { | 204 if (this._buttonStateChanged) { |
| 188 this._buttonStateChanged(); // abstract | 205 this._buttonStateChanged(); // abstract |
| 189 } | 206 } |
| 190 } | 207 } |
| 191 | 208 |
| 192 }; | 209 }; |
| 193 | 210 |
| 194 /** @polymerBehavior */ | 211 /** @polymerBehavior */ |
| 195 Polymer.IronButtonState = [ | 212 Polymer.IronButtonState = [ |
| 196 Polymer.IronA11yKeysBehavior, | 213 Polymer.IronA11yKeysBehavior, |
| 197 Polymer.IronButtonStateImpl | 214 Polymer.IronButtonStateImpl |
| 198 ]; | 215 ]; |
| 199 | |
| OLD | NEW |