| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 @license | |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 7 Code distributed by Google as part of the polymer project is also | |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 9 --> | |
| 10 | |
| 11 <link rel="import" href="../polymer/polymer.html"> | |
| 12 | |
| 13 <script> | |
| 14 | |
| 15 /** @polymerBehavior */ | |
| 16 | |
| 17 Polymer.IronControlState = { | |
| 18 | |
| 19 properties: { | |
| 20 | |
| 21 /** | |
| 22 * If true, the element currently has focus. | |
| 23 * | |
| 24 * @attribute focused | |
| 25 * @type boolean | |
| 26 * @default false | |
| 27 */ | |
| 28 focused: { | |
| 29 type: Boolean, | |
| 30 value: false, | |
| 31 notify: true, | |
| 32 readOnly: true, | |
| 33 reflectToAttribute: true | |
| 34 }, | |
| 35 | |
| 36 /** | |
| 37 * If true, the user cannot interact with this element. | |
| 38 * | |
| 39 * @attribute disabled | |
| 40 * @type boolean | |
| 41 * @default false | |
| 42 */ | |
| 43 disabled: { | |
| 44 type: Boolean, | |
| 45 value: false, | |
| 46 notify: true, | |
| 47 observer: '_disabledChanged', | |
| 48 reflectToAttribute: true | |
| 49 }, | |
| 50 | |
| 51 _oldTabIndex: { | |
| 52 type: Number | |
| 53 } | |
| 54 }, | |
| 55 | |
| 56 observers: [ | |
| 57 '_changedControlState(focused, disabled)' | |
| 58 ], | |
| 59 | |
| 60 listeners: { | |
| 61 focus: '_focusHandler', | |
| 62 blur: '_blurHandler' | |
| 63 }, | |
| 64 | |
| 65 ready: function() { | |
| 66 // TODO(sjmiles): ensure read-only property is valued so the compound | |
| 67 // observer will fire | |
| 68 if (this.focused === undefined) { | |
| 69 this._setFocused(false); | |
| 70 } | |
| 71 }, | |
| 72 | |
| 73 _focusHandler: function() { | |
| 74 this._setFocused(true); | |
| 75 }, | |
| 76 | |
| 77 _blurHandler: function() { | |
| 78 this._setFocused(false); | |
| 79 }, | |
| 80 | |
| 81 _disabledChanged: function(disabled, old) { | |
| 82 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
| 83 this.style.pointerEvents = disabled ? 'none' : ''; | |
| 84 if (disabled) { | |
| 85 this._oldTabIndex = this.tabIndex; | |
| 86 this.focused = false; | |
| 87 this.tabIndex = -1; | |
| 88 } else if (this._oldTabIndex !== undefined) { | |
| 89 this.tabIndex = this._oldTabIndex; | |
| 90 } | |
| 91 }, | |
| 92 | |
| 93 _changedControlState: function() { | |
| 94 // _controlStateChanged is abstract, follow-on behaviors may implement it | |
| 95 if (this._controlStateChanged) { | |
| 96 this._controlStateChanged(); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 }; | |
| 101 | |
| 102 </script> | |
| OLD | NEW |