From 82e00702bcc868a4435c17acf3dfbdf8e27c9103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Tue, 13 Jul 2021 00:56:12 +0200 Subject: [PATCH] Update: Run scroll and resize events only if visible --- dist/plex-meets-homeassistant.js | 30 ++++++++++++++++-------------- src/plex-meets-homeassistant.ts | 30 ++++++++++++++++-------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index c76dca0..c22de77 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -20782,7 +20782,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { } window.addEventListener('scroll', () => { // 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 episodeContainers = this.getElementsByClassName('episodeContainer'); const seasonElems = this.getElementsByClassName('seasonElem'); @@ -20822,22 +20822,24 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.renderNewElementsIfNeeded(); }); window.addEventListener('resize', () => { - if (!this.detailsShown) { - const videoPlayer = this.getElementsByClassName('videoPlayer')[0]; - let isFullScreen = false; - if (videoPlayer.children.length > 0) { - isFullScreen = isVideoFullScreen(this); - } - if (this.card && this.movieElems.length > 0 && !isFullScreen) { - if (this.previousPageWidth !== this.card.offsetWidth) { - this.previousPageWidth = this.card.offsetWidth; - this.renderPage(); - const contentbg = this.getElementsByClassName('contentbg'); - this.contentBGHeight = getHeight(contentbg[0]); + if (this.isVisible) { + if (!this.detailsShown) { + const videoPlayer = this.getElementsByClassName('videoPlayer')[0]; + let isFullScreen = false; + if (videoPlayer.children.length > 0) { + isFullScreen = isVideoFullScreen(this); + } + if (this.card && this.movieElems.length > 0 && !isFullScreen) { + if (this.previousPageWidth !== this.card.offsetWidth) { + this.previousPageWidth = this.card.offsetWidth; + this.renderPage(); + const contentbg = this.getElementsByClassName('contentbg'); + this.contentBGHeight = getHeight(contentbg[0]); + } } } + this.renderNewElementsIfNeeded(); } - this.renderNewElementsIfNeeded(); }); if (this.card) { this.previousPageWidth = this.card.offsetWidth; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 16f12e3..6f4c535 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -175,7 +175,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { window.addEventListener('scroll', () => { // 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; const episodeContainers = this.getElementsByClassName('episodeContainer') as HTMLCollectionOf; const seasonElems = this.getElementsByClassName('seasonElem') as HTMLCollectionOf; @@ -215,23 +215,25 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.renderNewElementsIfNeeded(); }); window.addEventListener('resize', () => { - if (!this.detailsShown) { - const videoPlayer = this.getElementsByClassName('videoPlayer')[0] as HTMLElement; - let isFullScreen = false; - if (videoPlayer.children.length > 0) { - isFullScreen = isVideoFullScreen(this); - } + if (this.isVisible) { + if (!this.detailsShown) { + const videoPlayer = this.getElementsByClassName('videoPlayer')[0] as HTMLElement; + let isFullScreen = false; + if (videoPlayer.children.length > 0) { + isFullScreen = isVideoFullScreen(this); + } - if (this.card && this.movieElems.length > 0 && !isFullScreen) { - if (this.previousPageWidth !== this.card.offsetWidth) { - this.previousPageWidth = this.card.offsetWidth; - this.renderPage(); - const contentbg = this.getElementsByClassName('contentbg'); - this.contentBGHeight = getHeight(contentbg[0] as HTMLElement); + if (this.card && this.movieElems.length > 0 && !isFullScreen) { + if (this.previousPageWidth !== this.card.offsetWidth) { + this.previousPageWidth = this.card.offsetWidth; + this.renderPage(); + const contentbg = this.getElementsByClassName('contentbg'); + this.contentBGHeight = getHeight(contentbg[0] as HTMLElement); + } } } + this.renderNewElementsIfNeeded(); } - this.renderNewElementsIfNeeded(); }); if (this.card) {