import optimizations for site.js

transfered pageIdOn and pageClassOn to clientUtils
This commit is contained in:
vitorsemeano 2020-11-09 00:14:33 +00:00
parent 5d94812220
commit 4e11e3ba66
9 changed files with 86 additions and 93 deletions

View file

@ -4,6 +4,7 @@ import dom from '../../scripts/dom';
import globalize from '../../scripts/globalize'; import globalize from '../../scripts/globalize';
import '../../elements/emby-button/emby-button'; import '../../elements/emby-button/emby-button';
import confirm from '../../components/confirm/confirm'; import confirm from '../../components/confirm/confirm';
import { pageIdOn } from '../../scripts/clientUtils';
/* eslint-disable indent */ /* eslint-disable indent */

View file

@ -7,7 +7,7 @@ import dom from '../../scripts/dom';
import imageHelper from '../../scripts/imagehelper'; import imageHelper from '../../scripts/imagehelper';
import '../../components/cardbuilder/card.css'; import '../../components/cardbuilder/card.css';
import '../../elements/emby-itemrefreshindicator/emby-itemrefreshindicator'; import '../../elements/emby-itemrefreshindicator/emby-itemrefreshindicator';
import Dashboard from '../../scripts/clientUtils'; import Dashboard, { pageClassOn, pageIdOn } from '../../scripts/clientUtils';
import confirm from '../../components/confirm/confirm'; import confirm from '../../components/confirm/confirm';
/* eslint-disable indent */ /* eslint-disable indent */

View file

