OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2015 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 <link rel="import" href="../polymer/polymer.html"> | |
11 | |
12 <script> | |
13 | |
14 Polymer.IronControlState = { | |
15 | |
16 properties: { | |
17 | |
18 /** | |
19 * If true, the element currently has focus. | |
20 * | |
21 * @attribute focused | |
22 * @type boolean | |
23 * @default false | |
24 */ | |
25 focused: { | |
26 type: Boolean, | |
27 value: false, | |
28 notify: true, | |
29 readOnly: true, | |
30 reflectToAttribute: true | |
31 }, | |
32 | |
33 /** | |
34 * If true, the user cannot interact with this element. | |
35 * | |
36 * @attribute disabled | |
37 * @type boolean | |
38 * @default false | |
39 */ | |
40 disabled: { | |
41 type: Boolean, | |
42 value: false, | |
43 notify: true, | |
44 observer: '_disabledChanged', | |
45 reflectToAttribute: true | |
46 }, | |
47 | |
48 _oldTabIndex: { | |
49 type: String | |
50 } | |
51 }, | |
52 | |
53 observers: [ | |
54 '_changedControlState(focused, disabled)' | |
55 ], | |
56 | |
57 listeners: { | |
58 focus: '_focusHandler', | |
59 blur: '_blurHandler' | |
60 }, | |
61 | |
62 ready: function() { | |
63 // TODO(sjmiles): ensure read-only property is valued so the compound | |
64 // observer will fire | |
65 if (this.focused === undefined) { | |
66 this._setFocused(false); | |
67 } | |
68 }, | |
69 | |
70 _focusHandler: function() { | |
71 this._setFocused(true); | |
72 }, | |
73 | |
74 _blurHandler: function() { | |
75 this._setFocused(false); | |
76 }, | |
77 | |
78 _disabledChanged: function(disabled, old) { | |
79 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
80 this.style.pointerEvents = disabled ? 'none' : ''; | |
81 if (disabled) { | |
82 this._oldTabIndex = this.tabIndex; | |
83 this.focused = false; | |
84 this.tabIndex = -1; | |
85 } else if (this._oldTabIndex !== undefined) { | |
86 this.tabIndex = this._oldTabIndex; | |
87 } | |
88 }, | |
89 | |
90 _changedControlState: function() { | |
91 // _controlStateChanged is abstract, follow-on behaviors may implement it | |
92 if (this._controlStateChanged) { | |
93 this._controlStateChanged(); | |
94 } | |
95 } | |
96 | |
97 }; | |
98 | |
99 </script> | |
OLD | NEW |