OLD | NEW |
1 | 1 /** |
2 | |
3 /** | |
4 * @demo demo/index.html | 2 * @demo demo/index.html |
5 * @polymerBehavior | 3 * @polymerBehavior |
6 */ | 4 */ |
7 Polymer.IronControlState = { | 5 Polymer.IronControlState = { |
8 | 6 |
9 properties: { | 7 properties: { |
10 | 8 |
11 /** | 9 /** |
12 * If true, the element currently has focus. | 10 * If true, the element currently has focus. |
13 */ | 11 */ |
(...skipping 27 matching lines...) Expand all Loading... |
41 } | 39 } |
42 } | 40 } |
43 | 41 |
44 }, | 42 }, |
45 | 43 |
46 observers: [ | 44 observers: [ |
47 '_changedControlState(focused, disabled)' | 45 '_changedControlState(focused, disabled)' |
48 ], | 46 ], |
49 | 47 |
50 ready: function() { | 48 ready: function() { |
51 // TODO(sjmiles): ensure read-only property is valued so the compound | |
52 // observer will fire | |
53 if (this.focused === undefined) { | |
54 this._setFocused(false); | |
55 } | |
56 this.addEventListener('focus', this._boundFocusBlurHandler, true); | 49 this.addEventListener('focus', this._boundFocusBlurHandler, true); |
57 this.addEventListener('blur', this._boundFocusBlurHandler, true); | 50 this.addEventListener('blur', this._boundFocusBlurHandler, true); |
58 }, | 51 }, |
59 | 52 |
60 _focusBlurHandler: function(event) { | 53 _focusBlurHandler: function(event) { |
61 var target = event.path ? event.path[0] : event.target; | 54 var target = event.path ? event.path[0] : event.target; |
62 if (target === this) { | 55 if (target === this) { |
63 var focused = event.type === 'focus'; | 56 var focused = event.type === 'focus'; |
64 this._setFocused(focused); | 57 this._setFocused(focused); |
65 } else if (!this.shadowRoot) { | 58 } else if (!this.shadowRoot) { |
66 event.stopPropagation(); | |
67 this.fire(event.type, {sourceEvent: event}, { | 59 this.fire(event.type, {sourceEvent: event}, { |
68 node: this, | 60 node: this, |
69 bubbles: event.bubbles, | 61 bubbles: event.bubbles, |
70 cancelable: event.cancelable | 62 cancelable: event.cancelable |
71 }); | 63 }); |
72 } | 64 } |
73 }, | 65 }, |
74 | 66 |
75 _disabledChanged: function(disabled, old) { | 67 _disabledChanged: function(disabled, old) { |
76 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | 68 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); |
77 this.style.pointerEvents = disabled ? 'none' : ''; | 69 this.style.pointerEvents = disabled ? 'none' : ''; |
78 if (disabled) { | 70 if (disabled) { |
79 this._oldTabIndex = this.tabIndex; | 71 this._oldTabIndex = this.tabIndex; |
80 this.focused = false; | 72 this.focused = false; |
81 this.tabIndex = -1; | 73 this.tabIndex = -1; |
82 } else if (this._oldTabIndex !== undefined) { | 74 } else if (this._oldTabIndex !== undefined) { |
83 this.tabIndex = this._oldTabIndex; | 75 this.tabIndex = this._oldTabIndex; |
84 } | 76 } |
85 }, | 77 }, |
86 | 78 |
87 _changedControlState: function() { | 79 _changedControlState: function() { |
88 // _controlStateChanged is abstract, follow-on behaviors may implement it | 80 // _controlStateChanged is abstract, follow-on behaviors may implement it |
89 if (this._controlStateChanged) { | 81 if (this._controlStateChanged) { |
90 this._controlStateChanged(); | 82 this._controlStateChanged(); |
91 } | 83 } |
92 } | 84 } |
93 | 85 |
94 }; | 86 }; |
95 | |
OLD | NEW |