diff --git a/src/components/favoriteitems.js b/src/components/favoriteitems.js index 396d4d3c22..05a8580e61 100644 --- a/src/components/favoriteitems.js +++ b/src/components/favoriteitems.js @@ -1,20 +1,32 @@ -define(["loading", "libraryBrowser", "cardBuilder", "dom", "apphost", "imageLoader", "globalize", "layoutManager", "scrollStyles", "emby-itemscontainer"], function(loading, libraryBrowser, cardBuilder, dom, appHost, imageLoader, globalize, layoutManager) { +define(["loading", "libraryBrowser", "cardBuilder", "dom", "apphost", "imageLoader", "globalize", "layoutManager", "scrollStyles", "emby-itemscontainer"], function (loading, libraryBrowser, cardBuilder, dom, appHost, imageLoader, globalize, layoutManager) { "use strict"; function enableScrollX() { - return !layoutManager.desktop + return !layoutManager.desktop; } function getThumbShape() { - return enableScrollX() ? "overflowBackdrop" : "backdrop" + if (enableScrollX()) { + return "overflowBackdrop"; + } + + return "backdrop"; } function getPosterShape() { - return enableScrollX() ? "overflowPortrait" : "portrait" + if (enableScrollX()) { + return "overflowPortrait"; + } + + return "portrait"; } function getSquareShape() { - return enableScrollX() ? "overflowSquare" : "square" + if (enableScrollX()) { + return "overflowSquare"; + } + + return "square"; } function getSections() { @@ -23,147 +35,208 @@ define(["loading", "libraryBrowser", "cardBuilder", "dom", "apphost", "imageLoad types: "Movie", id: "favoriteMovies", shape: getPosterShape(), - showTitle: !1, - overlayPlayButton: !0 + showTitle: false, + overlayPlayButton: true }, { name: "HeaderFavoriteShows", types: "Series", id: "favoriteShows", shape: getPosterShape(), - showTitle: !1, - overlayPlayButton: !0 + showTitle: false, + overlayPlayButton: true }, { name: "HeaderFavoriteEpisodes", types: "Episode", id: "favoriteEpisode", shape: getThumbShape(), - preferThumb: !1, - showTitle: !0, - showParentTitle: !0, - overlayPlayButton: !0, - overlayText: !1, - centerText: !0 + preferThumb: false, + showTitle: true, + showParentTitle: true, + overlayPlayButton: true, + overlayText: false, + centerText: true }, { name: "HeaderFavoriteVideos", types: "Video,MusicVideo", id: "favoriteVideos", shape: getThumbShape(), - preferThumb: !0, - showTitle: !0, - overlayPlayButton: !0, - overlayText: !1, - centerText: !0 + preferThumb: true, + showTitle: true, + overlayPlayButton: true, + overlayText: false, + centerText: true }, { name: "HeaderFavoriteArtists", types: "MusicArtist", id: "favoriteArtists", shape: getSquareShape(), - preferThumb: !1, - showTitle: !0, - overlayText: !1, - showParentTitle: !1, - centerText: !0, - overlayPlayButton: !0, - coverImage: !0 + preferThumb: false, + showTitle: true, + overlayText: false, + showParentTitle: false, + centerText: true, + overlayPlayButton: true, + coverImage: true }, { name: "HeaderFavoriteAlbums", types: "MusicAlbum", id: "favoriteAlbums", shape: getSquareShape(), - preferThumb: !1, - showTitle: !0, - overlayText: !1, - showParentTitle: !0, - centerText: !0, - overlayPlayButton: !0, - coverImage: !0 + preferThumb: false, + showTitle: true, + overlayText: false, + showParentTitle: true, + centerText: true, + overlayPlayButton: true, + coverImage: true }, { name: "HeaderFavoriteSongs", types: "Audio", id: "favoriteSongs", shape: getSquareShape(), - preferThumb: !1, - showTitle: !0, - overlayText: !1, - showParentTitle: !0, - centerText: !0, - overlayMoreButton: !0, + preferThumb: false, + showTitle: true, + overlayText: false, + showParentTitle: true, + centerText: true, + overlayMoreButton: true, action: "instantmix", - coverImage: !0 - }] + coverImage: true + }]; } function loadSection(elem, userId, topParentId, section, isSingleSection) { - var screenWidth = dom.getWindowSize().innerWidth, - options = { - SortBy: "SortName", - SortOrder: "Ascending", - Filters: "IsFavorite", - Recursive: !0, - Fields: "PrimaryImageAspectRatio,BasicSyncInfo", - CollapseBoxSetItems: !1, - ExcludeLocationTypes: "Virtual", - EnableTotalRecordCount: !1 - }; - topParentId && (options.ParentId = topParentId), isSingleSection || (options.Limit = screenWidth >= 1920 ? 10 : screenWidth >= 1440 ? 8 : 6, enableScrollX() && (options.Limit = 20)); + var screenWidth = dom.getWindowSize().innerWidth; + var options = { + SortBy: "SortName", + SortOrder: "Ascending", + Filters: "IsFavorite", + Recursive: true, + Fields: "PrimaryImageAspectRatio,BasicSyncInfo", + CollapseBoxSetItems: false, + ExcludeLocationTypes: "Virtual", + EnableTotalRecordCount: false + }; + + if (topParentId) { + options.ParentId = topParentId; + } + + if (!isSingleSection) { + options.Limit = screenWidth >= 1920 ? 10 : screenWidth >= 1440 ? 8 : 6; + + if (enableScrollX()) { + options.Limit = 20; + } + } + var promise; - return "MusicArtist" === section.types ? promise = ApiClient.getArtists(userId, options) : (options.IncludeItemTypes = section.types, promise = ApiClient.getItems(userId, options)), promise.then(function(result) { + + if ("MusicArtist" === section.types) { + promise = ApiClient.getArtists(userId, options); + } else { + options.IncludeItemTypes = section.types; + promise = ApiClient.getItems(userId, options); + } + + return promise.then(function (result) { var html = ""; + if (result.Items.length) { if (html += '
', !layoutManager.tv && options.Limit && result.Items.length >= options.Limit) { - html += '', html += '

', html += globalize.translate(section.name), html += "

", html += '', html += "
" - } else html += '

' + globalize.translate(section.name) + "

"; + html += ''; + html += '

'; + html += globalize.translate(section.name); + html += "

"; + html += ''; + html += "
"; + } else { + html += '

' + globalize.translate(section.name) + "

"; + } + if (html += "
", enableScrollX()) { var scrollXClass = "scrollX hiddenScrollX"; - layoutManager.tv && (scrollXClass += " smoothScrollX"), html += '
' - } else html += '
'; - var supportsImageAnalysis = appHost.supports("imageanalysis"), - cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle; - cardLayout = !1, html += cardBuilder.getCardsHtml(result.Items, { + + if (layoutManager.tv) { + scrollXClass += " smoothScrollX"; + } + + html += '
'; + } else { + html += '
'; + } + + var supportsImageAnalysis = appHost.supports("imageanalysis"); + var cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle; + cardLayout = false; + html += cardBuilder.getCardsHtml(result.Items, { preferThumb: section.preferThumb, shape: section.shape, centerText: section.centerText && !cardLayout, - overlayText: !1 !== section.overlayText, + overlayText: false !== section.overlayText, showTitle: section.showTitle, showParentTitle: section.showParentTitle, - scalable: !0, + scalable: true, coverImage: section.coverImage, overlayPlayButton: section.overlayPlayButton, overlayMoreButton: section.overlayMoreButton && !cardLayout, action: section.action, allowBottomPadding: !enableScrollX(), cardLayout: cardLayout - }), html += "
" + }); + html += "
"; } - elem.innerHTML = html, imageLoader.lazyChildren(elem) - }) + + elem.innerHTML = html; + imageLoader.lazyChildren(elem); + }); } function loadSections(page, userId, topParentId, types) { loading.show(); - var sections = getSections(), - sectionid = getParameterByName("sectionid"); - sectionid && (sections = sections.filter(function(s) { - return s.id === sectionid - })), types && (sections = sections.filter(function(s) { - return -1 !== types.indexOf(s.id) - })); - var i, length, elem = page.querySelector(".favoriteSections"); + var sections = getSections(); + var sectionid = getParameterByName("sectionid"); + + if (sectionid) { + sections = sections.filter(function (s) { + return s.id === sectionid; + }); + } + + if (types) { + sections = sections.filter(function (s) { + return -1 !== types.indexOf(s.id); + }); + } + + var i; + var length; + var elem = page.querySelector(".favoriteSections"); + if (!elem.innerHTML) { var html = ""; - for (i = 0, length = sections.length; i < length; i++) html += '
'; - elem.innerHTML = html + + for (i = 0, length = sections.length; i < length; i++) { + html += '
'; + } + + elem.innerHTML = html; } + var promises = []; + for (i = 0, length = sections.length; i < length; i++) { var section = sections[i]; - elem = page.querySelector(".section" + section.id), promises.push(loadSection(elem, userId, topParentId, section, 1 === sections.length)) + elem = page.querySelector(".section" + section.id); + promises.push(loadSection(elem, userId, topParentId, section, 1 === sections.length)); } - Promise.all(promises).then(function() { - loading.hide() - }) + + Promise.all(promises).then(function () { + loading.hide(); + }); } + return { render: loadSections - } + }; });