|
32 | 32 | <link rel="import" href="../polymer/polymer.html">
|
33 | 33 | <link rel="import" href="../core-selection/core-selection.html">
|
34 | 34 |
|
35 |
| -<polymer-element name="core-list" on-tap="{{tapHandler}}" on-scroll="{{scrollHandler}}"> |
| 35 | +<polymer-element name="core-list" on-tap="{{tapHandler}}"> |
36 | 36 | <template>
|
37 | 37 | <core-selection id="selection" multi="{{multi}}" on-core-select="{{selectedHandler}}"></core-selection>
|
38 | 38 | <link rel="stylesheet" href="core-list.css">
|
|
44 | 44 | Polymer('core-list', {
|
45 | 45 |
|
46 | 46 | publish: {
|
47 |
| - |
48 | 47 | /**
|
49 | 48 | * Fired when an item element is tapped.
|
50 | 49 | *
|
|
63 | 62 | */
|
64 | 63 | data: null,
|
65 | 64 |
|
| 65 | + /** |
| 66 | + * |
| 67 | + * An optional element on which to listen for scroll events. |
| 68 | + * |
| 69 | + * @attribute scrollTarget |
| 70 | + * @type Element |
| 71 | + * @default core-list |
| 72 | + */ |
| 73 | + scrollTarget: null, |
| 74 | + |
66 | 75 | /**
|
67 | 76 | *
|
68 | 77 | * The height of a list item. `core-list` currently supports only fixed-height
|
|
121 | 130 | },
|
122 | 131 |
|
123 | 132 | observe: {
|
124 |
| - 'data template': 'initialize' |
| 133 | + 'data template scrollTarget': 'initialize' |
125 | 134 | },
|
126 | 135 |
|
127 | 136 | ready: function() {
|
128 | 137 | this.clearSelection();
|
| 138 | + this._boundScrollHandler = this.scrollHandler.bind(this); |
129 | 139 | },
|
130 | 140 |
|
131 | 141 | attached: function() {
|
|
139 | 149 | if (!this.data || !this.template) {
|
140 | 150 | return;
|
141 | 151 | }
|
| 152 | + var target = this.scrollTarget || this; |
| 153 | + if (this._target !== target) { |
| 154 | + if (this._target) { |
| 155 | + this._target.removeEventListener('scroll', this._boundScrollHandler, false); |
| 156 | + } |
| 157 | + this._target = target; |
| 158 | + this._target.addEventListener('scroll', this._boundScrollHandler, false); |
| 159 | + } |
| 160 | + |
142 | 161 | this.initializeViewport();
|
143 | 162 | this.initalizeData();
|
144 | 163 | this.onMutation(this, this.initializeItems);
|
|
147 | 166 | // TODO(sorvell): need to handle resizing
|
148 | 167 | initializeViewport: function() {
|
149 | 168 | this.$.viewport.style.height = this.height * this.data.length + 'px';
|
150 |
| - this._visibleCount = Math.ceil(this.offsetHeight / this.height); |
| 169 | + this._visibleCount = Math.ceil(this._target.offsetHeight / this.height); |
151 | 170 | this._physicalCount = this._visibleCount + this.extraItems;
|
152 | 171 | this._physicalHeight = this.height * this._physicalCount;
|
153 | 172 | },
|
|
214 | 233 | }
|
215 | 234 | },
|
216 | 235 |
|
217 |
| - scrollHandler: function() { |
| 236 | + scrollHandler: function(e, detail) { |
| 237 | + this._scrollTop = e.detail ? e.detail.target.scrollTop : e.target.scrollTop; |
218 | 238 | this.refresh(false);
|
219 | 239 | },
|
220 | 240 |
|
|
224 | 244 | * @method refresh
|
225 | 245 | */
|
226 | 246 | refresh: function(force) {
|
227 |
| - var firstVisibleIndex = Math.floor(this.scrollTop / this.height); |
| 247 | + var firstVisibleIndex = Math.floor(this._scrollTop / this.height); |
228 | 248 | var visibleMidpoint = firstVisibleIndex + this._visibleCount / 2;
|
229 | 249 |
|
230 | 250 | var firstReifiedIndex = Math.max(0, Math.floor(visibleMidpoint -
|
|
0 commit comments