| OLD | NEW |
| 1 /** | 1 /** |
| 2 * `Polymer.IronMenuBehavior` implements accessible menu behavior. | 2 * `Polymer.IronMenuBehavior` implements accessible menu behavior. |
| 3 * | 3 * |
| 4 * @demo demo/index.html | 4 * @demo demo/index.html |
| 5 * @polymerBehavior Polymer.IronMenuBehavior | 5 * @polymerBehavior Polymer.IronMenuBehavior |
| 6 */ | 6 */ |
| 7 Polymer.IronMenuBehaviorImpl = { | 7 Polymer.IronMenuBehaviorImpl = { |
| 8 | 8 |
| 9 properties: { | 9 properties: { |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 }, | 121 }, |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Focuses the previous item (relative to the currently focused item) in the | 124 * Focuses the previous item (relative to the currently focused item) in the |
| 125 * menu, disabled items will be skipped. | 125 * menu, disabled items will be skipped. |
| 126 * Loop until length + 1 to handle case of single item in menu. | 126 * Loop until length + 1 to handle case of single item in menu. |
| 127 */ | 127 */ |
| 128 _focusPrevious: function() { | 128 _focusPrevious: function() { |
| 129 var length = this.items.length; | 129 var length = this.items.length; |
| 130 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 130 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 131 |
| 131 for (var i = 1; i < length + 1; i++) { | 132 for (var i = 1; i < length + 1; i++) { |
| 132 var item = this.items[(curFocusIndex - i + length) % length]; | 133 var item = this.items[(curFocusIndex - i + length) % length]; |
| 133 if (!item.hasAttribute('disabled')) { | 134 if (!item.hasAttribute('disabled')) { |
| 135 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 134 this._setFocusedItem(item); | 136 this._setFocusedItem(item); |
| 135 return; | 137 |
| 138 // Focus might not have worked, if the element was hidden or not |
| 139 // focusable. In that case, try again. |
| 140 if (Polymer.dom(owner).activeElement == item) { |
| 141 return; |
| 142 } |
| 136 } | 143 } |
| 137 } | 144 } |
| 138 }, | 145 }, |
| 139 | 146 |
| 140 /** | 147 /** |
| 141 * Focuses the next item (relative to the currently focused item) in the | 148 * Focuses the next item (relative to the currently focused item) in the |
| 142 * menu, disabled items will be skipped. | 149 * menu, disabled items will be skipped. |
| 143 * Loop until length + 1 to handle case of single item in menu. | 150 * Loop until length + 1 to handle case of single item in menu. |
| 144 */ | 151 */ |
| 145 _focusNext: function() { | 152 _focusNext: function() { |
| 146 var length = this.items.length; | 153 var length = this.items.length; |
| 147 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 154 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 155 |
| 148 for (var i = 1; i < length + 1; i++) { | 156 for (var i = 1; i < length + 1; i++) { |
| 149 var item = this.items[(curFocusIndex + i) % length]; | 157 var item = this.items[(curFocusIndex + i) % length]; |
| 150 if (!item.hasAttribute('disabled')) { | 158 if (!item.hasAttribute('disabled')) { |
| 159 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 151 this._setFocusedItem(item); | 160 this._setFocusedItem(item); |
| 152 return; | 161 |
| 162 // Focus might not have worked, if the element was hidden or not |
| 163 // focusable. In that case, try again. |
| 164 if (Polymer.dom(owner).activeElement == item) { |
| 165 return; |
| 166 } |
| 153 } | 167 } |
| 154 } | 168 } |
| 155 }, | 169 }, |
| 156 | 170 |
| 157 /** | 171 /** |
| 158 * Mutates items in the menu based on provided selection details, so that | 172 * Mutates items in the menu based on provided selection details, so that |
| 159 * all items correctly reflect selection state. | 173 * all items correctly reflect selection state. |
| 160 * | 174 * |
| 161 * @param {Element} item An item in the menu. | 175 * @param {Element} item An item in the menu. |
| 162 * @param {boolean} isSelected True if the item should be shown in a | 176 * @param {boolean} isSelected True if the item should be shown in a |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 }; | 323 }; |
| 310 | 324 |
| 311 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; | 325 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; |
| 312 | 326 |
| 313 /** @polymerBehavior Polymer.IronMenuBehavior */ | 327 /** @polymerBehavior Polymer.IronMenuBehavior */ |
| 314 Polymer.IronMenuBehavior = [ | 328 Polymer.IronMenuBehavior = [ |
| 315 Polymer.IronMultiSelectableBehavior, | 329 Polymer.IronMultiSelectableBehavior, |
| 316 Polymer.IronA11yKeysBehavior, | 330 Polymer.IronA11yKeysBehavior, |
| 317 Polymer.IronMenuBehaviorImpl | 331 Polymer.IronMenuBehaviorImpl |
| 318 ]; | 332 ]; |
| OLD | NEW |