1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update components

This commit is contained in:
Luke Pulverenti 2016-02-28 16:31:45 -05:00
parent fbb6861985
commit 7b40f1daff
9 changed files with 430 additions and 60 deletions

View file

@ -285,8 +285,24 @@ define([], function () {
return elem;
}
function intersectsInternal(a1, a2, b1, b2) {
return (b1 >= a1 && b1 <= a2) || (b2 >= a1 && b2 <= a2);
}
function intersects(a1, a2, b1, b2) {
return intersectsInternal(a1, a2, b1, b2) || intersectsInternal(b1, b2, a1, a2);
}
var enableDebugInfo = false;
function getNearestElements(elementInfos, options, direction) {
if (enableDebugInfo) {
removeAll();
}
// Get elements and work out x/y points
var cache = [],
point1x = parseFloat(options.left) || 0,
@ -310,58 +326,67 @@ define([], function () {
x = off.left,
y = off.top,
x2 = x + off.width - 1,
y2 = y + off.height - 1,
maxX1 = max(x, point1x),
minX2 = min(x2, point2x),
maxY1 = max(y, point1y),
minY2 = min(y2, point2y),
intersectX = minX2 >= maxX1,
intersectY = minY2 >= maxY1;
y2 = y + off.height - 1;
var intersectX = intersects(point1x, point2x, x, x2);
var intersectY = intersects(point1y, point2y, y, y2);
var midX = off.left + (off.width / 2);
var midY = off.top + (off.height / 2);
var distX;
var distY;
var distX2;
var distY2;
switch (direction) {
case 0:
// left
distX = intersectX ? 0 : Math.abs(point1x - x2);
distX = distX2 = Math.abs(point1x - Math.min(point1x, x2));
distY = intersectY ? 0 : Math.abs(sourceMidY - midY);
distY2 = Math.abs(sourceMidY - midY);
break;
case 1:
// right
distX = intersectX ? 0 : Math.abs(x - point2x);
distX = distX2 = Math.abs(point2x - Math.max(point2x, x));
distY = intersectY ? 0 : Math.abs(sourceMidY - midY);
distY2 = Math.abs(sourceMidY - midY);
break;
case 2:
// up
distY = intersectY ? 0 : Math.abs(point1y - y2);
distY = distY2 = Math.abs(point1y - Math.min(point1y, y2));
distX = intersectX ? 0 : Math.abs(sourceMidX - midX);
distX2 = Math.abs(sourceMidX - midX);
break;
case 3:
// down
distY = intersectY ? 0 : Math.abs(y - point2y);
distY = distY2 = Math.abs(point2y - Math.max(point2y, y));
distX = intersectX ? 0 : Math.abs(sourceMidX - midX);
distX2 = Math.abs(sourceMidX - midX);
break;
default:
break;
}
if (enableDebugInfo) {
addDebugInfo(elem, distX, distY);
}
var distT = Math.sqrt(distX * distX + distY * distY);
var distT2 = Math.sqrt(distX2 * distX2 + distY2 * distY2);
cache.push({
node: elem,
distX: distX,
distY: distY,
distT: distT
distT: distT,
distT2: distT2
});
}
cache.sort(sortNodesT);
//if (direction < 2) {
//if (direction >= 2) {
// cache.sort(sortNodesX);
//} else {
// cache.sort(sortNodesY);
@ -370,25 +395,61 @@ define([], function () {
return cache;
}
function addDebugInfo(elem, distX, distY) {
var div = elem.querySelector('focusInfo');
if (!div) {
div = document.createElement('div');
div.classList.add('focusInfo');
elem.appendChild(div);
if (getComputedStyle(elem, null).getPropertyValue('position') == 'static') {
elem.style.position = 'relative';
}
div.style.position = 'absolute';
div.style.left = '0';
div.style.top = '0';
div.style.color = 'white';
div.style.backgroundColor = 'red';
div.style.padding = '2px';
}
div.innerHTML = Math.round(distX) + ',' + Math.round(distY);
}
function removeAll() {
var elems = document.querySelectorAll('.focusInfo');
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].parentNode.removeChild(elems[i]);
}
}
function sortNodesX(a, b) {
var result = a.distX - b.distX;
if (result == 0) {
return a.distY - b.distY;
return a.distT - b.distT;
}
return result;
}
function sortNodesT(a, b) {
return a.distT - b.distT;
var result = a.distT - b.distT;
if (result == 0) {
return a.distT2 - b.distT2;
}
return result;
}
function sortNodesY(a, b) {
var result = a.distY - b.distY;
if (result == 0) {
return a.distX - b.distX;
return a.distT - b.distT;
}
return result;