mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
add iron-list
This commit is contained in:
parent
396b125d66
commit
da7c9a4899
47 changed files with 36356 additions and 0 deletions
141
dashboard-ui/bower_components/iron-list/test/helpers.html
vendored
Normal file
141
dashboard-ui/bower_components/iron-list/test/helpers.html
vendored
Normal file
|
@ -0,0 +1,141 @@
|
|||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
|
||||
-->
|
||||
|
||||
<script>
|
||||
function findElementInList(container, selector) {
|
||||
var i = 0;
|
||||
var children = container._children;
|
||||
var ms = Polymer.DomApi.matchesSelector;
|
||||
|
||||
for (; i < children.length; i++) {
|
||||
if (children[i].nodeType === Node.ELEMENT_NODE && ms.call(children[i], selector)) {
|
||||
return children[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildItem(index) {
|
||||
return {
|
||||
index: index
|
||||
};
|
||||
}
|
||||
|
||||
function buildDataSet(size) {
|
||||
var data = [];
|
||||
while (data.length < size) {
|
||||
data.push(buildItem(data.length));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function simulateScroll(config) {
|
||||
var list = config.list;
|
||||
var target = config.target;
|
||||
var delay = config.delay || 1;
|
||||
var contribution = Math.abs(config.contribution) || 10;
|
||||
// scroll back up
|
||||
if (target < list.scrollTop) {
|
||||
contribution = -contribution;
|
||||
}
|
||||
|
||||
function scrollHandler() {
|
||||
setTimeout(function() {
|
||||
var minScrollTop = 0;
|
||||
var maxScrollTop = list.scrollHeight - list.offsetHeight;
|
||||
|
||||
config.onScroll && config.onScroll();
|
||||
|
||||
if (list.scrollTop < target && contribution > 0 && list.scrollTop < maxScrollTop) {
|
||||
list.scrollTop = Math.min(maxScrollTop, list.scrollTop + contribution);
|
||||
|
||||
} else if (list.scrollTop > target && contribution < 0 && list.scrollTop > minScrollTop) {
|
||||
list.scrollTop = Math.max(minScrollTop, list.scrollTop + contribution);
|
||||
|
||||
} else {
|
||||
list.removeEventListener('scroll', scrollHandler);
|
||||
list.scrollTop = target;
|
||||
config.onScrollEnd && config.onScrollEnd();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
list.addEventListener('scroll', scrollHandler);
|
||||
scrollHandler();
|
||||
}
|
||||
|
||||
function getGridRowFromIndex(grid, index) {
|
||||
return Math.floor(index / grid._itemsPerRow);
|
||||
}
|
||||
|
||||
function getNthItemFromGrid(grid, n, itemSize) {
|
||||
itemSize = itemSize || 100;
|
||||
var gridRect = grid.getBoundingClientRect();
|
||||
var x = gridRect.left + ((n % grid._itemsPerRow) * itemSize) + (itemSize / 2);
|
||||
var y = gridRect.top + (Math.floor(n / grid._itemsPerRow) * itemSize) + (itemSize / 2);
|
||||
return document.elementFromPoint(x, y);
|
||||
}
|
||||
|
||||
function getFirstItemFromList(list) {
|
||||
var listRect = list.getBoundingClientRect();
|
||||
return document.elementFromPoint(listRect.left + 100, listRect.top + 1);
|
||||
}
|
||||
|
||||
function getLastItemFromList(list) {
|
||||
var listRect = list.getBoundingClientRect();
|
||||
return document.elementFromPoint(listRect.left + 100, listRect.top + listRect.height - 1);
|
||||
}
|
||||
|
||||
function isFullOfItems(list) {
|
||||
var listRect = list.getBoundingClientRect();
|
||||
var listHeight = listRect.height - 1;
|
||||
var item, y = listRect.top + 1;
|
||||
// IE 10 & 11 doesn't render propertly :(
|
||||
var badPixels = 0;
|
||||
while (y < listHeight) {
|
||||
item = document.elementFromPoint(listRect.left + 100, y);
|
||||
if (!item || (item.parentNode && !item.parentNode._templateInstance)) {
|
||||
badPixels++;
|
||||
}
|
||||
y++;
|
||||
if (badPixels > 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkRepeatedItems(list) {
|
||||
var listRect = list.getBoundingClientRect();
|
||||
var listHeight = list.offsetHeight;
|
||||
var listItems = {};
|
||||
|
||||
return function() {
|
||||
var itemKey;
|
||||
var y = listRect.top;
|
||||
while (y < listHeight) {
|
||||
item = document.elementFromPoint(listRect.left + 100, y + 2);
|
||||
itemKey = item.textContent || item.innerText;
|
||||
|
||||
if (item.parentNode && item.parentNode._templateInstance) {
|
||||
if (listItems[itemKey] && listItems[itemKey] != item) {
|
||||
return true;
|
||||
}
|
||||
listItems[itemKey] = item;
|
||||
}
|
||||
y += item.offsetHeight;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
function getNthItemRowStart(grid, n) {
|
||||
return n - (n % grid._itemsPerRow);
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue