(function ($, document) { function getUserViews(userId) { var deferred = $.Deferred(); ApiClient.getUserViews({}, userId).done(function (result) { var items = result.Items; var list = []; for (var i = 0, length = items.length; i < length; i++) { var view = items[i]; list.push(view); if (view.CollectionType == 'livetv') { view.ImageTags = {}; view.icon = 'live-tv'; view.onclick = "LibraryBrowser.showTab('livetv.html', 0);return false;"; var guideView = $.extend({}, view); guideView.Name = Globalize.translate('ButtonGuide'); guideView.ImageTags = {}; guideView.icon = 'dvr'; guideView.url = 'livetv.html?tab=1'; guideView.onclick = "LibraryBrowser.showTab('livetv.html', 1);return false;"; list.push(guideView); var recordedTvView = $.extend({}, view); recordedTvView.Name = Globalize.translate('ButtonRecordedTv'); recordedTvView.ImageTags = {}; recordedTvView.icon = 'video-library'; recordedTvView.url = 'livetv.html?tab=3'; recordedTvView.onclick = "LibraryBrowser.showTab('livetv.html', 3);return false;"; list.push(recordedTvView); } } deferred.resolveWith(null, [list]); }); return deferred.promise(); } function enableScrollX() { return $.browser.mobile && AppInfo.enableAppLayouts; } function getThumbShape() { return enableScrollX() ? 'overflowBackdrop' : 'backdrop'; } function getPortraitShape() { return enableScrollX() ? 'overflowPortrait' : 'portrait'; } function getLibraryButtonsHtml(items) { var html = ""; // "My Library" backgrounds for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; var icon; var backgroundColor = 'rgba(82, 181, 75, 0.9)'; switch (item.CollectionType) { case "movies": icon = "local-movies"; backgroundColor = 'rgba(176, 94, 81, 0.9)'; break; case "music": icon = "library-music"; backgroundColor = 'rgba(217, 145, 67, 0.9)'; break; case "photos": icon = "photo"; backgroundColor = 'rgba(127, 0, 0, 0.9)'; break; case "livetv": icon = "live-tv"; backgroundColor = 'rgba(217, 145, 67, 0.9)'; break; case "tvshows": icon = "live-tv"; backgroundColor = 'rgba(77, 88, 164, 0.9)'; break; case "games": icon = "folder"; backgroundColor = 'rgba(183, 202, 72, 0.9)'; break; case "trailers": icon = "local-movies"; backgroundColor = 'rgba(176, 94, 81, 0.9)'; break; case "homevideos": icon = "video-library"; backgroundColor = 'rgba(110, 52, 32, 0.9)'; break; case "musicvideos": icon = "video-library"; backgroundColor = 'rgba(143, 54, 168, 0.9)'; break; case "books": icon = "folder"; break; case "channels": icon = "folder"; backgroundColor = 'rgba(51, 136, 204, 0.9)'; break; case "playlists": icon = "folder"; break; default: icon = "folder"; break; } var cssClass = 'card smallBackdropCard buttonCard'; if (item.CollectionType) { cssClass += ' ' + item.CollectionType + 'buttonCard'; } var href = item.url || LibraryBrowser.getHref(item); var onclick = item.onclick ? ' onclick="' + item.onclick + '"' : ''; icon = item.icon || icon; html += ''; html += '
'; html += "
"; html += ''; html += '' + item.Name + ''; html += "
"; html += "
"; html += ""; } return html; } function loadlibraryButtons(elem, userId, index) { return getUserViews(userId).done(function (items) { var html = '
'; if (index) { html += '

' + Globalize.translate('HeaderMyMedia') + '

'; } html += '
'; html += getLibraryButtonsHtml(items); html += '
'; elem.innerHTML = html; handleLibraryLinkNavigations(elem); }); } function loadRecentlyAdded(elem, user) { var limit = AppInfo.hasLowImageBandwidth ? 16 : 20; var options = { Limit: limit, Fields: "PrimaryImageAspectRatio,SyncInfo", ImageTypeLimit: 1, EnableImageTypes: "Primary,Backdrop,Thumb" }; return ApiClient.getJSON(ApiClient.getUrl('Users/' + user.Id + '/Items/Latest', options)).done(function (items) { var html = ''; var cardLayout = false; if (items.length) { html += '
'; html += '

' + Globalize.translate('HeaderLatestMedia') + '

'; html += '
'; html += '
'; html += LibraryBrowser.getPosterViewHtml({ items: items, preferThumb: true, shape: 'backdrop', showUnplayedIndicator: false, showChildCountIndicator: true, lazy: true, cardLayout: cardLayout, showTitle: cardLayout, showYear: cardLayout, showDetailsMenu: true, context: 'home' }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadLatestMovies(elem, user) { var options = { Limit: 12, Fields: "PrimaryImageAspectRatio,SyncInfo", ImageTypeLimit: 1, EnableImageTypes: "Primary,Backdrop,Thumb", IncludeItemTypes: "Movie" }; return ApiClient.getJSON(ApiClient.getUrl('Users/' + user.Id + '/Items/Latest', options)).done(function (items) { var html = ''; var scrollX = enableScrollX(); if (items.length) { html += '

' + Globalize.translate('HeaderLatestMovies') + '

'; if (scrollX) { html += '
'; } else { html += '
'; } html += LibraryBrowser.getPosterViewHtml({ items: items, shape: getPortraitShape(), showUnplayedIndicator: false, showChildCountIndicator: true, lazy: true, context: 'home', centerText: true }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadLatestEpisodes(elem, user) { var options = { Limit: 12, Fields: "PrimaryImageAspectRatio,SyncInfo", ImageTypeLimit: 1, EnableImageTypes: "Primary,Backdrop,Thumb", IncludeItemTypes: "Episode" }; return ApiClient.getJSON(ApiClient.getUrl('Users/' + user.Id + '/Items/Latest', options)).done(function (items) { var html = ''; var scrollX = enableScrollX(); if (items.length) { html += '

' + Globalize.translate('HeaderLatestEpisodes') + '

'; if (scrollX) { html += '
'; } else { html += '
'; } html += LibraryBrowser.getPosterViewHtml({ items: items, preferThumb: true, shape: getThumbShape(), showUnplayedIndicator: false, showChildCountIndicator: true, lazy: true, context: 'home' }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadLatestChannelMedia(elem, userId) { var screenWidth = $(window).width(); var options = { Limit: screenWidth >= 2400 ? 10 : (screenWidth >= 1600 ? 10 : (screenWidth >= 1440 ? 8 : (screenWidth >= 800 ? 7 : 6))), Fields: "PrimaryImageAspectRatio,SyncInfo", Filters: "IsUnplayed", UserId: userId }; return ApiClient.getJSON(ApiClient.getUrl("Channels/Items/Latest", options)).done(function (result) { var html = ''; if (result.Items.length) { html += '

' + Globalize.translate('HeaderLatestChannelMedia') + '

'; html += '
'; html += LibraryBrowser.getPosterViewHtml({ items: result.Items, preferThumb: true, shape: 'auto', showTitle: true, centerText: true, lazy: true, showDetailsMenu: true }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadLibraryTiles(elem, user, shape, index, autoHideOnMobile, showTitles) { return getUserViews(user.Id).done(function (items) { var html = ''; if (autoHideOnMobile) { html += '
'; } else { html += '
'; } if (items.length) { var cssClass = index !== 0 ? 'listHeader' : 'listHeader'; html += '
'; html += '

' + Globalize.translate('HeaderMyMedia') + '

'; html += '
'; html += '
'; html += LibraryBrowser.getPosterViewHtml({ items: items, shape: shape, showTitle: showTitles, centerText: true, lazy: true, autoThumb: true, transition: false }); html += '
'; } html += '
'; if (autoHideOnMobile) { html += '
'; html += getLibraryButtonsHtml(items); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus({ showDetailsMenu: false }); handleLibraryLinkNavigations(elem); }); } function loadResume(elem, userId) { var screenWidth = $(window).width(); var options = { SortBy: "DatePlayed", SortOrder: "Descending", MediaTypes: "Video", Filters: "IsResumable", Limit: screenWidth >= 1920 ? 10 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 9 : 6)), Recursive: true, Fields: "PrimaryImageAspectRatio,SyncInfo", CollapseBoxSetItems: false, ExcludeLocationTypes: "Virtual", ImageTypeLimit: 1, EnableImageTypes: "Primary,Backdrop,Banner,Thumb" }; return ApiClient.getItems(userId, options).done(function (result) { var html = ''; if (result.Items.length) { html += '

' + Globalize.translate('HeaderResume') + '

'; if (enableScrollX()) { html += '
'; } else { html += '
'; } html += LibraryBrowser.getPosterViewHtml({ items: result.Items, preferThumb: true, shape: getThumbShape(), overlayText: false, showTitle: true, showParentTitle: true, lazy: true, showDetailsMenu: true, overlayPlayButton: true, context: 'home', centerText: true }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadNextUp(elem, userId) { var query = { Limit: 20, Fields: "PrimaryImageAspectRatio,SeriesInfo,DateCreated,SyncInfo", UserId: userId, ImageTypeLimit: 1, EnableImageTypes: "Primary,Backdrop,Banner,Thumb" }; ApiClient.getNextUpEpisodes(query).done(function (result) { var html = ''; if (result.Items.length) { html += '

' + Globalize.translate('HeaderNextUp') + '

'; if (enableScrollX()) { html += '
'; } else { html += '
'; } html += LibraryBrowser.getPosterViewHtml({ items: result.Items, preferThumb: true, shape: getThumbShape(), overlayText: false, showTitle: true, showParentTitle: true, lazy: true, overlayPlayButton: true, context: 'home', centerText: true }); html += '
'; } elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function handleLibraryLinkNavigations(elem) { $('a', elem).on('click', function () { var card = this; if (!this.classList.contains('card')) { card = $(this).parents('.card')[0]; } var textElem = $('.cardText', card); var text = textElem.text(); LibraryMenu.setTitle(text); }); } function loadLatestChannelItems(elem, userId, options) { options = $.extend(options || {}, { UserId: userId, SupportsLatestItems: true }); return ApiClient.getJSON(ApiClient.getUrl("Channels", options)).done(function (result) { var channels = result.Items; var channelsHtml = channels.map(function (c) { return '
'; }).join(''); elem.innerHTML = channelsHtml; for (var i = 0, length = channels.length; i < length; i++) { var channel = channels[i]; loadLatestChannelItemsFromChannel(elem, channel, i); } }); } function loadLatestChannelItemsFromChannel(page, channel, index) { var screenWidth = $(window).width(); var options = { Limit: screenWidth >= 1600 ? 10 : (screenWidth >= 1440 ? 5 : (screenWidth >= 800 ? 6 : 6)), Fields: "PrimaryImageAspectRatio,SyncInfo", Filters: "IsUnplayed", UserId: Dashboard.getCurrentUserId(), ChannelIds: channel.Id }; ApiClient.getJSON(ApiClient.getUrl("Channels/Items/Latest", options)).done(function (result) { var html = ''; if (result.Items.length) { html += '
'; html += '
'; var text = Globalize.translate('HeaderLatestFromChannel').replace('{0}', channel.Name); html += '

' + text + '

'; html += '' + Globalize.translate('ButtonMore') + ''; html += '
'; html += '
'; html += LibraryBrowser.getPosterViewHtml({ items: result.Items, shape: 'autohome', defaultShape: 'square', showTitle: true, centerText: true, lazy: true, showDetailsMenu: true, overlayPlayButton: true }); html += '
'; html += '
'; } var elem = page.querySelector('#channel' + channel.Id + ''); elem.innerHTML = html; ImageLoader.lazyChildren(elem); $(elem).createCardMenus(); }); } function loadLatestLiveTvRecordings(elem, userId, index) { return ApiClient.getLiveTvRecordings({ userId: userId, limit: 5, IsInProgress: false }).done(function (result) { var html = ''; if (result.Items.length) { var cssClass = index !== 0 ? 'listHeader' : 'listHeader'; html += '
'; html += '

' + Globalize.translate('HeaderLatestTvRecordings') + '

'; html += '' + Globalize.translate('ButtonMore') + ''; html += '
'; } html += LibraryBrowser.getPosterViewHtml({ items: result.Items, shape: "autohome", showTitle: true, showParentTitle: true, coverImage: true, lazy: true, showDetailsMenu: true, centerText: true }); elem.innerHTML = html; ImageLoader.lazyChildren(elem); }); } window.Sections = { loadRecentlyAdded: loadRecentlyAdded, loadLatestChannelMedia: loadLatestChannelMedia, loadLibraryTiles: loadLibraryTiles, loadResume: loadResume, loadNextUp: loadNextUp, loadLatestChannelItems: loadLatestChannelItems, loadLatestLiveTvRecordings: loadLatestLiveTvRecordings, loadlibraryButtons: loadlibraryButtons, loadLatestMovies: loadLatestMovies, loadLatestEpisodes: loadLatestEpisodes }; })(jQuery, document);