| 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 = 20; | 5 var DEFAULT_PHYSICAL_COUNT = 20; |
| 6 var MAX_PHYSICAL_COUNT = 500; | 6 var MAX_PHYSICAL_COUNT = 500; |
| 7 | 7 |
| 8 Polymer({ | 8 Polymer({ |
| 9 | 9 |
| 10 is: 'iron-list', | 10 is: 'iron-list', |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * The name of the variable to add to the binding scope for the array | 23 * The name of the variable to add to the binding scope for the array |
| 24 * element associated with a given template instance. | 24 * element associated with a given template instance. |
| 25 */ | 25 */ |
| 26 as: { | 26 as: { |
| 27 type: String, | 27 type: String, |
| 28 value: 'item' | 28 value: 'item' |
| 29 }, | 29 }, |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * The name of the variable to add to the binding scope with the index | 32 * The name of the variable to add to the binding scope with the index |
| 33 * for the row. If `sort` is provided, the index will reflect the | 33 * for the row. |
| 34 * sorted order (rather than the original array order). | |
| 35 */ | 34 */ |
| 36 indexAs: { | 35 indexAs: { |
| 37 type: String, | 36 type: String, |
| 38 value: 'index' | 37 value: 'index' |
| 39 }, | 38 }, |
| 40 | 39 |
| 41 /** | 40 /** |
| 42 * The name of the variable to add to the binding scope to indicate | 41 * The name of the variable to add to the binding scope to indicate |
| 43 * if the row is selected. | 42 * if the row is selected. |
| 44 */ | 43 */ |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 236 |
| 238 /** | 237 /** |
| 239 * The lowest n-th value for an item such that it can be rendered in `_physi
calStart`. | 238 * The lowest n-th value for an item such that it can be rendered in `_physi
calStart`. |
| 240 */ | 239 */ |
| 241 _minVirtualStart: 0, | 240 _minVirtualStart: 0, |
| 242 | 241 |
| 243 /** | 242 /** |
| 244 * The largest n-th value for an item such that it can be rendered in `_phys
icalStart`. | 243 * The largest n-th value for an item such that it can be rendered in `_phys
icalStart`. |
| 245 */ | 244 */ |
| 246 get _maxVirtualStart() { | 245 get _maxVirtualStart() { |
| 247 return this._virtualCount < this._physicalCount ? | 246 return Math.max(0, this._virtualCount - this._physicalCount); |
| 248 this._virtualCount : this._virtualCount - this._physicalCount; | |
| 249 }, | 247 }, |
| 250 | 248 |
| 251 /** | 249 /** |
| 252 * The height of the physical content that isn't on the screen. | 250 * The height of the physical content that isn't on the screen. |
| 253 */ | 251 */ |
| 254 get _hiddenContentSize() { | 252 get _hiddenContentSize() { |
| 255 return this._physicalSize - this._viewportSize; | 253 return this._physicalSize - this._viewportSize; |
| 256 }, | 254 }, |
| 257 | 255 |
| 258 /** | 256 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 }, | 289 }, |
| 292 | 290 |
| 293 /** | 291 /** |
| 294 * True if the current list is visible. | 292 * True if the current list is visible. |
| 295 */ | 293 */ |
| 296 get _isVisible() { | 294 get _isVisible() { |
| 297 return this._scroller && Boolean(this._scroller.offsetWidth || this._scrol
ler.offsetHeight); | 295 return this._scroller && Boolean(this._scroller.offsetWidth || this._scrol
ler.offsetHeight); |
| 298 }, | 296 }, |
| 299 | 297 |
| 300 /** | 298 /** |
| 301 * Gets the first visible item in the viewport. | 299 * Gets the index of the first visible item in the viewport. |
| 302 * | 300 * |
| 303 * @type {number} | 301 * @type {number} |
| 304 */ | 302 */ |
| 305 get firstVisibleIndex() { | 303 get firstVisibleIndex() { |
| 306 var physicalOffset; | 304 var physicalOffset; |
| 307 | 305 |
| 308 if (this._firstVisibleIndexVal === null) { | 306 if (this._firstVisibleIndexVal === null) { |
| 309 physicalOffset = this._physicalTop; | 307 physicalOffset = this._physicalTop; |
| 310 | 308 |
| 311 this._firstVisibleIndexVal = this._iterateItems( | 309 this._firstVisibleIndexVal = this._iterateItems( |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 return false; | 567 return false; |
| 570 } | 568 } |
| 571 | 569 |
| 572 var newPhysicalItems = this._createPool(delta); | 570 var newPhysicalItems = this._createPool(delta); |
| 573 var emptyArray = new Array(delta); | 571 var emptyArray = new Array(delta); |
| 574 | 572 |
| 575 [].push.apply(this._physicalItems, newPhysicalItems); | 573 [].push.apply(this._physicalItems, newPhysicalItems); |
| 576 [].push.apply(this._physicalSizes, emptyArray); | 574 [].push.apply(this._physicalSizes, emptyArray); |
| 577 | 575 |
| 578 this._physicalCount = prevPhysicalCount + delta; | 576 this._physicalCount = prevPhysicalCount + delta; |
| 579 | 577 |
| 580 return true; | 578 return true; |
| 581 }, | 579 }, |
| 582 | 580 |
| 583 /** | 581 /** |
| 584 * Render a new list of items. This method does exactly the same as `update`
, | 582 * Render a new list of items. This method does exactly the same as `update`
, |
| 585 * but it also ensures that only one `update` cycle is created. | 583 * but it also ensures that only one `update` cycle is created. |
| 586 */ | 584 */ |
| 587 _render: function() { | 585 _render: function() { |
| 588 var requiresUpdate = this._virtualCount > 0 || this._physicalCount > 0; | 586 var requiresUpdate = this._virtualCount > 0 || this._physicalCount > 0; |
| 589 | 587 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 } | 748 } |
| 751 }, | 749 }, |
| 752 | 750 |
| 753 _scrollHandler: function() { | 751 _scrollHandler: function() { |
| 754 this._refresh(); | 752 this._refresh(); |
| 755 }, | 753 }, |
| 756 | 754 |
| 757 /** | 755 /** |
| 758 * Executes a provided function per every physical index in `itemSet` | 756 * Executes a provided function per every physical index in `itemSet` |
| 759 * `itemSet` default value is equivalent to the entire set of physical index
es. | 757 * `itemSet` default value is equivalent to the entire set of physical index
es. |
| 760 * | 758 * |
| 761 * @param {!function(number, number)} fn | 759 * @param {!function(number, number)} fn |
| 762 * @param {!Array<number>=} itemSet | 760 * @param {!Array<number>=} itemSet |
| 763 */ | 761 */ |
| 764 _iterateItems: function(fn, itemSet) { | 762 _iterateItems: function(fn, itemSet) { |
| 765 var pidx, vidx, rtn, i; | 763 var pidx, vidx, rtn, i; |
| 766 | 764 |
| 767 if (arguments.length === 2 && itemSet) { | 765 if (arguments.length === 2 && itemSet) { |
| 768 for (i = 0; i < itemSet.length; i++) { | 766 for (i = 0; i < itemSet.length; i++) { |
| 769 pidx = itemSet[i]; | 767 pidx = itemSet[i]; |
| 770 if (pidx >= this._physicalStart) { | 768 if (pidx >= this._physicalStart) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 */ | 890 */ |
| 893 _resetScrollPosition: function(pos) { | 891 _resetScrollPosition: function(pos) { |
| 894 if (this._scroller) { | 892 if (this._scroller) { |
| 895 this._scroller.scrollTop = pos; | 893 this._scroller.scrollTop = pos; |
| 896 this._scrollPosition = this._scroller.scrollTop; | 894 this._scrollPosition = this._scroller.scrollTop; |
| 897 } | 895 } |
| 898 }, | 896 }, |
| 899 | 897 |
| 900 /** | 898 /** |
| 901 * Sets the scroll height, that's the height of the content, | 899 * Sets the scroll height, that's the height of the content, |
| 902 * | 900 * |
| 903 * @param {boolean=} forceUpdate If true, updates the height no matter what. | 901 * @param {boolean=} forceUpdate If true, updates the height no matter what. |
| 904 */ | 902 */ |
| 905 _updateScrollerSize: function(forceUpdate) { | 903 _updateScrollerSize: function(forceUpdate) { |
| 906 this._estScrollHeight = (this._physicalBottom + | 904 this._estScrollHeight = (this._physicalBottom + |
| 907 Math.max(this._virtualCount - this._physicalCount - this._virtualStart
Val, 0) * this._physicalAverage); | 905 Math.max(this._virtualCount - this._physicalCount - this._virtualStart
Val, 0) * this._physicalAverage); |
| 908 | 906 |
| 909 forceUpdate = forceUpdate || this._scrollHeight === 0; | 907 forceUpdate = forceUpdate || this._scrollHeight === 0; |
| 910 forceUpdate = forceUpdate || this._scrollPosition >= this._estScrollHeight
- this._physicalSize; | 908 forceUpdate = forceUpdate || this._scrollPosition >= this._estScrollHeight
- this._physicalSize; |
| 911 | 909 |
| 912 // amortize height adjustment, so it won't trigger repaints very often | 910 // amortize height adjustment, so it won't trigger repaints very often |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 var pidx = this._physicalIndexForKey[key]; | 1141 var pidx = this._physicalIndexForKey[key]; |
| 1144 | 1142 |
| 1145 if (pidx !== undefined) { | 1143 if (pidx !== undefined) { |
| 1146 this._updateMetrics([pidx]); | 1144 this._updateMetrics([pidx]); |
| 1147 this._positionItems(); | 1145 this._positionItems(); |
| 1148 } | 1146 } |
| 1149 } | 1147 } |
| 1150 }); | 1148 }); |
| 1151 | 1149 |
| 1152 })(); | 1150 })(); |
| OLD | NEW |