1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #1725 from matjaz321/livetvsuggested-to-es6-module-migration

Migrated livetvsuggested.js to es6 module
This commit is contained in:
Anthony Lavado 2020-08-12 15:58:19 -04:00 committed by GitHub
commit 021e75f3be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 355 additions and 349 deletions

View file

@ -259,6 +259,7 @@
"src/controllers/searchpage.js", "src/controllers/searchpage.js",
"src/controllers/livetv/livetvguide.js", "src/controllers/livetv/livetvguide.js",
"src/controllers/livetvtuner.js", "src/controllers/livetvtuner.js",
"src/controllers/livetv/livetvsuggested.js",
"src/controllers/livetvstatus.js", "src/controllers/livetvstatus.js",
"src/controllers/livetvguideprovider.js", "src/controllers/livetvguideprovider.js",
"src/controllers/livetvsettings.js", "src/controllers/livetvsettings.js",

View file

@ -1,8 +1,15 @@
define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize', 'libraryBrowser', 'mainTabsManager', 'cardBuilder', 'apphost', 'imageLoader', 'scrollStyles', 'emby-itemscontainer', 'emby-tabs', 'emby-button'], function (layoutManager, userSettings, inputManager, loading, globalize, libraryBrowser, mainTabsManager, cardBuilder, appHost, imageLoader) { import layoutManager from 'layoutManager';
'use strict'; import * as userSettings from 'userSettings';
import inputManager from 'inputManager';
loading = loading.default || loading; import loading from 'loading';
layoutManager = layoutManager.default || layoutManager; import globalize from 'globalize';
import * as mainTabsManager from 'mainTabsManager';
import cardBuilder from 'cardBuilder';
import imageLoader from 'imageLoader';
import 'scrollStyles';
import 'emby-itemscontainer';
import 'emby-tabs';
import 'emby-button';
function enableScrollX() { function enableScrollX() {
return !layoutManager.desktop; return !layoutManager.desktop;
@ -32,7 +39,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
function loadRecommendedPrograms(page) { function loadRecommendedPrograms(page) {
loading.show(); loading.show();
var limit = getLimit(); let limit = getLimit();
if (enableScrollX()) { if (enableScrollX()) {
limit *= 2; limit *= 2;
@ -53,7 +60,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
}); });
loading.hide(); loading.hide();
require(['autoFocuser'], function (autoFocuser) { import('autoFocuser').then(({default: autoFocuser}) => {
autoFocuser.autoFocus(page); autoFocuser.autoFocus(page);
}); });
}); });
@ -133,7 +140,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
} }
function renderItems(page, items, sectionClass, overlayButton, cardOptions) { function renderItems(page, items, sectionClass, overlayButton, cardOptions) {
var html = cardBuilder.getCardsHtml(Object.assign({ const html = cardBuilder.getCardsHtml(Object.assign({
items: items, items: items,
preferThumb: 'auto', preferThumb: 'auto',
inheritThumb: false, inheritThumb: false,
@ -152,7 +159,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
showAirTime: true, showAirTime: true,
showAirDateTime: true showAirDateTime: true
}, cardOptions || {})); }, cardOptions || {}));
var elem = page.querySelector('.' + sectionClass); const elem = page.querySelector('.' + sectionClass);
elem.innerHTML = html; elem.innerHTML = html;
imageLoader.lazyChildren(elem); imageLoader.lazyChildren(elem);
} }
@ -199,7 +206,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
return 0; return 0;
} }
return function (view, params) { export default function (view, params) {
function enableFullRender() { function enableFullRender() {
return new Date().getTime() - lastFullRender > 3e5; return new Date().getTime() - lastFullRender > 3e5;
} }
@ -209,7 +216,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
} }
function onTabChange(evt) { function onTabChange(evt) {
var previousTabController = tabControllers[parseInt(evt.detail.previousIndex)]; const previousTabController = tabControllers[parseInt(evt.detail.previousIndex)];
if (previousTabController && previousTabController.onHide) { if (previousTabController && previousTabController.onHide) {
previousTabController.onHide(); previousTabController.onHide();
@ -227,48 +234,47 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
} }
function getTabController(page, index, callback) { function getTabController(page, index, callback) {
var depends = []; let depends;
// TODO int is a little hard to read // TODO int is a little hard to read
switch (index) { switch (index) {
case 0: case 0:
depends = 'controllers/livetv/livetvsuggested';
break; break;
case 1: case 1:
depends.push('controllers/livetv/livetvguide'); depends = 'controllers/livetv/livetvguide';
break; break;
case 2: case 2:
depends.push('controllers/livetv/livetvchannels'); depends = 'controllers/livetv/livetvchannels';
break; break;
case 3: case 3:
depends.push('controllers/livetv/livetvrecordings'); depends = 'controllers/livetv/livetvrecordings';
break; break;
case 4: case 4:
depends.push('controllers/livetv/livetvschedule'); depends = 'controllers/livetv/livetvschedule';
break; break;
case 5: case 5:
depends.push('controllers/livetv/livetvseriestimers'); depends = 'controllers/livetv/livetvseriestimers';
break; break;
} }
require(depends, function (controllerFactory) { import(depends).then(({default: controllerFactory}) => {
controllerFactory = controllerFactory.default || controllerFactory; let tabContent;
var tabContent; if (index === 0) {
tabContent = view.querySelector(`.pageTabContent[data-index="${index}"]`);
if (index == 0) {
tabContent = view.querySelector(".pageTabContent[data-index='" + index + "']");
self.tabContent = tabContent; self.tabContent = tabContent;
} }
var controller = tabControllers[index]; let controller = tabControllers[index];
if (!controller) { if (!controller) {
tabContent = view.querySelector(".pageTabContent[data-index='" + index + "']"); tabContent = view.querySelector(`.pageTabContent[data-index="${index}"]`);
if (index === 0) { if (index === 0) {
controller = self; controller = self;
@ -304,7 +310,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
getTabController(page, index, function (controller) { getTabController(page, index, function (controller) {
initialTabIndex = null; initialTabIndex = null;
if (renderedTabs.indexOf(index) == -1) { if (renderedTabs.indexOf(index) === -1) {
if (index === 1) { if (index === 1) {
renderedTabs.push(index); renderedTabs.push(index);
} }
@ -325,13 +331,13 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
} }
} }
var isViewRestored; let isViewRestored;
var self = this; const self = this;
var currentTabIndex = parseInt(params.tab || getDefaultTabIndex('livetv')); let currentTabIndex = parseInt(params.tab || getDefaultTabIndex('livetv'));
var initialTabIndex = currentTabIndex; let initialTabIndex = currentTabIndex;
var lastFullRender = 0; let lastFullRender = 0;
[].forEach.call(view.querySelectorAll('.sectionTitleTextButton-programs'), function (link) { [].forEach.call(view.querySelectorAll('.sectionTitleTextButton-programs'), function (link) {
var href = link.href; const href = link.href;
if (href) { if (href) {
link.href = href + '&serverId=' + ApiClient.serverId(); link.href = href + '&serverId=' + ApiClient.serverId();
@ -339,16 +345,16 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
}); });
self.initTab = function () { self.initTab = function () {
var tabContent = view.querySelector(".pageTabContent[data-index='0']"); const tabContent = view.querySelector('.pageTabContent[data-index="0"]');
var containers = tabContent.querySelectorAll('.itemsContainer'); const containers = tabContent.querySelectorAll('.itemsContainer');
for (var i = 0, length = containers.length; i < length; i++) { for (let i = 0, length = containers.length; i < length; i++) {
setScrollClasses(containers[i], enableScrollX()); setScrollClasses(containers[i], enableScrollX());
} }
}; };
self.renderTab = function () { self.renderTab = function () {
var tabContent = view.querySelector(".pageTabContent[data-index='0']"); const tabContent = view.querySelector('.pageTabContent[data-index="0"]');
if (enableFullRender()) { if (enableFullRender()) {
reload(tabContent, true); reload(tabContent, true);
@ -358,9 +364,9 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
} }
}; };
var currentTabController; let currentTabController;
var tabControllers = []; const tabControllers = [];
var renderedTabs = []; const renderedTabs = [];
view.addEventListener('viewbeforeshow', function (evt) { view.addEventListener('viewbeforeshow', function (evt) {
isViewRestored = evt.detail.isRestored; isViewRestored = evt.detail.isRestored;
initTabs(); initTabs();
@ -374,19 +380,18 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
inputManager.on(window, onInputCommand); inputManager.on(window, onInputCommand);
}); });
view.addEventListener('viewbeforehide', function (e) { view.addEventListener('viewbeforehide', function () {
if (currentTabController && currentTabController.onHide) { if (currentTabController && currentTabController.onHide) {
currentTabController.onHide(); currentTabController.onHide();
} }
inputManager.off(window, onInputCommand); inputManager.off(window, onInputCommand);
}); });
view.addEventListener('viewdestroy', function (evt) { view.addEventListener('viewdestroy', function () {
tabControllers.forEach(function (tabController) { tabControllers.forEach(function (tabController) {
if (tabController.destroy) { if (tabController.destroy) {
tabController.destroy(); tabController.destroy();
} }
}); });
}); });
}; }
});