| OLD | NEW |
| 1 (function() { | 1 (function() { |
| 2 | 2 |
| 3 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); | 3 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); |
| 4 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; | 4 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; |
| 5 var DEFAULT_PHYSICAL_COUNT = 3; | 5 var DEFAULT_PHYSICAL_COUNT = 3; |
| 6 var HIDDEN_Y = '-10000px'; | 6 var HIDDEN_Y = '-10000px'; |
| 7 var DEFAULT_GRID_SIZE = 200; | 7 var DEFAULT_GRID_SIZE = 200; |
| 8 var SECRET_TABINDEX = -100; | 8 var SECRET_TABINDEX = -100; |
| 9 | 9 |
| 10 Polymer({ | 10 Polymer({ |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 * Scroll to a specific index in the virtual list regardless | 1172 * Scroll to a specific index in the virtual list regardless |
| 1173 * of the physical items in the DOM tree. | 1173 * of the physical items in the DOM tree. |
| 1174 * | 1174 * |
| 1175 * @method scrollToIndex | 1175 * @method scrollToIndex |
| 1176 * @param {number} idx The index of the item | 1176 * @param {number} idx The index of the item |
| 1177 */ | 1177 */ |
| 1178 scrollToIndex: function(idx) { | 1178 scrollToIndex: function(idx) { |
| 1179 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { | 1179 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { |
| 1180 return; | 1180 return; |
| 1181 } | 1181 } |
| 1182 | |
| 1183 Polymer.dom.flush(); | 1182 Polymer.dom.flush(); |
| 1184 | 1183 // Items should have been rendered prior scrolling to an index. |
| 1184 if (!this._itemsRendered) { |
| 1185 return; |
| 1186 } |
| 1185 idx = Math.min(Math.max(idx, 0), this._virtualCount-1); | 1187 idx = Math.min(Math.max(idx, 0), this._virtualCount-1); |
| 1186 // update the virtual start only when needed | 1188 // update the virtual start only when needed |
| 1187 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { | 1189 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { |
| 1188 this._virtualStart = this.grid ? (idx - this._itemsPerRow * 2) : (idx -
1); | 1190 this._virtualStart = this.grid ? (idx - this._itemsPerRow * 2) : (idx -
1); |
| 1189 } | 1191 } |
| 1190 // manage focus | 1192 // manage focus |
| 1191 this._manageFocus(); | 1193 this._manageFocus(); |
| 1192 // assign new models | 1194 // assign new models |
| 1193 this._assignModels(); | 1195 this._assignModels(); |
| 1194 // measure the new sizes | 1196 // measure the new sizes |
| 1195 this._updateMetrics(); | 1197 this._updateMetrics(); |
| 1196 | |
| 1197 // estimate new physical offset | 1198 // estimate new physical offset |
| 1198 var estPhysicalTop = Math.floor(this._virtualStart / this._itemsPerRow) *
this._physicalAverage; | 1199 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) *
this._physicalAverage; |
| 1199 this._physicalTop = estPhysicalTop; | |
| 1200 | 1200 |
| 1201 var currentTopItem = this._physicalStart; | 1201 var currentTopItem = this._physicalStart; |
| 1202 var currentVirtualItem = this._virtualStart; | 1202 var currentVirtualItem = this._virtualStart; |
| 1203 var targetOffsetTop = 0; | 1203 var targetOffsetTop = 0; |
| 1204 var hiddenContentSize = this._hiddenContentSize; | 1204 var hiddenContentSize = this._hiddenContentSize; |
| 1205 | |
| 1206 // scroll to the item as much as we can | 1205 // scroll to the item as much as we can |
| 1207 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { | 1206 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { |
| 1208 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); | 1207 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); |
| 1209 currentTopItem = (currentTopItem + 1) % this._physicalCount; | 1208 currentTopItem = (currentTopItem + 1) % this._physicalCount; |
| 1210 currentVirtualItem++; | 1209 currentVirtualItem++; |
| 1211 } | 1210 } |
| 1212 // update the scroller size | 1211 // update the scroller size |
| 1213 this._updateScrollerSize(true); | 1212 this._updateScrollerSize(true); |
| 1214 // update the position of the items | 1213 // update the position of the items |
| 1215 this._positionItems(); | 1214 this._positionItems(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 if (target.localName === 'input' || | 1383 if (target.localName === 'input' || |
| 1385 target.localName === 'button' || | 1384 target.localName === 'button' || |
| 1386 target.localName === 'select') { | 1385 target.localName === 'select') { |
| 1387 return; | 1386 return; |
| 1388 } | 1387 } |
| 1389 // Set a temporary tabindex | 1388 // Set a temporary tabindex |
| 1390 modelTabIndex = model.tabIndex; | 1389 modelTabIndex = model.tabIndex; |
| 1391 model.tabIndex = SECRET_TABINDEX; | 1390 model.tabIndex = SECRET_TABINDEX; |
| 1392 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; | 1391 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; |
| 1393 model.tabIndex = modelTabIndex; | 1392 model.tabIndex = modelTabIndex; |
| 1393 |
| 1394 // Only select the item if the tap wasn't on a focusable child | 1394 // Only select the item if the tap wasn't on a focusable child |
| 1395 // or the element bound to `tabIndex` | 1395 // or the element bound to `tabIndex` |
| 1396 if (activeEl && physicalItem.contains(activeEl) && activeElTabIndex !== SE
CRET_TABINDEX) { | 1396 if (activeEl && physicalItem !== activeEl && physicalItem.contains(activeE
l) && activeElTabIndex !== SECRET_TABINDEX) { |
| 1397 return; | 1397 return; |
| 1398 } | 1398 } |
| 1399 this.toggleSelectionForItem(model[this.as]); | 1399 this.toggleSelectionForItem(model[this.as]); |
| 1400 }, | 1400 }, |
| 1401 | 1401 |
| 1402 _multiSelectionChanged: function(multiSelection) { | 1402 _multiSelectionChanged: function(multiSelection) { |
| 1403 this.clearSelection(); | 1403 this.clearSelection(); |
| 1404 this.$.selector.multi = multiSelection; | 1404 this.$.selector.multi = multiSelection; |
| 1405 }, | 1405 }, |
| 1406 | 1406 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 this._focusPhysicalItem(this._focusedIndex + 1); | 1586 this._focusPhysicalItem(this._focusedIndex + 1); |
| 1587 }, | 1587 }, |
| 1588 | 1588 |
| 1589 _didEnter: function(e) { | 1589 _didEnter: function(e) { |
| 1590 this._focusPhysicalItem(this._focusedIndex); | 1590 this._focusPhysicalItem(this._focusedIndex); |
| 1591 this._selectionHandler(e.detail.keyboardEvent); | 1591 this._selectionHandler(e.detail.keyboardEvent); |
| 1592 } | 1592 } |
| 1593 }); | 1593 }); |
| 1594 | 1594 |
| 1595 })(); | 1595 })(); |
| OLD | NEW |