Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 7eaf65d

Browse files
committed
core-list can be controlled via an external scrollTarget.
1 parent 7e21a0f commit 7eaf65d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

core-list.html

100755100644
+26-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<link rel="import" href="../polymer/polymer.html">
3333
<link rel="import" href="../core-selection/core-selection.html">
3434

35-
<polymer-element name="core-list" on-tap="{{tapHandler}}" on-scroll="{{scrollHandler}}">
35+
<polymer-element name="core-list" on-tap="{{tapHandler}}">
3636
<template>
3737
<core-selection id="selection" multi="{{multi}}" on-core-select="{{selectedHandler}}"></core-selection>
3838
<link rel="stylesheet" href="core-list.css">
@@ -44,7 +44,6 @@
4444
Polymer('core-list', {
4545

4646
publish: {
47-
4847
/**
4948
* Fired when an item element is tapped.
5049
*
@@ -63,6 +62,16 @@
6362
*/
6463
data: null,
6564

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+
6675
/**
6776
*
6877
* The height of a list item. `core-list` currently supports only fixed-height
@@ -121,11 +130,12 @@
121130
},
122131

123132
observe: {
124-
'data template': 'initialize'
133+
'data template scrollTarget': 'initialize'
125134
},
126135

127136
ready: function() {
128137
this.clearSelection();
138+
this._boundScrollHandler = this.scrollHandler.bind(this);
129139
},
130140

131141
attached: function() {
@@ -139,6 +149,15 @@
139149
if (!this.data || !this.template) {
140150
return;
141151
}
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+
142161
this.initializeViewport();
143162
this.initalizeData();
144163
this.onMutation(this, this.initializeItems);
@@ -147,7 +166,7 @@
147166
// TODO(sorvell): need to handle resizing
148167
initializeViewport: function() {
149168
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);
151170
this._physicalCount = this._visibleCount + this.extraItems;
152171
this._physicalHeight = this.height * this._physicalCount;
153172
},
@@ -214,7 +233,8 @@
214233
}
215234
},
216235

217-
scrollHandler: function() {
236+
scrollHandler: function(e, detail) {
237+
this._scrollTop = e.detail ? e.detail.target.scrollTop : e.target.scrollTop;
218238
this.refresh(false);
219239
},
220240

@@ -224,7 +244,7 @@
224244
* @method refresh
225245
*/
226246
refresh: function(force) {
227-
var firstVisibleIndex = Math.floor(this.scrollTop / this.height);
247+
var firstVisibleIndex = Math.floor(this._scrollTop / this.height);
228248
var visibleMidpoint = firstVisibleIndex + this._visibleCount / 2;
229249

230250
var firstReifiedIndex = Math.max(0, Math.floor(visibleMidpoint -

0 commit comments

Comments
 (0)