@ -4,7 +4,7 @@ import dom from '../../../../scripts/dom';
import globalize from '../../../../scripts/globalize'; import globalize from '../../../../scripts/globalize';
import '../../../../components/cardbuilder/card.css'; import '../../../../components/cardbuilder/card.css';
import '../../../../elements/emby-button/emby-button'; import '../../../../elements/emby-button/emby-button';
import Dashboard from '../../../../scripts/clientUtils'; import Dashboard, { pageIdOn } from '../../../../scripts/clientUtils';
import confirm from '../../../../components/confirm/confirm'; import confirm from '../../../../components/confirm/confirm';
function deletePlugin(page, uniqueid, name) { function deletePlugin(page, uniqueid, name) {

View file

@ -8,7 +8,7 @@ import '../../../components/cardbuilder/card.css';
import '../../../elements/emby-button/emby-button'; import '../../../elements/emby-button/emby-button';
import '../../../components/indicators/indicators.css'; import '../../../components/indicators/indicators.css';
import '../../../assets/css/flexstyles.scss'; import '../../../assets/css/flexstyles.scss';
import Dashboard from '../../../scripts/clientUtils'; import Dashboard, { pageIdOn } from '../../../scripts/clientUtils';
import confirm from '../../../components/confirm/confirm'; import confirm from '../../../components/confirm/confirm';
/* eslint-disable indent */ /* eslint-disable indent */

View file

@ -1,7 +1,7 @@
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import loading from '../components/loading/loading'; import loading from '../components/loading/loading';
import globalize from '../scripts/globalize'; import globalize from '../scripts/globalize';
import Dashboard from '../scripts/clientUtils'; import Dashboard, { pageIdOn } from '../scripts/clientUtils';
function onListingsSubmitted() { function onListingsSubmitted() {
Dashboard.navigate('livetvstatus.html'); Dashboard.navigate('livetvstatus.html');

View file

@ -1,6 +1,7 @@
import backdrop from '../components/backdrop/backdrop'; import backdrop from '../components/backdrop/backdrop';
import * as userSettings from './settings/userSettings'; import * as userSettings from './settings/userSettings';
import libraryMenu from './libraryMenu'; import libraryMenu from './libraryMenu';
import { pageClassOn } from './clientUtils';
const cache = {}; const cache = {};

View file

@ -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 = { const Dashboard = {
alert, alert,
capabilities, capabilities,

View file

@ -15,7 +15,7 @@ import '../elements/emby-button/paper-icon-button-light';
import 'material-design-icons-iconfont'; import 'material-design-icons-iconfont';
import '../assets/css/scrollstyles.css'; import '../assets/css/scrollstyles.css';
import '../assets/css/flexstyles.scss'; import '../assets/css/flexstyles.scss';
import Dashboard from './clientUtils'; import Dashboard, { pageClassOn } from './clientUtils';
import ServerConnections from '../components/ServerConnections'; import ServerConnections from '../components/ServerConnections';
import Headroom from 'headroom.js'; import Headroom from 'headroom.js';

View file

@ -20,6 +20,16 @@ import { getPlugins } from './settings/webSettings';
import { pluginManager } from '../components/pluginManager'; import { pluginManager } from '../components/pluginManager';
import packageManager from '../components/packageManager'; import packageManager from '../components/packageManager';
import { appRouter } from '../components/appRouter'; 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 // TODO: Move this elsewhere
window.getWindowLocationSearch = function(win) { window.getWindowLocationSearch = function(win) {
@ -50,28 +60,6 @@ window.getParameterByName = function(name, url) {
return decodeURIComponent(results[1].replace(/\+/g, ' ')); 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') { if (window.appMode === 'cordova' || window.appMode === 'android' || window.appMode === 'standalone') {
AppInfo.isNativeApp = true; AppInfo.isNativeApp = true;
} }
@ -153,7 +141,7 @@ function loadPlugins() {
Promise.all(list.map((plugin) => { Promise.all(list.map((plugin) => {
return pluginManager.loadPlugin(import(/* webpackChunkName: "[request]" */ `../plugins/${plugin}`)); return pluginManager.loadPlugin(import(/* webpackChunkName: "[request]" */ `../plugins/${plugin}`));
})) }))
.then(function (pluginPromises) { .then(function () {
console.debug('finished loading plugins'); console.debug('finished loading plugins');
}) })
.catch(() => console.debug('failed loading plugins') .catch(() => console.debug('failed loading plugins')
@ -175,79 +163,62 @@ function onAppReady() {
import('../assets/css/ios.scss'); import('../assets/css/ios.scss');
} }
Promise.all([ appRouter.start({
import('../elements/emby-button/emby-button'), click: false,
import('./autoThemes'), hashbang: true
import('./libraryMenu'), });
import('./routes')
])
.then(() => {
appRouter.start({
click: false,
hashbang: true
});
import('../components/themeMediaPlayer'); if (!browser.tv && !browser.xboxOne && !browser.ps4) {
import('./autoBackdrops'); import('../components/nowPlayingBar/nowPlayingBar');
}
if (!browser.tv && !browser.xboxOne && !browser.ps4) { if (appHost.supports('remotecontrol')) {
import('../components/nowPlayingBar/nowPlayingBar'); import('../components/playback/playerSelectionMenu');
} import('../components/playback/remotecontrolautoplay');
}
if (appHost.supports('remotecontrol')) { if (!appHost.supports('physicalvolumecontrol') || browser.touch) {
import('../components/playback/playerSelectionMenu'); import('../components/playback/volumeosd');
import('../components/playback/remotecontrolautoplay'); }
}
import('../libraries/screensavermanager'); /* eslint-disable-next-line compat/compat */
if (navigator.mediaSession || window.NativeShell) {
import('../components/playback/mediasession');
}
if (!appHost.supports('physicalvolumecontrol') || browser.touch) { if (!browser.tv && !browser.xboxOne) {
import('../components/playback/volumeosd'); import('../components/playback/playbackorientation');
} registerServiceWorker();
/* eslint-disable-next-line compat/compat */ if (window.Notification) {
if (navigator.mediaSession || window.NativeShell) { import('../components/notifications/notifications');
import('../components/playback/mediasession'); }
} }
import('./serverNotifications'); const apiClient = ServerConnections.currentApiClient();
if (apiClient) {
if (!browser.tv && !browser.xboxOne) { fetch(apiClient.getUrl('Branding/Css'))
import('../components/playback/playbackorientation'); .then(function(response) {
registerServiceWorker(); if (!response.ok) {
throw new Error(response.status + ' ' + response.statusText);
if (window.Notification) {
import('../components/notifications/notifications');
} }
} return response.text();
})
import('../components/playback/playerSelectionMenu'); .then(function(css) {
let style = document.querySelector('#cssBranding');
const apiClient = ServerConnections.currentApiClient(); if (!style) {
if (apiClient) { // Inject the branding css as a dom element in body so it will take
fetch(apiClient.getUrl('Branding/Css')) // precedence over other stylesheets
.then(function(response) { style = document.createElement('style');
if (!response.ok) { style.id = 'cssBranding';
throw new Error(response.status + ' ' + response.statusText); document.body.appendChild(style);
} }
return response.text(); style.textContent = css;
}) })
.then(function(css) { .catch(function(err) {
let style = document.querySelector('#cssBranding'); console.warn('Error applying custom css', err);
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() { function registerServiceWorker() {