';
$('.tabButtons', page).html(tabsHtml).trigger('create');
$('#detailsSection', page).removeClass('hide');
var elems = $('.radioDetailTab', page).on('change', function () {
$('.detailTab', page).hide();
$('.' + this.value, page).show();
});
elems[0].click();
$(elems[0]).trigger('change');
} else {
$('#detailsSection', page).addClass('hide');
$('.tabButtons', page).empty();
}
//var elem = $('.detailSectionContent', detailsSection)[0];
//var text = elem.textContent || elem.innerText;
//if (!text.trim()) {
// detailsSection.addClass('hide');
//} else {
// detailsSection.removeClass('hide');
//}
}
function getArtistLinksHtml(artists) {
var html = [];
for (var i = 0, length = artists.length; i < length; i++) {
var artist = artists[i];
html.push('' + artist + '');
}
html = html.join(' / ');
if (artists.length == 1) {
return 'Artist: ' + html;
}
if (artists.length > 1) {
return 'Artists: ' + html;
}
return html;
}
function renderSoundtracks(page, item) {
if (item.Type == "MusicAlbum") {
$('#soundtracksHeader', page).html("This album is the soundtrack for ...");
} else {
$('#soundtracksHeader', page).html("Soundtrack(s)");
}
ApiClient.getItems(Dashboard.getCurrentUserId(), {
Ids: item.SoundtrackIds.join(","),
ItemFields: "PrimaryImageAspectRatio,ItemCounts,AudioInfo",
SortBy: "SortName"
}).done(function (result) {
var html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: item.Type == "MusicAlbum" ? "portrait" : "square"
});
$('#soundtracksContent', page).html(html);
});
}
function renderSiblingLinks(page, item) {
$('.lnkSibling', page).addClass('hide');
if ((item.Type != "Episode" && item.Type != "Season" && item.Type != "Audio") || item.IndexNumber == null) {
return;
}
var promise;
if (item.Type == "Season") {
promise = ApiClient.getSeasons(item.SeriesId, {
userId: Dashboard.getCurrentUserId(),
AdjacentTo: item.Id
});
}
else if (item.Type == "Episode" && item.SeasonId) {
// Use dedicated episodes endpoint
promise = ApiClient.getEpisodes(item.SeriesId, {
seasonId: item.SeasonId,
userId: Dashboard.getCurrentUserId(),
AdjacentTo: item.Id
});
} else {
promise = ApiClient.getItems(Dashboard.getCurrentUserId(), {
AdjacentTo: item.Id,
ParentId: item.ParentId
});
}
promise.done(function (result) {
for (var i = 0, length = result.Items.length; i < length; i++) {
var curr = result.Items[i];
if (curr.IndexNumber == null) {
continue;
}
if (curr.IndexNumber < item.IndexNumber) {
$('.lnkPreviousItem', page).removeClass('hide').attr('href', 'itemdetails.html?id=' + curr.Id);
}
else if (curr.IndexNumber > item.IndexNumber) {
$('.lnkNextItem', page).removeClass('hide').attr('href', 'itemdetails.html?id=' + curr.Id);
}
}
});
}
function renderSimilarItems(page, item) {
var promise;
var options = {
userId: Dashboard.getCurrentUserId(),
limit: item.Type == "MusicAlbum" ? 4 : 6,
fields: "PrimaryImageAspectRatio,UserData"
};
if (item.Type == "Movie") {
promise = ApiClient.getSimilarMovies(item.Id, options);
}
else if (item.Type == "Trailer") {
promise = ApiClient.getSimilarTrailers(item.Id, options);
}
else if (item.Type == "MusicAlbum") {
promise = ApiClient.getSimilarAlbums(item.Id, options);
}
else if (item.Type == "Series") {
promise = ApiClient.getSimilarShows(item.Id, options);
}
else if (item.MediaType == "Game") {
promise = ApiClient.getSimilarGames(item.Id, options);
} else {
$('#similarCollapsible', page).hide();
return;
}
promise.done(function (result) {
if (!result.Items.length) {
$('#similarCollapsible', page).hide();
return;
}
var elem = $('#similarCollapsible', page).show();
$('.detailSectionHeader', elem).html('If you like ' + item.Name + ', check these out...');
var html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: item.Type == "MusicAlbum" ? "square" : "portrait",
showParentTitle: item.Type == "MusicAlbum",
centerText: item.Type != "MusicAlbum",
showTitle: item.Type == "MusicAlbum" || item.Type == "Game",
borderless: item.Type == "Game"
});
$('#similarContent', page).html(html).createPosterItemMenus();
});
}
function renderSeriesAirTime(page, item, context) {
if (item.Type != "Series") {
$('#seriesAirTime', page).hide();
return;
}
var html = '';
if (item.AirDays && item.AirDays.length) {
html += item.AirDays.length == 7 ? 'daily' : item.AirDays.map(function (a) {
return a + "s";
}).join(',');
}
if (item.AirTime) {
html += ' at ' + item.AirTime;
}
if (item.Studios.length) {
html += ' on ' + item.Studios[0].Name + '';
}
if (html) {
html = (item.Status == 'Ended' ? 'Aired ' : 'Airs ') + html;
$('#seriesAirTime', page).show().html(html).trigger('create');
} else {
$('#seriesAirTime', page).hide();
}
}
function renderTags(page, item) {
if (item.Tags && item.Tags.length) {
var html = '';
html += '
Tags
';
for (var i = 0, length = item.Tags.length; i < length; i++) {
html += '
' + item.Tags[i] + '
';
}
$('.itemTags', page).show().html(html);
} else {
$('.itemTags', page).hide();
}
}
function renderKeywords(page, item) {
if (item.Keywords && item.Keywords.length) {
var html = '';
html += '
Plot Keywords
';
for (var i = 0, length = item.Keywords.length; i < length; i++) {
html += '
' + item.Keywords[i] + '
';
}
$('.itemKeywords', page).show().html(html);
} else {
$('.itemKeywords', page).hide();
}
}
function renderChildren(page, item, user) {
var fields = "ItemCounts,AudioInfo,PrimaryImageAspectRatio";
var query = {
ParentId: item.Id,
Fields: fields
};
// Let the server pre-sort boxsets
if (item.Type !== "BoxSet") {
query.SortBy = "SortName";
}
var promise;
if (item.Type == "Series") {
promise = ApiClient.getSeasons(item.Id, {
userId: user.Id,
Fields: fields
});
}
else if (item.Type == "Season") {
// Use dedicated episodes endpoint
promise = ApiClient.getEpisodes(item.SeriesId, {
seasonId: item.Id,
userId: user.Id,
Fields: fields
});
}
promise = promise || ApiClient.getItems(Dashboard.getCurrentUserId(), query);
promise.done(function (result) {
if (item.Type == "MusicAlbum") {
$('#childrenContent', page).html(LibraryBrowser.getSongTableHtml(result.Items, { showArtist: true })).trigger('create');
} else {
var html = '';
if (item.Type == "Series") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
showTitle: true,
centerText: true
});
}
else if (item.Type == "Season") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "smallBackdrop",
showTitle: true,
displayAsSpecial: item.Type == "Season" && item.IndexNumber
});
}
else if (item.Type == "GameSystem") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
context: 'games',
showTitle: true,
centerText: true
});
}
$('#childrenContent', page).html(html).createPosterItemMenus();
if (item.Type == "BoxSet") {
var collectionItemTypes = [
{ name: 'Movies', type: 'Movie' },
{ name: 'Series', type: 'Series' },
{ name: 'Albums', type: 'MusicAlbum' },
{ name: 'Games', type: 'Game' },
{ name: 'Books', type: 'Book' }
];
renderCollectionItems(page, collectionItemTypes, result.Items, user);
}
}
});
if (item.Type == "Season") {
$('#childrenTitle', page).html('Episodes');
}
else if (item.Type == "Series") {
$('#childrenTitle', page).html('Seasons');
}
else if (item.Type == "MusicAlbum") {
$('#childrenTitle', page).html('Tracks');
}
else if (item.Type == "GameSystem") {
$('#childrenTitle', page).html('Games');
}
else {
$('#childrenTitle', page).html('Items');
}
}
function renderCollectionItems(page, types, items, user) {
for (var i = 0, length = types.length; i < length; i++) {
var type = types[i];
var typeItems = items.filter(function (curr) {
return curr.Type == type.type;
});
if (!typeItems.length) {
continue;
}
renderCollectionItemType(page, type, typeItems, user);
}
var otherType = { name: 'Other Items' };
var otherTypeItems = items.filter(function (curr) {
return !types.filter(function (t) {
return t.type == curr.Type;
}).length;
});
if (otherTypeItems.length) {
renderCollectionItemType(page, otherType, otherTypeItems, user);
}
if (!items.length) {
renderCollectionItemType(page, { name: 'Titles' }, items, user);
}
$('.collectionItems', page).trigger('create').createPosterItemMenus();
}
function renderCollectionItemType(page, type, items, user) {
var html = '';
html += '
';
html += '
';
html += '' + type.name + '';
if (user.Configuration.IsAdministrator) {
html += 'Edit';
}
html += '
';
html += '
';
var shape = type.type == 'MusicAlbum' ? 'square' : 'portrait';
html += LibraryBrowser.getPosterViewHtml({
items: items,
shape: shape,
showTitle: true,
centerText: true
});
html += '
';
html += '
';
$('.collectionItems', page).append(html);
}
function renderUserDataIcons(page, item) {
$('.userDataIcons', page).html(LibraryBrowser.getUserDataIconsHtml(item));
}
function renderCriticReviews(page, item, limit) {
if (item.Type != "Movie" && item.Type != "Trailer" && item.Type != "MusicVideo") {
$('#criticReviewsCollapsible', page).hide();
return;
}
var options = {};
if (limit) {
options.limit = limit;
}
ApiClient.getCriticReviews(item.Id, options).done(function (result) {
if (result.TotalRecordCount || item.CriticRatingSummary || item.AwardSummary) {
$('#criticReviewsCollapsible', page).show();
renderCriticReviewsContent(page, result, limit);
} else {
$('#criticReviewsCollapsible', page).hide();
}
});
}
function renderCriticReviewsContent(page, result, limit) {
var html = '';
var reviews = result.Items;
for (var i = 0, length = reviews.length; i < length; i++) {
var review = reviews[i];
html += '
';
html += '
';
if (review.Score != null) {
html += review.Score;
}
else if (review.Likes != null) {
if (review.Likes) {
html += '';
} else {
html += '';
}
}
html += '
';
html += '
' + review.Caption + '
';
var vals = [];
if (review.ReviewerName) {
vals.push(review.ReviewerName);
}
if (review.Publisher) {
vals.push(review.Publisher);
}
html += '
' + vals.join(', ') + '.';
if (review.Date) {
try {
var date = parseISO8601Date(review.Date, { toLocal: true }).toLocaleDateString();
html += '' + date + '';
}
catch (error) {
}
}
html += '
';
html += '';
}
if (limit && chapters.length > limit) {
html += '';
}
$('#scenesContent', page).html(html).trigger('create');
}
function renderMediaSources(page, item) {
var html = item.MediaSources.map(function (v) {
return getMediaSourceHtml(item, v);
}).join('');
if (item.MediaSources.length > 1) {
html = ' ' + html;
}
$('#mediaInfoContent', page).html(html).trigger('create');
}
function getMediaSourceHtml(item, version) {
var html = '';
if (version.Name && item.MediaSources.length > 1) {
html += '
' + version.Name + '
';
}
for (var i = 0, length = version.MediaStreams.length; i < length; i++) {
var stream = version.MediaStreams[i];
if (stream.Type == "Data") {
continue;
}
var type = stream.Type.replace('EmbeddedImage', 'Embedded Image');
html += '
';
html += '
' + type + '
';
var attributes = [];
if (stream.Language && stream.Type != "Video") {
attributes.push(createAttribute("Language", stream.Language));
}
if (stream.Codec) {
attributes.push(createAttribute("Codec", stream.Codec.toUpperCase()));
}
if (stream.Profile) {
attributes.push(createAttribute("Profile", stream.Profile));
}
if (stream.Level) {
attributes.push(createAttribute("Level", stream.Level));
}
if (stream.Width || stream.Height) {
attributes.push(createAttribute("Resolution", stream.Width + 'x' + stream.Height));
}
if (stream.AspectRatio && stream.Codec != "mjpeg") {
attributes.push(createAttribute("Aspect Ratio", stream.AspectRatio));
}
if (type == "Video") {
attributes.push(createAttribute("Interlaced", (stream.IsInterlaced ? 'Yes' : 'No')));
}
if (stream.AverageFrameRate || stream.RealFrameRate) {
attributes.push(createAttribute("Framerate", (stream.AverageFrameRate || stream.RealFrameRate)));
}
if (stream.ChannelLayout) {
attributes.push(createAttribute("Layout", stream.ChannelLayout));
}
else if (stream.Channels) {
attributes.push(createAttribute("Channels", stream.Channels + ' ch'));
}
if (stream.BitRate && stream.Codec != "mjpeg") {
attributes.push(createAttribute("Bitrate", (parseInt(stream.BitRate / 1000)) + ' kbps'));
}
if (stream.SampleRate) {
attributes.push(createAttribute("Sample Rate", stream.SampleRate + ' khz'));
}
if (stream.BitDepth) {
attributes.push(createAttribute("Bit Depth", stream.BitDepth + ' bit'));
}
if (stream.PixelFormat) {
attributes.push(createAttribute("Pixel Format", stream.PixelFormat));
}
if (stream.Type != "Video") {
attributes.push(createAttribute("Default", (stream.IsDefault ? 'Yes' : 'No')));
}
if (stream.Type == "Subtitle") {
attributes.push(createAttribute("Forced", (stream.IsForced ? 'Yes' : 'No')));
attributes.push(createAttribute("External", (stream.IsExternal ? 'Yes' : 'No')));
}
if (stream.Type == "Video" && version.Timestamp) {
attributes.push(createAttribute("Timestamp", version.Timestamp));
}
html += attributes.join(' ');
html += '
';
}
if (version.Size) {
var size = (version.Size / (1024 * 1024)).toFixed(0);
html += '
Size' + size + ' MB
';
}
if (version.Path) {
html += '
Path' + version.Path + '
';
}
if (version.Container) {
//html += '
Container' + version.Container + '
';
}
if (version.Formats && version.Formats.length) {
//html += '