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

autobackdrops.js

This commit is contained in:
grafixeyehero 2019-10-08 00:56:51 +03:00
parent 40b8a0d881
commit af8d421a8c

View file

@ -1,53 +1,76 @@
define(["backdrop", "userSettings", "libraryMenu"], function(backdrop, userSettings, libraryMenu) { define(["backdrop", "userSettings", "libraryMenu"], function (backdrop, userSettings, libraryMenu) {
"use strict"; "use strict";
function enabled() { function enabled() {
return userSettings.enableBackdrops() return userSettings.enableBackdrops();
} }
function getBackdropItemIds(apiClient, userId, types, parentId) { function getBackdropItemIds(apiClient, userId, types, parentId) {
var key = "backdrops2_" + userId + (types || "") + (parentId || ""), var key = "backdrops2_" + userId + (types || "") + (parentId || "");
data = cache[key]; var data = cache[key];
if (data) return console.log("Found backdrop id list in cache. Key: " + key), data = JSON.parse(data), Promise.resolve(data);
if (data) {
console.log("Found backdrop id list in cache. Key: " + key);
data = JSON.parse(data);
return Promise.resolve(data);
}
var options = { var options = {
SortBy: "IsFavoriteOrLiked,Random", SortBy: "IsFavoriteOrLiked,Random",
Limit: 20, Limit: 20,
Recursive: !0, Recursive: true,
IncludeItemTypes: types, IncludeItemTypes: types,
ImageTypes: "Backdrop", ImageTypes: "Backdrop",
ParentId: parentId, ParentId: parentId,
EnableTotalRecordCount: !1 EnableTotalRecordCount: false
}; };
return apiClient.getItems(apiClient.getCurrentUserId(), options).then(function(result) { return apiClient.getItems(apiClient.getCurrentUserId(), options).then(function (result) {
var images = result.Items.map(function(i) { var images = result.Items.map(function (i) {
return { return {
Id: i.Id, Id: i.Id,
tag: i.BackdropImageTags[0], tag: i.BackdropImageTags[0],
ServerId: i.ServerId ServerId: i.ServerId
} };
}); });
return cache[key] = JSON.stringify(images), images cache[key] = JSON.stringify(images);
}) return images;
});
} }
function showBackdrop(type, parentId) { function showBackdrop(type, parentId) {
var apiClient = window.ApiClient; var apiClient = window.ApiClient;
apiClient && getBackdropItemIds(apiClient, apiClient.getCurrentUserId(), type, parentId).then(function(images) {
images.length ? backdrop.setBackdrops(images.map(function(i) { if (apiClient) {
return i.BackdropImageTags = [i.tag], i getBackdropItemIds(apiClient, apiClient.getCurrentUserId(), type, parentId).then(function (images) {
})) : backdrop.clear() if (images.length) {
}) backdrop.setBackdrops(images.map(function (i) {
i.BackdropImageTags = [i.tag];
return i;
}));
} else {
backdrop.clear();
}
});
}
} }
var cache = {}; var cache = {};
pageClassOn("pageshow", "page", function() { pageClassOn("pageshow", "page", function () {
var page = this; var page = this;
if (!page.classList.contains("selfBackdropPage"))
if (page.classList.contains("backdropPage")) if (!page.classList.contains("selfBackdropPage")) {
if (page.classList.contains("backdropPage")) {
if (enabled()) { if (enabled()) {
var type = page.getAttribute("data-backdroptype"), var type = page.getAttribute("data-backdroptype");
parentId = page.classList.contains("globalBackdropPage") ? "" : libraryMenu.getTopParentId(); var parentId = page.classList.contains("globalBackdropPage") ? "" : libraryMenu.getTopParentId();
showBackdrop(type, parentId) showBackdrop(type, parentId);
} else page.classList.remove("backdropPage"), backdrop.clear(); } else {
else backdrop.clear() page.classList.remove("backdropPage");
}) backdrop.clear();
}); }
} else {
backdrop.clear();
}
}
});
});