Fix: Bottom scroll boundary for every season and fullscreen infinite loop

pull/16/head
Juraj Nyíri 4 years ago
parent 9ad716a42a
commit f21a99421e

@ -19157,11 +19157,11 @@ const getOffset = (el) => {
}
return { top: y, left: x };
};
const getDetailsBottom = (seasonContainers, episodeContainers) => {
const getDetailsBottom = (seasonContainers, episodeContainers, activeElem) => {
const lastSeasonContainer = seasonContainers[seasonContainers.length - 1];
const lastEpisodeContainer = episodeContainers[episodeContainers.length - 1];
let detailBottom = false;
if (seasonContainers.length > 0 && parseInt(lastSeasonContainer.style.top, 10) > 0) {
if (seasonContainers.length > 0 && parseInt(activeElem.style.top, 10) > 0) {
detailBottom = getHeight(lastSeasonContainer) + parseInt(getOffset(lastSeasonContainer).top, 10) + 10;
}
else if (episodeContainers.length > 0) {
@ -20040,20 +20040,21 @@ class PlexMeetsHomeAssistant extends HTMLElement {
return false;
}
});
if (this.getTop() < parseInt(getOffset(activeElem).top, 10) - 70) {
const detailTop = parseInt(getOffset(activeElem).top, 10) - 70;
const detailBottom = getDetailsBottom(seasonContainers, episodeContainers, activeElem);
if (this.getTop() < detailTop) {
window.scroll({
top: getOffset(activeElem).top - 70
top: detailTop
});
}
else {
const detailBottom = getDetailsBottom(seasonContainers, episodeContainers);
if (detailBottom && this.getTop() + window.innerHeight > detailBottom) {
else if (detailBottom &&
window.innerHeight < detailBottom - detailTop &&
this.getTop() + window.innerHeight > detailBottom) {
window.scroll({
top: detailBottom - window.innerHeight
});
}
}
}
this.renderNewElementsIfNeeded();
});
window.addEventListener('resize', () => {

@ -49,13 +49,14 @@ const getOffset = (el: Element): Record<string, any> => {
const getDetailsBottom = (
seasonContainers: HTMLCollectionOf<HTMLElement>,
episodeContainers: HTMLCollectionOf<HTMLElement>
episodeContainers: HTMLCollectionOf<HTMLElement>,
activeElem: HTMLElement
): number | false => {
const lastSeasonContainer = seasonContainers[seasonContainers.length - 1];
const lastEpisodeContainer = episodeContainers[episodeContainers.length - 1];
let detailBottom: number | false = false;
if (seasonContainers.length > 0 && parseInt(lastSeasonContainer.style.top, 10) > 0) {
if (seasonContainers.length > 0 && parseInt(activeElem.style.top, 10) > 0) {
detailBottom = getHeight(lastSeasonContainer) + parseInt(getOffset(lastSeasonContainer).top, 10) + 10;
} else if (episodeContainers.length > 0) {
detailBottom = getHeight(lastEpisodeContainer) + parseInt(getOffset(lastEpisodeContainer).top, 10) + 10;

@ -163,19 +163,23 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}
});
if (this.getTop() < parseInt(getOffset(activeElem as Element).top, 10) - 70) {
const detailTop = parseInt(getOffset(activeElem as Element).top, 10) - 70;
const detailBottom = getDetailsBottom(seasonContainers, episodeContainers, activeElem);
if (this.getTop() < detailTop) {
window.scroll({
top: getOffset(activeElem as Element).top - 70
top: detailTop
});
} else {
const detailBottom = getDetailsBottom(seasonContainers, episodeContainers);
if (detailBottom && this.getTop() + window.innerHeight > detailBottom) {
} else if (
detailBottom &&
window.innerHeight < detailBottom - detailTop &&
this.getTop() + window.innerHeight > detailBottom
) {
window.scroll({
top: detailBottom - window.innerHeight
});
}
}
}
this.renderNewElementsIfNeeded();
});

Loading…
Cancel
Save