mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 11:28:23 -07:00
292 lines
8.7 KiB
JavaScript
292 lines
8.7 KiB
JavaScript
define(['libraryBrowser', 'cardBuilder', 'apphost', 'scrollStyles', 'emby-itemscontainer', 'emby-tabs', 'emby-button'], function (libraryBrowser, cardBuilder, appHost) {
|
|
|
|
function enableScrollX() {
|
|
return browserInfo.mobile && AppInfo.enableAppLayouts;
|
|
}
|
|
|
|
function getPortraitShape() {
|
|
return enableScrollX() ? 'overflowPortrait' : 'portrait';
|
|
}
|
|
|
|
function getLimit() {
|
|
|
|
return enableScrollX() ? 12 : 8;
|
|
}
|
|
|
|
function loadRecommendedPrograms(page) {
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
var limit = getLimit();
|
|
if (enableScrollX()) {
|
|
limit *= 2;
|
|
}
|
|
|
|
ApiClient.getLiveTvRecommendedPrograms({
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
IsAiring: true,
|
|
limit: limit,
|
|
ImageTypeLimit: 1,
|
|
EnableImageTypes: "Primary,Thumb,Backdrop",
|
|
EnableTotalRecordCount: false,
|
|
Fields: "ChannelInfo"
|
|
|
|
}).then(function (result) {
|
|
|
|
renderItems(page, result.Items, 'activeProgramItems', 'play');
|
|
Dashboard.hideLoadingMsg();
|
|
});
|
|
}
|
|
|
|
function reload(page) {
|
|
|
|
loadRecommendedPrograms(page);
|
|
|
|
ApiClient.getLiveTvRecommendedPrograms({
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
IsAiring: false,
|
|
HasAired: false,
|
|
limit: getLimit(),
|
|
IsMovie: false,
|
|
IsSports: false,
|
|
IsKids: false,
|
|
IsSeries: true,
|
|
EnableTotalRecordCount: false,
|
|
Fields: "ChannelInfo",
|
|
EnableImageTypes: "Primary,Thumb"
|
|
|
|
}).then(function (result) {
|
|
|
|
renderItems(page, result.Items, 'upcomingProgramItems');
|
|
});
|
|
|
|
ApiClient.getLiveTvRecommendedPrograms({
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
IsAiring: false,
|
|
HasAired: false,
|
|
limit: getLimit(),
|
|
IsMovie: true,
|
|
EnableTotalRecordCount: false,
|
|
Fields: "ChannelInfo",
|
|
EnableImageTypes: "Primary,Thumb"
|
|
|
|
}).then(function (result) {
|
|
|
|
renderItems(page, result.Items, 'upcomingTvMovieItems', null, getPortraitShape());
|
|
});
|
|
|
|
ApiClient.getLiveTvRecommendedPrograms({
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
IsAiring: false,
|
|
HasAired: false,
|
|
limit: getLimit(),
|
|
IsSports: true,
|
|
EnableTotalRecordCount: false,
|
|
Fields: "ChannelInfo",
|
|
EnableImageTypes: "Primary,Thumb"
|
|
|
|
}).then(function (result) {
|
|
|
|
renderItems(page, result.Items, 'upcomingSportsItems');
|
|
});
|
|
|
|
ApiClient.getLiveTvRecommendedPrograms({
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
IsAiring: false,
|
|
HasAired: false,
|
|
limit: getLimit(),
|
|
IsKids: true,
|
|
EnableTotalRecordCount: false,
|
|
Fields: "ChannelInfo",
|
|
EnableImageTypes: "Primary,Thumb"
|
|
|
|
}).then(function (result) {
|
|
|
|
renderItems(page, result.Items, 'upcomingKidsItems');
|
|
});
|
|
}
|
|
|
|
function renderItems(page, items, sectionClass, overlayButton, shape) {
|
|
|
|
var supportsImageAnalysis = appHost.supports('imageanalysis');
|
|
|
|
var html = cardBuilder.getCardsHtml({
|
|
items: items,
|
|
preferThumb: !shape,
|
|
inheritThumb: false,
|
|
shape: shape || (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
showParentTitleOrTitle: true,
|
|
showTitle: false,
|
|
centerText: true,
|
|
coverImage: true,
|
|
overlayText: false,
|
|
lazy: true,
|
|
overlayMoreButton: overlayButton != 'play' && !supportsImageAnalysis,
|
|
overlayPlayButton: overlayButton == 'play',
|
|
allowBottomPadding: !enableScrollX(),
|
|
showAirTime: true,
|
|
showAirDateTime: true,
|
|
showChannelName: true,
|
|
vibrant: true,
|
|
cardLayout: supportsImageAnalysis
|
|
//cardFooterAside: 'logo'
|
|
});
|
|
|
|
var elem = page.querySelector('.' + sectionClass);
|
|
|
|
elem.innerHTML = html;
|
|
ImageLoader.lazyChildren(elem);
|
|
}
|
|
|
|
return function (view, params) {
|
|
|
|
var self = this;
|
|
|
|
self.initTab = function () {
|
|
|
|
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
|
|
|
|
var containers = tabContent.querySelectorAll('.itemsContainer');
|
|
|
|
for (var i = 0, length = containers.length; i < length; i++) {
|
|
if (enableScrollX()) {
|
|
containers[i].classList.add('hiddenScrollX');
|
|
containers[i].classList.remove('vertical-wrap');
|
|
} else {
|
|
containers[i].classList.remove('hiddenScrollX');
|
|
containers[i].classList.add('vertical-wrap');
|
|
}
|
|
}
|
|
};
|
|
|
|
self.renderTab = function () {
|
|
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
|
|
reload(tabContent);
|
|
};
|
|
|
|
var tabControllers = [];
|
|
var renderedTabs = [];
|
|
|
|
var tabControllers = [];
|
|
var renderedTabs = [];
|
|
|
|
function getTabController(page, index, callback) {
|
|
|
|
var depends = [];
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
depends.push('scripts/livetvguide');
|
|
break;
|
|
case 2:
|
|
depends.push('scripts/livetvchannels');
|
|
break;
|
|
case 3:
|
|
depends.push('scripts/livetvrecordings');
|
|
break;
|
|
case 4:
|
|
depends.push('scripts/livetvschedule');
|
|
break;
|
|
case 5:
|
|
depends.push('scripts/livetvseriestimers');
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
require(depends, function (controllerFactory) {
|
|
var tabContent;
|
|
if (index == 0) {
|
|
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
|
|
self.tabContent = tabContent;
|
|
}
|
|
var controller = tabControllers[index];
|
|
if (!controller) {
|
|
tabContent = view.querySelector('.pageTabContent[data-index=\'' + index + '\']');
|
|
controller = index ? new controllerFactory(view, params, tabContent) : self;
|
|
tabControllers[index] = controller;
|
|
|
|
if (controller.initTab) {
|
|
controller.initTab();
|
|
}
|
|
}
|
|
|
|
callback(controller);
|
|
});
|
|
}
|
|
|
|
|
|
function preLoadTab(page, index) {
|
|
|
|
getTabController(page, index, function (controller) {
|
|
if (renderedTabs.indexOf(index) == -1) {
|
|
if (controller.preRender) {
|
|
controller.preRender();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function loadTab(page, index) {
|
|
|
|
getTabController(page, index, function (controller) {
|
|
|
|
if (index === 1) {
|
|
document.body.classList.add('autoScrollY');
|
|
} else {
|
|
document.body.classList.remove('autoScrollY');
|
|
}
|
|
|
|
if (renderedTabs.indexOf(index) == -1) {
|
|
|
|
if (index < 2) {
|
|
renderedTabs.push(index);
|
|
}
|
|
controller.renderTab();
|
|
}
|
|
});
|
|
}
|
|
|
|
var viewTabs = view.querySelector('.libraryViewNav');
|
|
|
|
libraryBrowser.configurePaperLibraryTabs(view, viewTabs, view.querySelectorAll('.pageTabContent'), [0, 2, 3, 4, 5]);
|
|
|
|
viewTabs.addEventListener('beforetabchange', function (e) {
|
|
preLoadTab(view, parseInt(e.detail.selectedTabIndex));
|
|
});
|
|
|
|
viewTabs.addEventListener('tabchange', function (e) {
|
|
loadTab(view, parseInt(e.detail.selectedTabIndex));
|
|
});
|
|
|
|
view.addEventListener('viewbeforehide', function (e) {
|
|
|
|
document.body.classList.remove('autoScrollY');
|
|
});
|
|
|
|
require(["headroom-window"], function (headroom) {
|
|
headroom.add(viewTabs);
|
|
self.headroom = headroom;
|
|
});
|
|
|
|
view.addEventListener('viewdestroy', function (e) {
|
|
|
|
if (self.headroom) {
|
|
self.headroom.remove(viewTabs);
|
|
}
|
|
tabControllers.forEach(function (t) {
|
|
if (t.destroy) {
|
|
t.destroy();
|
|
}
|
|
});
|
|
});
|
|
};
|
|
}); |