mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
diminify favorites.js
This commit is contained in:
parent
b6db366d0e
commit
08f249b007
1 changed files with 187 additions and 107 deletions
|
@ -1,4 +1,4 @@
|
||||||
define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "apphost", "layoutManager", "focusManager", "emby-itemscontainer", "emby-scroller"], function(appRouter, cardBuilder, dom, globalize, connectionManager, appHost, layoutManager, focusManager) {
|
define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "apphost", "layoutManager", "focusManager", "emby-itemscontainer", "emby-scroller"], function (appRouter, cardBuilder, dom, globalize, connectionManager, appHost, layoutManager, focusManager) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function enableScrollX() {
|
function enableScrollX() {
|
||||||
|
@ -22,92 +22,92 @@ define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "ap
|
||||||
name: "HeaderFavoriteMovies",
|
name: "HeaderFavoriteMovies",
|
||||||
types: "Movie",
|
types: "Movie",
|
||||||
shape: getPosterShape(),
|
shape: getPosterShape(),
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
showYear: !0,
|
showYear: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
centerText: !0
|
centerText: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteShows",
|
name: "HeaderFavoriteShows",
|
||||||
types: "Series",
|
types: "Series",
|
||||||
shape: getPosterShape(),
|
shape: getPosterShape(),
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
showYear: !0,
|
showYear: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
centerText: !0
|
centerText: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteEpisodes",
|
name: "HeaderFavoriteEpisodes",
|
||||||
types: "Episode",
|
types: "Episode",
|
||||||
shape: getThumbShape(),
|
shape: getThumbShape(),
|
||||||
preferThumb: !1,
|
preferThumb: false,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
showParentTitle: !0,
|
showParentTitle: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
centerText: !0
|
centerText: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteVideos",
|
name: "HeaderFavoriteVideos",
|
||||||
types: "Video",
|
types: "Video",
|
||||||
shape: getThumbShape(),
|
shape: getThumbShape(),
|
||||||
preferThumb: !0,
|
preferThumb: true,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
centerText: !0
|
centerText: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteCollections",
|
name: "HeaderFavoriteCollections",
|
||||||
types: "BoxSet",
|
types: "BoxSet",
|
||||||
shape: getPosterShape(),
|
shape: getPosterShape(),
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
centerText: !0
|
centerText: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoritePlaylists",
|
name: "HeaderFavoritePlaylists",
|
||||||
types: "Playlist",
|
types: "Playlist",
|
||||||
shape: getSquareShape(),
|
shape: getSquareShape(),
|
||||||
preferThumb: !1,
|
preferThumb: false,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
showParentTitle: !1,
|
showParentTitle: false,
|
||||||
centerText: !0,
|
centerText: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
coverImage: !0
|
coverImage: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteArtists",
|
name: "HeaderFavoriteArtists",
|
||||||
types: "MusicArtist",
|
types: "MusicArtist",
|
||||||
shape: getSquareShape(),
|
shape: getSquareShape(),
|
||||||
preferThumb: !1,
|
preferThumb: false,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
showParentTitle: !1,
|
showParentTitle: false,
|
||||||
centerText: !0,
|
centerText: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
coverImage: !0
|
coverImage: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteAlbums",
|
name: "HeaderFavoriteAlbums",
|
||||||
types: "MusicAlbum",
|
types: "MusicAlbum",
|
||||||
shape: getSquareShape(),
|
shape: getSquareShape(),
|
||||||
preferThumb: !1,
|
preferThumb: false,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
showParentTitle: !0,
|
showParentTitle: true,
|
||||||
centerText: !0,
|
centerText: true,
|
||||||
overlayPlayButton: !0,
|
overlayPlayButton: true,
|
||||||
coverImage: !0
|
coverImage: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteSongs",
|
name: "HeaderFavoriteSongs",
|
||||||
types: "Audio",
|
types: "Audio",
|
||||||
shape: getSquareShape(),
|
shape: getSquareShape(),
|
||||||
preferThumb: !1,
|
preferThumb: false,
|
||||||
showTitle: !0,
|
showTitle: true,
|
||||||
overlayText: !1,
|
overlayText: false,
|
||||||
showParentTitle: !0,
|
showParentTitle: true,
|
||||||
centerText: !0,
|
centerText: true,
|
||||||
overlayMoreButton: !0,
|
overlayMoreButton: true,
|
||||||
action: "instantmix",
|
action: "instantmix",
|
||||||
coverImage: !0
|
coverImage: true
|
||||||
}, {
|
}, {
|
||||||
name: "HeaderFavoriteBooks",
|
name: "HeaderFavoriteBooks",
|
||||||
types: "Book",
|
types: "Book",
|
||||||
|
@ -117,59 +117,78 @@ define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "ap
|
||||||
overlayPlayButton: true,
|
overlayPlayButton: true,
|
||||||
overlayText: false,
|
overlayText: false,
|
||||||
centerText: true
|
centerText: true
|
||||||
}]
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFetchDataFn(section) {
|
function getFetchDataFn(section) {
|
||||||
return function() {
|
return function () {
|
||||||
var apiClient = this.apiClient,
|
var apiClient = this.apiClient;
|
||||||
options = {
|
var options = {
|
||||||
SortBy: (section.types, "SeriesName,SortName"),
|
SortBy: (section.types, "SeriesName,SortName"),
|
||||||
SortOrder: "Ascending",
|
SortOrder: "Ascending",
|
||||||
Filters: "IsFavorite",
|
Filters: "IsFavorite",
|
||||||
Recursive: !0,
|
Recursive: true,
|
||||||
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
|
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
|
||||||
CollapseBoxSetItems: !1,
|
CollapseBoxSetItems: false,
|
||||||
ExcludeLocationTypes: "Virtual",
|
ExcludeLocationTypes: "Virtual",
|
||||||
EnableTotalRecordCount: !1
|
EnableTotalRecordCount: false
|
||||||
};
|
};
|
||||||
options.Limit = 20;
|
options.Limit = 20;
|
||||||
var userId = apiClient.getCurrentUserId();
|
var userId = apiClient.getCurrentUserId();
|
||||||
return "MusicArtist" === section.types ? apiClient.getArtists(userId, options) : (options.IncludeItemTypes = section.types, apiClient.getItems(userId, options))
|
|
||||||
}
|
if ("MusicArtist" === section.types) {
|
||||||
|
return apiClient.getArtists(userId, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.IncludeItemTypes = section.types;
|
||||||
|
return apiClient.getItems(userId, options);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRouteUrl(section, serverId) {
|
function getRouteUrl(section, serverId) {
|
||||||
return appRouter.getRouteUrl("list", {
|
return appRouter.getRouteUrl("list", {
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
itemTypes: section.types,
|
itemTypes: section.types,
|
||||||
isFavorite: !0
|
isFavorite: true
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemsHtmlFn(section) {
|
function getItemsHtmlFn(section) {
|
||||||
return function(items) {
|
return function (items) {
|
||||||
var supportsImageAnalysis = appHost.supports("imageanalysis"),
|
var supportsImageAnalysis = appHost.supports("imageanalysis");
|
||||||
cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
|
var cardLayout = (appHost.preferVisualCards || supportsImageAnalysis) && section.autoCardLayout && section.showTitle;
|
||||||
cardLayout = !1;
|
cardLayout = false;
|
||||||
var serverId = this.apiClient.serverId(),
|
var serverId = this.apiClient.serverId();
|
||||||
leadingButtons = layoutManager.tv ? [{
|
var leadingButtons = layoutManager.tv ? [{
|
||||||
name: globalize.translate("All"),
|
name: globalize.translate("All"),
|
||||||
id: "more",
|
id: "more",
|
||||||
icon: "",
|
icon: "",
|
||||||
routeUrl: getRouteUrl(section, serverId)
|
routeUrl: getRouteUrl(section, serverId)
|
||||||
}] : null,
|
}] : null;
|
||||||
lines = 0;
|
var lines = 0;
|
||||||
return section.showTitle && lines++, section.showYear && lines++, section.showParentTitle && lines++, cardBuilder.getCardsHtml({
|
|
||||||
|
if (section.showTitle) {
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (section.showYear) {
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (section.showParentTitle) {
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardBuilder.getCardsHtml({
|
||||||
items: items,
|
items: items,
|
||||||
preferThumb: section.preferThumb,
|
preferThumb: section.preferThumb,
|
||||||
shape: section.shape,
|
shape: section.shape,
|
||||||
centerText: section.centerText && !cardLayout,
|
centerText: section.centerText && !cardLayout,
|
||||||
overlayText: !1 !== section.overlayText,
|
overlayText: false !== section.overlayText,
|
||||||
showTitle: section.showTitle,
|
showTitle: section.showTitle,
|
||||||
showYear: section.showYear,
|
showYear: section.showYear,
|
||||||
showParentTitle: section.showParentTitle,
|
showParentTitle: section.showParentTitle,
|
||||||
scalable: !0,
|
scalable: true,
|
||||||
coverImage: section.coverImage,
|
coverImage: section.coverImage,
|
||||||
overlayPlayButton: section.overlayPlayButton,
|
overlayPlayButton: section.overlayPlayButton,
|
||||||
overlayMoreButton: section.overlayMoreButton && !cardLayout,
|
overlayMoreButton: section.overlayMoreButton && !cardLayout,
|
||||||
|
@ -178,39 +197,100 @@ define(["appRouter", "cardBuilder", "dom", "globalize", "connectionManager", "ap
|
||||||
cardLayout: cardLayout,
|
cardLayout: cardLayout,
|
||||||
leadingButtons: leadingButtons,
|
leadingButtons: leadingButtons,
|
||||||
lines: lines
|
lines: lines
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function FavoritesTab(view, params) {
|
function FavoritesTab(view, params) {
|
||||||
this.view = view, this.params = params, this.apiClient = connectionManager.currentApiClient(), this.sectionsContainer = view.querySelector(".sections"), createSections(this, this.sectionsContainer, this.apiClient)
|
this.view = view;
|
||||||
|
this.params = params;
|
||||||
|
this.apiClient = connectionManager.currentApiClient();
|
||||||
|
this.sectionsContainer = view.querySelector(".sections");
|
||||||
|
createSections(this, this.sectionsContainer, this.apiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSections(instance, elem, apiClient) {
|
function createSections(instance, elem, apiClient) {
|
||||||
var i, length, sections = getSections(),
|
var i;
|
||||||
html = "";
|
var length;
|
||||||
|
var sections = getSections();
|
||||||
|
var html = "";
|
||||||
|
|
||||||
for (i = 0, length = sections.length; i < length; i++) {
|
for (i = 0, length = sections.length; i < length; i++) {
|
||||||
var section = sections[i],
|
var section = sections[i];
|
||||||
sectionClass = "verticalSection";
|
var sectionClass = "verticalSection";
|
||||||
section.showTitle || (sectionClass += " verticalSection-extrabottompadding"), html += '<div class="' + sectionClass + ' hide">', html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">', layoutManager.tv ? html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + "</h2>" : (html += '<a is="emby-linkbutton" href="' + getRouteUrl(section, apiClient.serverId()) + '" class="more button-flat button-flat-mini sectionTitleTextButton">', html += '<h2 class="sectionTitle sectionTitle-cards">', html += globalize.translate(section.name), html += "</h2>", html += '<i class="md-icon"></i>', html += "</a>"), html += "</div>", html += '<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale" data-mousewheel="false" data-centerfocus="true"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x padded-left padded-right" data-monitor="markfavorite"></div></div>', html += "</div>"
|
|
||||||
|
if (!section.showTitle) {
|
||||||
|
sectionClass += " verticalSection-extrabottompadding";
|
||||||
|
}
|
||||||
|
|
||||||
|
html += '<div class="' + sectionClass + ' hide">';
|
||||||
|
html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">';
|
||||||
|
|
||||||
|
if (layoutManager.tv) {
|
||||||
|
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + "</h2>";
|
||||||
|
} else {
|
||||||
|
html += '<a is="emby-linkbutton" href="' + getRouteUrl(section, apiClient.serverId()) + '" class="more button-flat button-flat-mini sectionTitleTextButton">';
|
||||||
|
html += '<h2 class="sectionTitle sectionTitle-cards">';
|
||||||
|
html += globalize.translate(section.name);
|
||||||
|
html += "</h2>";
|
||||||
|
html += '<i class="md-icon"></i>';
|
||||||
|
html += "</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
html += "</div>";
|
||||||
|
html += '<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale" data-mousewheel="false" data-centerfocus="true"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x padded-left padded-right" data-monitor="markfavorite"></div></div>';
|
||||||
|
html += "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.innerHTML = html;
|
elem.innerHTML = html;
|
||||||
var elems = elem.querySelectorAll(".itemsContainer");
|
var elems = elem.querySelectorAll(".itemsContainer");
|
||||||
|
|
||||||
for (i = 0, length = elems.length; i < length; i++) {
|
for (i = 0, length = elems.length; i < length; i++) {
|
||||||
var itemsContainer = elems[i];
|
var itemsContainer = elems[i];
|
||||||
itemsContainer.fetchData = getFetchDataFn(sections[i]).bind(instance), itemsContainer.getItemsHtml = getItemsHtmlFn(sections[i]).bind(instance), itemsContainer.parentContainer = dom.parentWithClass(itemsContainer, "verticalSection")
|
itemsContainer.fetchData = getFetchDataFn(sections[i]).bind(instance);
|
||||||
|
itemsContainer.getItemsHtml = getItemsHtmlFn(sections[i]).bind(instance);
|
||||||
|
itemsContainer.parentContainer = dom.parentWithClass(itemsContainer, "verticalSection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FavoritesTab.prototype.onResume = function(options) {
|
|
||||||
for (var promises = (this.apiClient, []), view = this.view, elems = this.sectionsContainer.querySelectorAll(".itemsContainer"), i = 0, length = elems.length; i < length; i++) promises.push(elems[i].resume(options));
|
FavoritesTab.prototype.onResume = function (options) {
|
||||||
Promise.all(promises).then(function() {
|
var promises = (this.apiClient, []);
|
||||||
options.autoFocus && focusManager.autoFocus(view)
|
var view = this.view;
|
||||||
})
|
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
|
||||||
}, FavoritesTab.prototype.onPause = function() {
|
|
||||||
for (var elems = this.sectionsContainer.querySelectorAll(".itemsContainer"), i = 0, length = elems.length; i < length; i++) elems[i].pause()
|
for (var i = 0, length = elems.length; i < length; i++) {
|
||||||
}, FavoritesTab.prototype.destroy = function() {
|
promises.push(elems[i].resume(options));
|
||||||
this.view = null, this.params = null, this.apiClient = null;
|
}
|
||||||
for (var elems = this.sectionsContainer.querySelectorAll(".itemsContainer"), i = 0, length = elems.length; i < length; i++) elems[i].fetchData = null, elems[i].getItemsHtml = null, elems[i].parentContainer = null;
|
|
||||||
this.sectionsContainer = null
|
Promise.all(promises).then(function () {
|
||||||
}, FavoritesTab
|
if (options.autoFocus) {
|
||||||
|
focusManager.autoFocus(view);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
FavoritesTab.prototype.onPause = function () {
|
||||||
|
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
|
||||||
|
|
||||||
|
for (var i = 0, length = elems.length; i < length; i++) {
|
||||||
|
elems[i].pause();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
FavoritesTab.prototype.destroy = function () {
|
||||||
|
this.view = null;
|
||||||
|
this.params = null;
|
||||||
|
this.apiClient = null;
|
||||||
|
var elems = this.sectionsContainer.querySelectorAll(".itemsContainer");
|
||||||
|
|
||||||
|
for (var i = 0, length = elems.length; i < length; i++) {
|
||||||
|
elems[i].fetchData = null;
|
||||||
|
elems[i].getItemsHtml = null;
|
||||||
|
elems[i].parentContainer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sectionsContainer = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return FavoritesTab;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue