diff --git a/src/controllers/dashboard/apikeys.js b/src/controllers/dashboard/apikeys.js index 5dfe95c132..fcee86f827 100644 --- a/src/controllers/dashboard/apikeys.js +++ b/src/controllers/dashboard/apikeys.js @@ -4,6 +4,7 @@ import dom from '../../scripts/dom'; import globalize from '../../scripts/globalize'; import '../../elements/emby-button/emby-button'; import confirm from '../../components/confirm/confirm'; +import { pageIdOn } from '../../scripts/clientUtils'; /* eslint-disable indent */ diff --git a/src/controllers/dashboard/library.js b/src/controllers/dashboard/library.js index ed45ff1308..8bac92d5d1 100644 --- a/src/controllers/dashboard/library.js +++ b/src/controllers/dashboard/library.js @@ -7,7 +7,7 @@ import dom from '../../scripts/dom'; import imageHelper from '../../scripts/imagehelper'; import '../../components/cardbuilder/card.css'; import '../../elements/emby-itemrefreshindicator/emby-itemrefreshindicator'; -import Dashboard from '../../scripts/clientUtils'; +import Dashboard, { pageClassOn, pageIdOn } from '../../scripts/clientUtils'; import confirm from '../../components/confirm/confirm'; /* eslint-disable indent */ diff --git a/src/controllers/dashboard/plugins/installed/index.js b/src/controllers/dashboard/plugins/installed/index.js index 5ff7a5d462..d224268975 100644 --- a/src/controllers/dashboard/plugins/installed/index.js +++ b/src/controllers/dashboard/plugins/installed/index.js @@ -4,7 +4,7 @@ import dom from '../../../../scripts/dom'; import globalize from '../../../../scripts/globalize'; import '../../../../components/cardbuilder/card.css'; import '../../../../elements/emby-button/emby-button'; -import Dashboard from '../../../../scripts/clientUtils'; +import Dashboard, { pageIdOn } from '../../../../scripts/clientUtils'; import confirm from '../../../../components/confirm/confirm'; function deletePlugin(page, uniqueid, name) { diff --git a/src/controllers/dashboard/users/userprofilespage.js b/src/controllers/dashboard/users/userprofilespage.js index 1a38beff2b..a88393d731 100644 --- a/src/controllers/dashboard/users/userprofilespage.js +++ b/src/controllers/dashboard/users/userprofilespage.js @@ -8,7 +8,7 @@ import '../../../components/cardbuilder/card.css'; import '../../../elements/emby-button/emby-button'; import '../../../components/indicators/indicators.css'; import '../../../assets/css/flexstyles.scss'; -import Dashboard from '../../../scripts/clientUtils'; +import Dashboard, { pageIdOn } from '../../../scripts/clientUtils'; import confirm from '../../../components/confirm/confirm'; /* eslint-disable indent */ diff --git a/src/controllers/livetvguideprovider.js b/src/controllers/livetvguideprovider.js index c4e2d870f6..ecdb186e9f 100644 --- a/src/controllers/livetvguideprovider.js +++ b/src/controllers/livetvguideprovider.js @@ -1,7 +1,7 @@ import { Events } from 'jellyfin-apiclient'; import loading from '../components/loading/loading'; import globalize from '../scripts/globalize'; -import Dashboard from '../scripts/clientUtils'; +import Dashboard, { pageIdOn } from '../scripts/clientUtils'; function onListingsSubmitted() { Dashboard.navigate('livetvstatus.html'); diff --git a/src/scripts/autoBackdrops.js b/src/scripts/autoBackdrops.js index 0ecd583f45..c0967a3bd8 100644 --- a/src/scripts/autoBackdrops.js +++ b/src/scripts/autoBackdrops.js @@ -1,6 +1,7 @@ import backdrop from '../components/backdrop/backdrop'; import * as userSettings from './settings/userSettings'; import libraryMenu from './libraryMenu'; +import { pageClassOn } from './clientUtils'; const cache = {}; diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 0f75975f40..ec0a0e784f 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -158,6 +158,26 @@ export function confirm(message, title, callback) { }); } +export const pageClassOn = function(eventName, className, fn) { + document.addEventListener(eventName, function (event) { + const target = event.target; + + if (target.classList.contains(className)) { + fn.call(target, event); + } + }); +}; + +export const pageIdOn = function(eventName, id, fn) { + document.addEventListener(eventName, function (event) { + const target = event.target; + + if (target.id === id) { + fn.call(target, event); + } + }); +}; + const Dashboard = { alert, capabilities, diff --git a/src/scripts/libraryMenu.js b/src/scripts/libraryMenu.js index 1bfef52f50..5c72685749 100644 --- a/src/scripts/libraryMenu.js +++ b/src/scripts/libraryMenu.js @@ -15,7 +15,7 @@ import '../elements/emby-button/paper-icon-button-light'; import 'material-design-icons-iconfont'; import '../assets/css/scrollstyles.css'; import '../assets/css/flexstyles.scss'; -import Dashboard from './clientUtils'; +import Dashboard, { pageClassOn } from './clientUtils'; import ServerConnections from '../components/ServerConnections'; import Headroom from 'headroom.js'; diff --git a/src/scripts/site.js b/src/scripts/site.js index 77dc1fe866..d4b4dab527 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -20,6 +20,16 @@ import { getPlugins } from './settings/webSettings'; import { pluginManager } from '../components/pluginManager'; import packageManager from '../components/packageManager'; import { appRouter } from '../components/appRouter'; +import '../elements/emby-button/emby-button'; +import './autoThemes'; +import './libraryMenu'; +import './routes'; +import '../components/themeMediaPlayer'; +import './autoBackdrops'; +import { pageClassOn } from './clientUtils'; +import '../libraries/screensavermanager'; +import './serverNotifications'; +import '../components/playback/playerSelectionMenu'; // TODO: Move this elsewhere window.getWindowLocationSearch = function(win) { @@ -50,28 +60,6 @@ window.getParameterByName = function(name, url) { return decodeURIComponent(results[1].replace(/\+/g, ' ')); }; -// TODO: Move this elsewhere -window.pageClassOn = function(eventName, className, fn) { - document.addEventListener(eventName, function (event) { - const target = event.target; - - if (target.classList.contains(className)) { - fn.call(target, event); - } - }); -}; - -// TODO: Move this elsewhere -window.pageIdOn = function(eventName, id, fn) { - document.addEventListener(eventName, function (event) { - const target = event.target; - - if (target.id === id) { - fn.call(target, event); - } - }); -}; - if (window.appMode === 'cordova' || window.appMode === 'android' || window.appMode === 'standalone') { AppInfo.isNativeApp = true; } @@ -153,7 +141,7 @@ function loadPlugins() { Promise.all(list.map((plugin) => { return pluginManager.loadPlugin(import(/* webpackChunkName: "[request]" */ `../plugins/${plugin}`)); })) - .then(function (pluginPromises) { + .then(function () { console.debug('finished loading plugins'); }) .catch(() => console.debug('failed loading plugins') @@ -175,79 +163,62 @@ function onAppReady() { import('../assets/css/ios.scss'); } - Promise.all([ - import('../elements/emby-button/emby-button'), - import('./autoThemes'), - import('./libraryMenu'), - import('./routes') - ]) - .then(() => { - appRouter.start({ - click: false, - hashbang: true - }); + appRouter.start({ + click: false, + hashbang: true + }); - import('../components/themeMediaPlayer'); - import('./autoBackdrops'); + if (!browser.tv && !browser.xboxOne && !browser.ps4) { + import('../components/nowPlayingBar/nowPlayingBar'); + } - if (!browser.tv && !browser.xboxOne && !browser.ps4) { - import('../components/nowPlayingBar/nowPlayingBar'); - } + if (appHost.supports('remotecontrol')) { + import('../components/playback/playerSelectionMenu'); + import('../components/playback/remotecontrolautoplay'); + } - if (appHost.supports('remotecontrol')) { - import('../components/playback/playerSelectionMenu'); - import('../components/playback/remotecontrolautoplay'); - } + if (!appHost.supports('physicalvolumecontrol') || browser.touch) { + import('../components/playback/volumeosd'); + } - import('../libraries/screensavermanager'); + /* eslint-disable-next-line compat/compat */ + if (navigator.mediaSession || window.NativeShell) { + import('../components/playback/mediasession'); + } - if (!appHost.supports('physicalvolumecontrol') || browser.touch) { - import('../components/playback/volumeosd'); - } + if (!browser.tv && !browser.xboxOne) { + import('../components/playback/playbackorientation'); + registerServiceWorker(); - /* eslint-disable-next-line compat/compat */ - if (navigator.mediaSession || window.NativeShell) { - import('../components/playback/mediasession'); - } + if (window.Notification) { + import('../components/notifications/notifications'); + } + } - import('./serverNotifications'); - - if (!browser.tv && !browser.xboxOne) { - import('../components/playback/playbackorientation'); - registerServiceWorker(); - - if (window.Notification) { - import('../components/notifications/notifications'); + const apiClient = ServerConnections.currentApiClient(); + if (apiClient) { + fetch(apiClient.getUrl('Branding/Css')) + .then(function(response) { + if (!response.ok) { + throw new Error(response.status + ' ' + response.statusText); } - } - - import('../components/playback/playerSelectionMenu'); - - const apiClient = ServerConnections.currentApiClient(); - if (apiClient) { - fetch(apiClient.getUrl('Branding/Css')) - .then(function(response) { - if (!response.ok) { - throw new Error(response.status + ' ' + response.statusText); - } - return response.text(); - }) - .then(function(css) { - let style = document.querySelector('#cssBranding'); - if (!style) { - // Inject the branding css as a dom element in body so it will take - // precedence over other stylesheets - style = document.createElement('style'); - style.id = 'cssBranding'; - document.body.appendChild(style); - } - style.textContent = css; - }) - .catch(function(err) { - console.warn('Error applying custom css', err); - }); - } - }); + return response.text(); + }) + .then(function(css) { + let style = document.querySelector('#cssBranding'); + if (!style) { + // Inject the branding css as a dom element in body so it will take + // precedence over other stylesheets + style = document.createElement('style'); + style.id = 'cssBranding'; + document.body.appendChild(style); + } + style.textContent = css; + }) + .catch(function(err) { + console.warn('Error applying custom css', err); + }); + } } function registerServiceWorker() {