1
0
Fork 0
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:
Luke Pulverenti 2016-07-30 22:54:17 -04:00
parent f9089f44cc
commit ce0fd77a63
8 changed files with 135 additions and 110 deletions

View file

@ -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 {