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

@ -49,13 +49,14 @@ const getOffset = (el: Element): Record<string, any> => {
const getDetailsBottom = ( const getDetailsBottom = (
seasonContainers: HTMLCollectionOf<HTMLElement>, seasonContainers: HTMLCollectionOf<HTMLElement>,
episodeContainers: HTMLCollectionOf<HTMLElement> episodeContainers: HTMLCollectionOf<HTMLElement>,
activeElem: HTMLElement
): number | false => { ): number | false => {
const lastSeasonContainer = seasonContainers[seasonContainers.length - 1]; const lastSeasonContainer = seasonContainers[seasonContainers.length - 1];
const lastEpisodeContainer = episodeContainers[episodeContainers.length - 1]; const lastEpisodeContainer = episodeContainers[episodeContainers.length - 1];
let detailBottom: number | false = false; 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; detailBottom = getHeight(lastSeasonContainer) + parseInt(getOffset(lastSeasonContainer).top, 10) + 10;
} else if (episodeContainers.length > 0) { } else if (episodeContainers.length > 0) {
detailBottom = getHeight(lastEpisodeContainer) + parseInt(getOffset(lastEpisodeContainer).top, 10) + 10; 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({ window.scroll({
top: getOffset(activeElem as Element).top - 70 top: detailTop
}); });
} else { } else if (
const detailBottom = getDetailsBottom(seasonContainers, episodeContainers); detailBottom &&
if (detailBottom && this.getTop() + window.innerHeight > detailBottom) { window.innerHeight < detailBottom - detailTop &&
this.getTop() + window.innerHeight > detailBottom
) {
window.scroll({ window.scroll({
top: detailBottom - window.innerHeight top: detailBottom - window.innerHeight
}); });
} }
} }
}
this.renderNewElementsIfNeeded(); this.renderNewElementsIfNeeded();
}); });

Loading…
Cancel
Save