(function ($, document, LibraryBrowser, window) { var currentItem; function reload(page) { var id = getParameterByName('id'); Dashboard.showLoadingMsg(); ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) { currentItem = item; renderHeader(page, item); var name = item.Name; if (item.IndexNumber != null) { name = item.IndexNumber + " - " + name; } if (item.ParentIndexNumber != null) { name = item.ParentIndexNumber + "." + name; } $('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item)); Dashboard.setPageTitle(name); $('#itemName', page).html(name); if (item.SeriesName) { $('#seriesName', page).html('' + item.SeriesName + '').show().trigger('create'); } else if (item.Album && item.Type == "Audio") { $('#seriesName', page).html('' + item.Album + '').show().trigger('create'); } else if (item.Album) { $('#seriesName', page).html(item.Album).show(); } else { $('#seriesName', page).hide(); } setInitialCollapsibleState(page, item); renderDetails(page, item); if (MediaPlayer.canPlay(item)) { $('#btnPlayMenu', page).show(); $('#playButtonShadow', page).show(); if (MediaPlayer.isPlaying()) $('#btnQueueMenu', page).show(); else $('#btnQueueMenu', page).hide(); } else { $('#btnPlayMenu', page).hide(); $('#playButtonShadow', page).hide(); $('#btnQueueMenu', page).hide(); } Dashboard.hideLoadingMsg(); }); } function enableCustomHeader(page, text) { var elem = $('.libraryPageHeader', page).show(); $('span', elem).html(text); } function renderHeader(page, item) { if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "BoxSet") { enableCustomHeader(page, "Movies"); $('#standardLogo', page).hide(); } else if (item.Type == "Episode" || item.Type == "Season" || item.Type == "Series") { enableCustomHeader(page, "TV Shows"); $('#standardLogo', page).hide(); } else if (item.Type == "Audio" || item.Type == "MusicAlbum") { enableCustomHeader(page, "Music"); $('#standardLogo', page).hide(); } else { $('.libraryPageHeader', page).hide(); $('#standardLogo', page).show(); } if (item.Type == "MusicAlbum") { $('#albumTabs', page).show(); } else { $('#albumTabs', page).hide(); } if (item.Type == "Audio") { $('#songTabs', page).show(); } else { $('#songTabs', page).hide(); } if (item.Type == "Movie") { $('#movieTabs', page).show(); } else { $('#movieTabs', page).hide(); } if (item.Type == "BoxSet") { $('#boxsetTabs', page).show(); } else { $('#boxsetTabs', page).hide(); } if (item.Type == "Trailer") { $('#trailerTabs', page).show(); } else { $('#trailerTabs', page).hide(); } if (item.Type == "Episode" || item.Type == "Season" || item.Type == "Series") { $('#tvShowsTabs', page).show(); } else { $('#tvShowsTabs', page).hide(); } } function setInitialCollapsibleState(page, item) { if (item.ChildCount) { $('#childrenCollapsible', page).show(); renderChildren(page, item); } else { $('#childrenCollapsible', page).hide(); } if (LibraryBrowser.shouldDisplayGallery(item)) { $('#galleryCollapsible', page).show(); renderGallery(page, item); } else { $('#galleryCollapsible', page).hide(); } if (!item.MediaStreams || !item.MediaStreams.length) { $('#mediaInfoCollapsible', page).hide(); } else { $('#mediaInfoCollapsible', page).show(); renderMediaInfo(page, item); } if (!item.Chapters || !item.Chapters.length) { $('#scenesCollapsible', page).hide(); } else { $('#scenesCollapsible', page).show(); renderScenes(page, item); } if (!item.LocalTrailerCount || item.LocalTrailerCount == 0) { $('#trailersCollapsible', page).hide(); } else { $('#trailersCollapsible', page).show(); renderTrailers(page, item); } if (!item.SpecialFeatureCount || item.SpecialFeatureCount == 0) { $('#specialsCollapsible', page).hide(); } else { $('#specialsCollapsible', page).show(); renderSpecials(page, item); } if (!item.People || !item.People.length) { $('#castCollapsible', page).hide(); } else { $('#castCollapsible', page).show(); renderCast(page, item); } } function renderDetails(page, item) { if (item.Taglines && item.Taglines.length) { $('#itemTagline', page).html(item.Taglines[0]).show(); } else { $('#itemTagline', page).hide(); } LibraryBrowser.renderOverview($('#itemOverview', page), item); if (item.CommunityRating) { $('#itemCommunityRating', page).html(LibraryBrowser.getStarRatingHtml(item)).show().attr('title', item.CommunityRating); } else { $('#itemCommunityRating', page).hide(); } LibraryBrowser.renderPremiereDate($('#itemPremiereDate', page), item); LibraryBrowser.renderBudget($('#itemBudget', page), item); LibraryBrowser.renderRevenue($('#itemRevenue', page), item); $('#itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(item)); LibraryBrowser.renderGenres($('#itemGenres', page), item); LibraryBrowser.renderStudios($('#itemStudios', page), item); renderUserDataIcons(page, item); LibraryBrowser.renderLinks($('#itemLinks', page), item); } function renderChildren(page, item) { ApiClient.getItems(Dashboard.getCurrentUserId(), { ParentId: getParameterByName('id'), SortBy: "SortName", Fields: "PrimaryImageAspectRatio,ItemCounts,DisplayMediaType,DateCreated,UserData" }).done(function (result) { if (item.Type == "MusicAlbum") { $('#childrenContent', page).html(LibraryBrowser.getSongTableHtml(result.Items)).trigger('create'); } else { var html = LibraryBrowser.getPosterDetailViewHtml({ items: result.Items, useAverageAspectRatio: true }); $('#childrenContent', page).html(html); } }); if (item.Type == "Season") { $('#childrenTitle', page).html('Episodes (' + item.ChildCount + ')'); } else if (item.Type == "Series") { $('#childrenTitle', page).html('Seasons (' + item.ChildCount + ')'); } else if (item.Type == "BoxSet") { $('#childrenTitle', page).html('Movies (' + item.ChildCount + ')'); } else if (item.Type == "MusicAlbum") { $('#childrenTitle', page).html('Tracks (' + item.ChildCount + ')'); } else { $('#childrenTitle', page).html('Items (' + item.ChildCount + ')'); } } function renderUserDataIcons(page, item) { $('#itemRatings', page).html(LibraryBrowser.getUserDataIconsHtml(item)); } function renderScenes(page, item) { var html = ''; var chapters = item.Chapters || {}; for (var i = 0, length = chapters.length; i < length; i++) { var chapter = chapters[i]; var chapterName = chapter.Name || "Chapter " + i; html += '
'; html += ''; if (chapter.ImageTag) { var imgUrl = ApiClient.getImageUrl(item.Id, { width: 400, tag: chapter.ImageTag, type: "Chapter", index: i }); html += ''; } else { html += ''; } html += '
' + chapterName + '
'; html += '
'; html += ticks_to_human(chapter.StartPositionTicks); html += '
'; html += '
'; html += '
'; } $('#scenesContent', page).html(html); } function renderGallery(page, item) { var html = LibraryBrowser.getGalleryHtml(item); $('#galleryContent', page).html(html).trigger('create'); } function renderMediaInfo(page, item) { var html = ''; for (var i = 0, length = item.MediaStreams.length; i < length; i++) { var stream = item.MediaStreams[i]; if (stream.Type == "Data") { continue; } var type; if (item.MediaType == "Audio" && stream.Type == "Video") { type = "Embedded Image"; } else { type = stream.Type; } html += '
'; html += '

' + type + '

'; html += ''; html += '
'; } $('#mediaInfoContent', page).html(html).trigger('create'); } function renderSpecials(page, item) { var html = ''; ApiClient.getSpecialFeatures(Dashboard.getCurrentUserId(), item.Id).done(function (specials) { for (var i = 0, length = specials.length; i < length; i++) { var special = specials[i]; html += '
'; html += ''; var imageTags = special.ImageTags || {}; if (imageTags.Primary) { var imgUrl = ApiClient.getImageUrl(special.Id, { maxwidth: 500, tag: imageTags.Primary, type: "primary" }); html += ''; } else { html += ''; } html += '
' + special.Name + '
'; html += '
'; if (special.RunTimeTicks != "") { html += ticks_to_human(special.RunTimeTicks); } else { html += " "; } html += '
'; html += '
'; html += '
'; } $('#specialsContent', page).html(html); }); } function renderTrailers(page, item) { var html = ''; ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), item.Id).done(function (trailers) { for (var i = 0, length = trailers.length; i < length; i++) { var trailer = trailers[i]; html += '
'; html += ''; var imageTags = trailer.ImageTags || {}; if (imageTags.Primary) { var imgUrl = ApiClient.getImageUrl(trailer.Id, { maxwidth: 500, tag: imageTags.Primary, type: "primary" }); html += ''; } else { html += ''; } html += '
' + trailer.Name + '
'; html += '
'; if (trailer.RunTimeTicks != "") { html += ticks_to_human(trailer.RunTimeTicks); } else { html += " "; } html += '
'; html += '
'; html += '
'; } $('#trailersContent', page).html(html); }); } function renderCast(page, item) { var html = ''; var casts = item.People || []; for (var i = 0, length = casts.length; i < length; i++) { var cast = casts[i]; html += LibraryBrowser.createCastImage(cast); } $('#castContent', page).html(html); } function play(startPosition) { MediaPlayer.play([currentItem], startPosition); } $(document).on('pageinit', "#itemDetailPage", function () { var page = this; $('#btnPlayMenu', page).on('click', function () { var userdata = currentItem.UserData || {}; if (userdata.PlaybackPositionTicks) { var pos = $('#playMenuAnchor', page).offset(); $('#playMenu', page).popup("open", { x: pos.left + 125, y: pos.top + 20 }); } else { play(); } }); $('#btnQueueMenu', page).on('click', function () { var pos = $('#queueMenuAnchor', page).offset(); $('#queueMenu', page).popup("open", { x: pos.left + 165, y: pos.top + 20 }); }); $('#btnPlay', page).on('click', function () { $('#playMenu', page).popup("close"); play(); }); $('#btnResume', page).on('click', function () { $('#playMenu', page).popup("close"); var userdata = currentItem.UserData || {}; play(userdata.PlaybackPositionTicks); }); $('#btnQueue', page).on('click', function () { $('#queueMenu', page).popup("close"); Playlist.add(currentItem); }); }).on('pageshow', "#itemDetailPage", function () { var page = this; reload(page); }).on('pagehide', "#itemDetailPage", function () { currentItem = null; }); function itemDetailPage() { var self = this; self.play = play; 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]]); }); }; } window.ItemDetailPage = new itemDetailPage(); })(jQuery, document, LibraryBrowser, window);