mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
use shared chaptercardbuilder.js
This commit is contained in:
parent
f9089f44cc
commit
ce0fd77a63
8 changed files with 135 additions and 110 deletions
|
@ -1,4 +1,4 @@
|
|||
define(['datetime', 'imageLoader', 'itemShortcuts'], function (datetime, imageLoader, itemShortcuts) {
|
||||
define(['datetime', 'imageLoader', 'itemShortcuts', 'connectionManager'], function (datetime, imageLoader, itemShortcuts, connectionManager) {
|
||||
|
||||
function buildChapterCardsHtml(item, chapters, options) {
|
||||
|
||||
|
@ -27,6 +27,8 @@ define(['datetime', 'imageLoader', 'itemShortcuts'], function (datetime, imageLo
|
|||
var html = '';
|
||||
var itemsInRow = 0;
|
||||
|
||||
var apiClient = connectionManager.getApiClient(item.ServerId);
|
||||
|
||||
for (var i = 0, length = chapters.length; i < length; i++) {
|
||||
|
||||
if (options.rows && itemsInRow == 0) {
|
||||
|
@ -35,7 +37,7 @@ define(['datetime', 'imageLoader', 'itemShortcuts'], function (datetime, imageLo
|
|||
|
||||
var chapter = chapters[i];
|
||||
|
||||
html += buildChapterCard(item, chapter, options, className);
|
||||
html += buildChapterCard(item, apiClient, chapter, i, options, className);
|
||||
itemsInRow++;
|
||||
|
||||
if (options.rows && itemsInRow >= options.rows) {
|
||||
|
@ -47,9 +49,25 @@ define(['datetime', 'imageLoader', 'itemShortcuts'], function (datetime, imageLo
|
|||
return html;
|
||||
}
|
||||
|
||||
function buildChapterCard(item, chapter, options, className) {
|
||||
function getImgUrl(item, chapter, index, maxWidth, apiClient) {
|
||||
|
||||
var imgUrl = chapter.images ? chapter.images.primary : '';
|
||||
if (chapter.ImageTag) {
|
||||
|
||||
return apiClient.getScaledImageUrl(item.Id, {
|
||||
|
||||
maxWidth: maxWidth,
|
||||
tag: chapter.ImageTag,
|
||||
type: "Chapter",
|
||||
index: index
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildChapterCard(item, apiClient, chapter, index, options, className) {
|
||||
|
||||
var imgUrl = getImgUrl(item, chapter, index, options.width || 400, apiClient);
|
||||
|
||||
var cardImageContainerClass = 'cardImageContainer';
|
||||
if (options.coverImage) {
|
||||
|
@ -84,12 +102,12 @@ define(['datetime', 'imageLoader', 'itemShortcuts'], function (datetime, imageLo
|
|||
|
||||
function buildChapterCards(item, chapters, options) {
|
||||
|
||||
// Abort if the container has been disposed
|
||||
if (!document.body.contains(options.parentContainer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.parentContainer) {
|
||||
// Abort if the container has been disposed
|
||||
if (!document.body.contains(options.parentContainer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (chapters.length) {
|
||||
options.parentContainer.classList.remove('hide');
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue