Update: Run scroll and resize events only if visible

pull/30/head
Juraj Nyíri 3 years ago
parent 824f993694
commit 82e00702bc

@ -20782,7 +20782,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {
// todo: improve performance by calculating this when needed only // todo: improve performance by calculating this when needed only
if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this)) { if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) {
const seasonContainers = this.getElementsByClassName('seasonContainer'); const seasonContainers = this.getElementsByClassName('seasonContainer');
const episodeContainers = this.getElementsByClassName('episodeContainer'); const episodeContainers = this.getElementsByClassName('episodeContainer');
const seasonElems = this.getElementsByClassName('seasonElem'); const seasonElems = this.getElementsByClassName('seasonElem');
@ -20822,6 +20822,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderNewElementsIfNeeded(); this.renderNewElementsIfNeeded();
}); });
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
if (this.isVisible) {
if (!this.detailsShown) { if (!this.detailsShown) {
const videoPlayer = this.getElementsByClassName('videoPlayer')[0]; const videoPlayer = this.getElementsByClassName('videoPlayer')[0];
let isFullScreen = false; let isFullScreen = false;
@ -20838,6 +20839,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
} }
this.renderNewElementsIfNeeded(); this.renderNewElementsIfNeeded();
}
}); });
if (this.card) { if (this.card) {
this.previousPageWidth = this.card.offsetWidth; this.previousPageWidth = this.card.offsetWidth;

@ -175,7 +175,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {
// todo: improve performance by calculating this when needed only // todo: improve performance by calculating this when needed only
if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this)) { if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) {
const seasonContainers = this.getElementsByClassName('seasonContainer') as HTMLCollectionOf<HTMLElement>; const seasonContainers = this.getElementsByClassName('seasonContainer') as HTMLCollectionOf<HTMLElement>;
const episodeContainers = this.getElementsByClassName('episodeContainer') as HTMLCollectionOf<HTMLElement>; const episodeContainers = this.getElementsByClassName('episodeContainer') as HTMLCollectionOf<HTMLElement>;
const seasonElems = this.getElementsByClassName('seasonElem') as HTMLCollectionOf<HTMLElement>; const seasonElems = this.getElementsByClassName('seasonElem') as HTMLCollectionOf<HTMLElement>;
@ -215,6 +215,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderNewElementsIfNeeded(); this.renderNewElementsIfNeeded();
}); });
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
if (this.isVisible) {
if (!this.detailsShown) { if (!this.detailsShown) {
const videoPlayer = this.getElementsByClassName('videoPlayer')[0] as HTMLElement; const videoPlayer = this.getElementsByClassName('videoPlayer')[0] as HTMLElement;
let isFullScreen = false; let isFullScreen = false;
@ -232,6 +233,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
} }
this.renderNewElementsIfNeeded(); this.renderNewElementsIfNeeded();
}
}); });
if (this.card) { if (this.card) {

Loading…
Cancel
Save