jellyfin-web/dashboard-ui/scripts/Itemdetailpage.js

516 lines
16 KiB
JavaScript
Raw Normal View History

2013-04-10 14:14:25 -07:00
(function ($, document, LibraryBrowser, window) {
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
var currentItem;
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
function reload(page) {
2013-03-06 16:28:43 -07:00
2013-02-20 18:33:05 -07:00
var id = getParameterByName('id');
Dashboard.showLoadingMsg();
2013-04-10 14:14:25 -07:00
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
currentItem = item;
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
var name = item.Name;
2013-03-06 16:28:43 -07:00
2013-04-10 14:14:25 -07:00
if (item.IndexNumber != null) {
name = item.IndexNumber + " - " + name;
}
if (item.ParentIndexNumber != null) {
name = item.ParentIndexNumber + "." + name;
}
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item));
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
Dashboard.setPageTitle(name);
2013-03-26 14:32:01 -07:00
2013-04-10 14:14:25 -07:00
$('#itemName', page).html(name);
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
if (item.SeriesName || item.Album) {
var seriesName = item.SeriesName || item.Album;
$('#seriesName', page).html(seriesName).show();
}
setInitialCollapsibleState(page, item);
renderDetails(page, item);
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
if (MediaPlayer.canPlay(item)) {
$('#btnPlayMenu', page).show();
$('#playButtonShadow', page).show();
2013-04-11 05:49:14 -07:00
$('#btnQueueMenu', page).hide();
2013-04-10 14:14:25 -07:00
} else {
$('#btnPlayMenu', page).hide();
$('#playButtonShadow', page).hide();
2013-04-14 08:14:10 -07:00
$('#btnQueueMenu', page).hide();
2013-04-10 14:14:25 -07:00
}
if (LibraryBrowser.shouldDisplayGallery(item)) {
$('#galleryCollapsible', page).show();
} else {
$('#galleryCollapsible', page).hide();
}
2013-04-10 14:14:25 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-04-10 14:14:25 -07:00
function setInitialCollapsibleState(page, item) {
2013-04-14 08:14:10 -07:00
2013-03-26 16:57:18 -07:00
if (!item.MediaStreams || !item.MediaStreams.length) {
$('#mediaInfoCollapsible', page).hide();
2013-03-29 07:12:14 -07:00
} else {
2013-03-26 16:57:18 -07:00
$('#mediaInfoCollapsible', page).show();
}
if (!item.Chapters || !item.Chapters.length) {
2013-03-26 14:32:01 -07:00
$('#scenesCollapsible', page).hide();
} else {
2013-03-26 15:53:06 -07:00
$('#scenesCollapsible', page).show();
}
if (!item.LocalTrailerCount || item.LocalTrailerCount == 0) {
2013-03-26 14:32:01 -07:00
$('#trailersCollapsible', page).hide();
} else {
2013-03-26 15:53:06 -07:00
$('#trailersCollapsible', page).show();
}
if (!item.SpecialFeatureCount || item.SpecialFeatureCount == 0) {
2013-03-26 14:32:01 -07:00
$('#specialsCollapsible', page).hide();
} else {
2013-03-26 15:53:06 -07:00
$('#specialsCollapsible', page).show();
}
2013-03-26 22:20:46 -07:00
if (!item.People || !item.People.length) {
$('#castCollapsible', page).hide();
} else {
$('#castCollapsible', page).show();
}
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderDetails(page, item) {
2013-02-20 18:33:05 -07:00
if (item.Taglines && item.Taglines.length) {
$('#itemTagline', page).html(item.Taglines[0]).show();
} else {
$('#itemTagline', page).hide();
}
2013-03-26 15:53:06 -07:00
if (item.Overview || item.OverviewHtml) {
var overview = item.OverviewHtml || item.Overview;
$('#itemOverview', page).html(overview).show();
2013-03-29 07:12:14 -07:00
$('#itemOverview a').each(function () {
$(this).attr("target", "_blank");
2013-03-26 15:53:06 -07:00
});
2013-02-20 18:33:05 -07:00
} else {
$('#itemOverview', page).hide();
}
if (item.CommunityRating) {
2013-04-10 06:53:44 -07:00
$('#itemCommunityRating', page).html(LibraryBrowser.getStarRatingHtml(item)).show().attr('title', item.CommunityRating);
2013-02-20 18:33:05 -07:00
} else {
$('#itemCommunityRating', page).hide();
}
2013-04-12 08:25:00 -07:00
LibraryBrowser.renderBudget($('#itemBudget', page), item);
2013-04-10 14:14:25 -07:00
$('#itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(item));
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
LibraryBrowser.renderGenres($('#itemGenres', page), item);
LibraryBrowser.renderStudios($('#itemStudios', page), item);
renderUserDataIcons(page, item);
2013-04-14 08:14:10 -07:00
LibraryBrowser.renderLinks($('#itemLinks', page), item);
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderUserDataIcons(page, item) {
$('#itemRatings', page).html(LibraryBrowser.getUserDataIconsHtml(item));
}
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
function renderScenes(page, item) {
2013-02-20 18:33:05 -07:00
var html = '';
2013-04-10 14:14:25 -07:00
var chapters = item.Chapters || {};
2013-02-20 18:33:05 -07:00
for (var i = 0, length = chapters.length; i < length; i++) {
var chapter = chapters[i];
2013-04-10 10:11:23 -07:00
var chapterName = chapter.Name || "Chapter " + i;
html += '<div class="posterViewItem posterViewItemWithDualText">';
2013-03-26 14:32:01 -07:00
html += '<a href="#play-Chapter-' + i + '" onclick="ItemDetailPage.play(' + chapter.StartPositionTicks + ');">';
if (chapter.ImageTag) {
var imgUrl = ApiClient.getImageUrl(item.Id, {
width: 500,
tag: chapter.ImageTag,
type: "Chapter",
index: i
});
2013-02-20 18:33:05 -07:00
html += '<img src="' + imgUrl + '" />';
} else {
2013-03-26 10:21:14 -07:00
html += '<img src="css/images/items/list/chapter.png"/>';
}
2013-02-20 18:33:05 -07:00
2013-04-10 10:11:23 -07:00
html += '<div class="posterViewItemText posterViewItemPrimaryText">' + chapterName + '</div>';
html += '<div class="posterViewItemText">';
2013-02-20 18:33:05 -07:00
2013-03-26 15:53:06 -07:00
html += ticks_to_human(chapter.StartPositionTicks);
html += '</div>';
html += '</a>';
html += '</div>';
2013-02-20 18:33:05 -07:00
}
$('#scenesContent', page).html(html);
2013-04-10 14:14:25 -07:00
}
2013-03-06 16:28:43 -07:00
2013-04-10 14:14:25 -07:00
function renderGallery(page, item) {
2013-02-20 18:33:05 -07:00
2013-04-15 18:09:27 -07:00
var html = LibraryBrowser.getGalleryHtml(item);
2013-04-15 15:13:55 -07:00
$('#galleryContent', page).html(html).trigger('create');
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderMediaInfo(page, item) {
2013-03-26 14:32:01 -07:00
2013-03-26 16:57:18 -07:00
var html = '';
for (var i = 0, length = item.MediaStreams.length; i < length; i++) {
var stream = item.MediaStreams[i];
2013-04-09 11:01:39 -07:00
if (stream.Type == "Data") {
continue;
}
2013-04-09 11:38:58 -07:00
var type;
if (item.MediaType == "Audio" && stream.Type == "Video") {
type = "Embedded Image";
} else {
type = stream.Type;
}
2013-04-09 11:38:58 -07:00
html += '<div class="mediaInfoStream">';
2013-03-26 16:57:18 -07:00
2013-04-09 11:38:58 -07:00
html += '<p class="mediaInfoStreamType">' + type + '</p>';
2013-04-09 19:28:24 -07:00
2013-04-09 11:38:58 -07:00
html += '<ul class="mediaInfoDetails">';
2013-04-09 19:28:24 -07:00
2013-04-09 11:38:58 -07:00
if (stream.Codec) {
html += '<li><span class="mediaInfoLabel">Codec</span> ' + stream.Codec + '</li>';
}
if (stream.Profile) {
html += '<li><span class="mediaInfoLabel">Profile</span> ' + stream.Profile + '</li>';
}
if (stream.Level) {
html += '<li><span class="mediaInfoLabel">Level</span> ' + stream.Level + '</li>';
}
if (stream.Language) {
2013-04-09 11:38:58 -07:00
html += '<li><span class="mediaInfoLabel">Language</span> ' + stream.Language + '</li>';
}
if (stream.Width) {
html += '<li><span class="mediaInfoLabel">Width</span> ' + stream.Width + '</li>';
}
if (stream.Height) {
html += '<li><span class="mediaInfoLabel">Height</span> ' + stream.Height + '</li>';
}
if (stream.AspectRatio) {
html += '<li><span class="mediaInfoLabel">Aspect Ratio</span> ' + stream.AspectRatio + '</li>';
}
if (stream.Bitrate) {
html += '<li><span class="mediaInfoLabel">Bitrate</span> ' + stream.Bitrate + '</li>';
}
if (stream.Channels) {
2013-04-09 11:38:58 -07:00
html += '<li><span class="mediaInfoLabel">Channels</span> ' + stream.Channels + '</li>';
2013-03-26 16:57:18 -07:00
}
2013-04-09 12:38:19 -07:00
if (stream.SampleRate) {
html += '<li><span class="mediaInfoLabel">Sample Rate</span> ' + stream.SampleRate + '</li>';
}
2013-04-09 11:38:58 -07:00
var framerate = stream.AverageFrameRate || stream.RealFrameRate;
2013-04-09 19:28:24 -07:00
2013-04-09 11:38:58 -07:00
if (framerate) {
html += '<li><span class="mediaInfoLabel">Framerate</span> ' + framerate + '</li>';
}
2013-04-09 19:28:24 -07:00
2013-04-09 12:38:19 -07:00
if (stream.PixelFormat) {
html += '<li><span class="mediaInfoLabel">Pixel Format</span> ' + stream.PixelFormat + '</li>';
}
2013-04-09 11:38:58 -07:00
if (stream.IsDefault) {
html += '<li>Default</li>';
}
if (stream.IsForced) {
html += '<li>Forced</li>';
}
if (stream.IsExternal) {
html += '<li>External</li>';
}
if (stream.Path) {
html += '<li><span class="mediaInfoLabel">Path</span> ' + stream.Path + '</li>';
2013-03-26 16:57:18 -07:00
}
2013-04-09 11:38:58 -07:00
html += '</ul>';
2013-04-09 11:38:58 -07:00
html += '</div>';
2013-02-20 18:33:05 -07:00
}
2013-03-26 16:57:18 -07:00
$('#mediaInfoContent', page).html(html).trigger('create');
2013-04-09 11:38:58 -07:00
2013-02-20 18:33:05 -07:00
$('#mediaInfoCollapsible', page).show();
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderSpecials(page, item) {
var html = '';
2013-04-10 14:14:25 -07:00
ApiClient.getSpecialFeatures(Dashboard.getCurrentUserId(), item.Id).done(function (specials) {
2013-04-10 14:14:25 -07:00
for (var i = 0, length = specials.length; i < length; i++) {
2013-04-10 14:14:25 -07:00
var special = specials[i];
2013-03-26 14:32:01 -07:00
html += '<div class="posterViewItem posterViewItemWithDualText">';
2013-04-10 14:14:25 -07:00
html += '<a href="#play-Special-' + i + '" onclick="ItemDetailPage.playSpecial(' + i + ');">';
2013-04-10 14:14:25 -07:00
var imageTags = special.ImageTags || {};
2013-03-29 07:12:14 -07:00
2013-03-26 14:32:01 -07:00
if (imageTags.Primary) {
2013-04-10 14:14:25 -07:00
var imgUrl = ApiClient.getImageUrl(special.Id, {
2013-03-26 14:32:01 -07:00
maxwidth: 500,
tag: imageTags.Primary,
type: "primary"
});
2013-03-26 14:32:01 -07:00
html += '<img src="' + imgUrl + '" />';
} else {
html += '<img src="css/images/items/detail/video.png"/>';
}
2013-04-10 14:14:25 -07:00
html += '<div class="posterViewItemText posterViewItemPrimaryText">' + special.Name + '</div>';
2013-03-26 14:32:01 -07:00
html += '<div class="posterViewItemText">';
2013-04-10 14:14:25 -07:00
if (special.RunTimeTicks != "") {
html += ticks_to_human(special.RunTimeTicks);
2013-03-26 14:32:01 -07:00
}
else {
html += "&nbsp;";
2013-03-26 14:32:01 -07:00
}
html += '</div>';
2013-03-26 14:32:01 -07:00
html += '</a>';
2013-03-26 14:32:01 -07:00
html += '</div>';
}
2013-04-10 14:14:25 -07:00
$('#specialsContent', page).html(html);
});
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderTrailers(page, item) {
var html = '';
2013-04-10 14:14:25 -07:00
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), item.Id).done(function (trailers) {
2013-04-10 14:14:25 -07:00
for (var i = 0, length = trailers.length; i < length; i++) {
2013-04-10 14:14:25 -07:00
var trailer = trailers[i];
html += '<div class="posterViewItem posterViewItemWithDualText">';
2013-04-10 14:14:25 -07:00
html += '<a href="#play-Trailer-' + i + '" onclick="ItemDetailPage.playTrailer(' + i + ');">';
2013-04-10 14:14:25 -07:00
var imageTags = trailer.ImageTags || {};
2013-03-26 14:32:01 -07:00
if (imageTags.Primary) {
2013-04-10 14:14:25 -07:00
var imgUrl = ApiClient.getImageUrl(trailer.Id, {
2013-03-26 14:32:01 -07:00
maxwidth: 500,
tag: imageTags.Primary,
type: "primary"
});
html += '<img src="' + imgUrl + '" />';
} else {
2013-03-26 14:32:01 -07:00
html += '<img src="css/images/items/detail/video.png"/>';
}
2013-04-10 14:14:25 -07:00
html += '<div class="posterViewItemText posterViewItemPrimaryText">' + trailer.Name + '</div>';
html += '<div class="posterViewItemText">';
2013-04-10 14:14:25 -07:00
if (trailer.RunTimeTicks != "") {
html += ticks_to_human(trailer.RunTimeTicks);
}
else {
html += "&nbsp;";
}
html += '</div>';
html += '</a>';
html += '</div>';
}
2013-04-10 14:14:25 -07:00
$('#trailersContent', page).html(html);
});
2013-04-10 14:14:25 -07:00
}
2013-03-26 22:20:46 -07:00
2013-04-10 14:14:25 -07:00
function renderCast(page, item) {
2013-03-26 22:20:46 -07:00
var html = '';
2013-04-10 14:14:25 -07:00
var casts = item.People || [];
2013-03-26 22:20:46 -07:00
for (var i = 0, length = casts.length; i < length; i++) {
var cast = casts[i];
2013-03-26 22:20:46 -07:00
html += LibraryBrowser.createCastImage(cast);
2013-03-26 22:20:46 -07:00
}
$('#castContent', page).html(html);
2013-04-10 14:14:25 -07:00
}
2013-04-14 08:14:10 -07:00
2013-04-10 14:14:25 -07:00
function play(startPosition) {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
MediaPlayer.play([currentItem], startPosition);
}
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$(document).on('pageinit', "#itemDetailPage", function () {
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
var page = this;
2013-04-04 10:27:36 -07:00
2013-04-10 14:14:25 -07:00
$('#btnPlayMenu', page).on('click', function () {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
var userdata = currentItem.UserData || {};
2013-03-28 22:51:45 -07:00
if (userdata.PlaybackPositionTicks) {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
var pos = $('#playMenuAnchor', page).offset();
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#playMenu', page).popup("open", {
x: pos.left + 125,
y: pos.top + 20
});
2013-03-29 07:12:14 -07:00
}
else {
play();
}
2013-04-10 14:14:25 -07:00
});
2013-03-28 22:51:45 -07:00
2013-04-14 08:14:10 -07:00
$('#btnQueueMenu', page).on('click', function () {
var pos = $('#queueMenuAnchor', page).offset();
2013-04-14 08:14:10 -07:00
$('#queueMenu', page).popup("open", {
x: pos.left + 165,
y: pos.top + 20
});
});
2013-04-10 14:14:25 -07:00
$('#btnPlay', page).on('click', function () {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#playMenu', page).popup("close");
play();
});
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#btnResume', page).on('click', function () {
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
$('#playMenu', page).popup("close");
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
var userdata = currentItem.UserData || {};
2013-04-14 08:14:10 -07:00
2013-04-10 14:14:25 -07:00
play(userdata.PlaybackPositionTicks);
});
2013-03-29 07:12:14 -07:00
2013-04-14 08:14:10 -07:00
$('#btnQueue', page).on('click', function () {
2013-04-14 08:14:10 -07:00
$('#queueMenu', page).popup("close");
Playlist.add(currentItem);
});
2013-04-10 14:14:25 -07:00
}).on('pageshow', "#itemDetailPage", function () {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
var page = this;
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
reload(page);
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#mediaInfoCollapsible', page).on('expand.lazyload', function () {
renderMediaInfo(page, currentItem);
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
$(this).off('expand.lazyload');
});
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#scenesCollapsible', page).on('expand.lazyload', function () {
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
if (currentItem) {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
renderScenes(page, currentItem);
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$(this).off('expand.lazyload');
}
});
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$('#specialsCollapsible', page).on('expand.lazyload', function () {
renderSpecials(page, currentItem);
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$(this).off('expand.lazyload');
});
$('#trailersCollapsible', page).on('expand.lazyload', function () {
renderTrailers(page, currentItem);
$(this).off('expand.lazyload');
});
$('#castCollapsible', page).on('expand.lazyload', function () {
renderCast(page, currentItem);
$(this).off('expand.lazyload');
});
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
$('#galleryCollapsible', page).on('expand.lazyload', function () {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
renderGallery(page, currentItem);
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$(this).off('expand.lazyload');
});
}).on('pagehide', "#itemDetailPage", function () {
2013-04-10 14:14:25 -07:00
currentItem = null;
var page = this;
2013-04-10 14:14:25 -07:00
$('#mediaInfoCollapsible', page).off('expand.lazyload');
$('#scenesCollapsible', page).off('expand.lazyload');
$('#specialsCollapsible', page).off('expand.lazyload');
$('#trailersCollapsible', page).off('expand.lazyload');
$('#castCollapsible', page).off('expand.lazyload');
$('#galleryCollapsible', page).off('expand.lazyload');
});
2013-04-14 08:14:10 -07:00
2013-04-10 14:14:25 -07:00
function itemDetailPage() {
2013-04-10 14:14:25 -07:00
var self = this;
2013-04-10 14:14:25 -07:00
self.play = play;
2013-04-10 14:14:25 -07:00
self.playTrailer = function (index) {
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), currentItem.Id).done(function (trailers) {
MediaPlayer.play([trailers[index]]);
});
};
self.playSpecial = function (index) {
ApiClient.getSpecialFeatures(Dashboard.getCurrentUserId(), currentItem.Id).done(function (specials) {
MediaPlayer.play([specials[index]]);
});
};
2013-04-09 11:38:58 -07:00
}
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
window.ItemDetailPage = new itemDetailPage();
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
})(jQuery, document, LibraryBrowser, window);