3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
7
Code distributed by Google as part of the polymer project is also
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
12
function findElementInList(container, selector) {
14
var children = container._children;
15
var ms = Polymer.DomApi.matchesSelector;
17
for (; i < children.length; i++) {
18
if (children[i].nodeType === Node.ELEMENT_NODE && ms.call(children[i], selector)) {
25
function buildItem(index) {
31
function buildDataSet(size) {
33
while (data.length < size) {
34
data.push(buildItem(data.length));
39
function simulateScroll(config) {
40
var list = config.list;
41
var target = config.target;
42
var delay = config.delay || 1;
43
var contribution = Math.abs(config.contribution) || 10;
45
if (target < list.scrollTop) {
46
contribution = -contribution;
49
function scrollHandler() {
50
setTimeout(function() {
52
var maxScrollTop = list.scrollHeight - list.offsetHeight;
54
config.onScroll && config.onScroll();
56
if (list.scrollTop < target && contribution > 0 && list.scrollTop < maxScrollTop) {
57
list.scrollTop = Math.min(maxScrollTop, list.scrollTop + contribution);
59
} else if (list.scrollTop > target && contribution < 0 && list.scrollTop > minScrollTop) {
60
list.scrollTop = Math.max(minScrollTop, list.scrollTop + contribution);
63
list.removeEventListener('scroll', scrollHandler);
64
list.scrollTop = target;
65
config.onScrollEnd && config.onScrollEnd();
69
list.addEventListener('scroll', scrollHandler);
73
function getFirstItemFromList(list) {
74
var listRect = list.getBoundingClientRect();
75
return document.elementFromPoint(listRect.left + 100, listRect.top + 1);
78
function getLastItemFromList(list) {
79
var listRect = list.getBoundingClientRect();
80
return document.elementFromPoint(listRect.left + 100, listRect.top + listRect.height - 1);
83
function isFullOfItems(list) {
84
var listRect = list.getBoundingClientRect();
85
var listHeight = listRect.height - 1;
86
var item, y = listRect.top + 1;
87
// IE 10 & 11 doesn't render propertly :(
89
while (y < listHeight) {
90
item = document.elementFromPoint(listRect.left + 100, y);
91
if (!item || (item.parentNode && !item.parentNode._templateInstance)) {
102
function checkRepeatedItems(list) {
103
var listRect = list.getBoundingClientRect();
104
var listHeight = list.offsetHeight;
109
var y = listRect.top;
110
while (y < listHeight) {
111
item = document.elementFromPoint(listRect.left + 100, y + 2);
112
itemKey = item.textContent || item.innerText;
114
if (item.parentNode && item.parentNode._templateInstance) {
115
if (listItems[itemKey] && listItems[itemKey] != item) {
118
listItems[itemKey] = item;
120
y += item.offsetHeight;