var LibraryBrowser = (function (window, document, $) { var defaultBackground = "#999;"; return { getDetaultPageSize: function () { if (window.location.toString().toLowerCase().indexOf('localhost') != -1) { return 100; } return 20; }, getPosterDetailViewHtml: function (options) { var items = options.items; if (!options.shape) { options.shape = options.preferBackdrop ? "backdrop" : "poster"; } var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null; var html = ''; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; var imgUrl; var isDefault = false; var cssClass = "tileItem"; if (options.shape) { cssClass += " " + options.shape + "TileItem"; } html += ''; if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, { height: 198, width: 352 }); } else if (options.preferBackdrop && item.ImageTags && item.ImageTags.Thumb) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Thumb", height: 198, width: 352, tag: item.ImageTags.Thumb }); } else if (item.ImageTags && item.ImageTags.Primary) { var height = 300; var width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null; imgUrl = LibraryBrowser.getImageUrl(item, 'Primary', 0, { height: height, width: width }); } else if (item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, { height: 198, width: 352 }); } else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") { imgUrl = "css/images/items/list/audio.png"; isDefault = true; } else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") { imgUrl = "css/images/items/list/video.png"; isDefault = true; } else if (item.Type == "Person") { imgUrl = "css/images/items/list/person.png"; isDefault = true; } else if (item.Type == "Artist") { imgUrl = "css/images/items/list/audiocollection.png"; isDefault = true; } else if (item.MediaType == "Game") { imgUrl = "css/images/items/list/game.png"; isDefault = true; } else if (item.Type == "Studio" || item.Type == "Genre") { if (options.context == "games") { imgUrl = "css/images/items/list/game.png"; } else if (options.context == "music") { imgUrl = "css/images/items/list/audio.png"; } else if (options.context == "movies") { imgUrl = "css/images/items/list/chapter.png"; } else { imgUrl = "css/images/items/list/collection.png"; } isDefault = true; } else { imgUrl = "css/images/items/list/collection.png"; isDefault = true; } cssClass = isDefault ? "tileImage defaultTileImage" : "tileImage"; html += '
'; html += '
'; if (item.SeriesName || item.Album) { var seriesName = item.SeriesName || item.Album; html += '
' + seriesName + '
'; } var name = item.Name; if (item.IndexNumber != null) { name = item.IndexNumber + " - " + name; } if (item.ParentIndexNumber != null) { name = item.ParentIndexNumber + "." + name; } html += '
' + name + '
'; if (item.CommunityRating) { html += '

' + LibraryBrowser.getFiveStarRatingHtml(item) + '

'; } var childText; if (item.Type == "BoxSet") { childText = item.ChildCount == 1 ? "1 Movie" : item.ChildCount + " Movies"; html += '

' + childText + '

'; } else if (item.Type == "GamePlatform") { childText = item.ChildCount == 1 ? "1 Game" : item.ChildCount + " Games"; html += '

' + childText + '

'; } else if (item.Type == "MusicAlbum") { childText = item.ChildCount == 1 ? "1 Song" : item.ChildCount + " Songs"; html += '

' + childText + '

'; } else if (item.Type == "Genre" || item.Type == "Studio" || item.Type == "Person" || item.Type == "Artist") { childText = item.ChildCount == 1 ? "1 " + options.countNameSingular : item.ChildCount + " " + options.countNamePlural; html += '

' + childText + '

'; } else if (item.Type == "Game") { html += '

' + item.GameSystem + '

'; } else { html += '

' + LibraryBrowser.getMiscInfoHtml(item) + '

'; } if (item.Type == "MusicAlbum") { html += '

' + LibraryBrowser.getMiscInfoHtml(item) + '

'; } html += '

' + LibraryBrowser.getUserDataIconsHtml(item) + '

'; html += '
'; html += LibraryBrowser.getNewIndicatorHtml(item); html += "
"; } return html; }, getSongTableHtml: function (items, options) { options = options || {}; var html = ''; var cssClass = "detailTable"; html += '
'; html += ''; html += ''; html += ''; html += ''; if (options.showAlbum) { html += ''; } if (options.showArtist) { html += ''; } html += ''; html += ''; html += ''; html += ''; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; html += ''; html += ''; var num = item.IndexNumber; if (num && item.ParentIndexNumber) { num = item.ParentIndexNumber + "." + num; } html += ''; html += ''; if (options.showAlbum) { if (item.Album && item.ParentId) { html += ''; } else { html += ''; } } if (options.showArtist) { if (item.Artists && item.Artists.length) { var artist = item.Artists[0]; html += ''; } else { html += ''; } } var time = DashboardPage.getDisplayText(item.RunTimeTicks || 0); html += ''; html += ''; html += ''; html += ''; } html += '
TrackAlbumArtistDurationPlay Count
' + (num || "") + '' + (item.Name || "") + '' + item.Album + '' + artist + '' + time + '' + (item.UserData ? item.UserData.PlayCount : 0) + '' + LibraryBrowser.getUserDataIconsHtml(item) + '
'; return html; }, showPlayMenu: function (positionTo, itemId, mediaType, resumePositionTicks) { var isPlaying = MediaPlayer.isPlaying(); if (!isPlaying && !resumePositionTicks) { MediaPlayer.playById(itemId); return; } $('.playFlyout').popup("close").remove(); var html = '
'; html += ''; html += '
'; $($.mobile.activePage).append(html); $('.playFlyout').popup({ positionTo: positionTo || "window" }).trigger('create').popup("open").on("popupafterclose", function () { $(this).off("popupafterclose").remove(); }).parents(".ui-popup-container").css("margin-left", 100).css("margin-top", 35); }, closePlayMenu: function () { $('.playFlyout').popup("close").remove(); }, getHref: function (item, itemByNameContext) { if (item.url) { return item.url; } itemByNameContext = itemByNameContext || ""; // Handle search hints var id = item.Id || item.ItemId; if (item.Type == "Series") { return "itemdetails.html?id=" + id; } if (item.Type == "Season") { return "itemdetails.html?id=" + id; } if (item.Type == "BoxSet") { return "itemdetails.html?id=" + id; } if (item.Type == "MusicAlbum") { return "itemdetails.html?id=" + id; } if (item.Type == "GamePlatform") { return "itemdetails.html?id=" + id; } if (item.Type == "Genre") { return "itembynamedetails.html?genre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Studio") { return "itembynamedetails.html?studio=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Person") { return "itembynamedetails.html?person=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Artist") { return "itembynamedetails.html?artist=" + ApiClient.encodeName(item.Name) + "&context=" + (itemByNameContext || "music"); } return item.IsFolder ? (id ? "itemList.html?parentId=" + id : "#") : "itemdetails.html?id=" + id; }, getImageUrl: function (item, type, index, options) { options = options || {}; options.type = type; options.index = index; if (type == 'Backdrop') { options.tag = item.BackdropImageTags[index]; } else { options.tag = item.ImageTags[type]; } if (item.Type == "Studio") { return ApiClient.getStudioImageUrl(item.Name, options); } if (item.Type == "Person") { return ApiClient.getPersonImageUrl(item.Name, options); } if (item.Type == "Genre") { return ApiClient.getGenreImageUrl(item.Name, options); } if (item.Type == "Artist") { return ApiClient.getArtistImageUrl(item.Name, options); } // For search hints return ApiClient.getImageUrl(item.Id || item.ItemId, options); }, getPosterViewHtml: function (options) { var items = options.items; options.shape = options.shape || "portrait"; var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null; var html = ""; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; var imgUrl = null; var background; if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Backdrop", height: 198, width: 352, tag: item.BackdropImageTags[0] }); } else if (item.ImageTags && item.ImageTags.Primary) { var height = 300; var width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null; imgUrl = ApiClient.getImageUrl(item.Id, { type: "Primary", height: height, width: width, tag: item.ImageTags.Primary }); } else if (item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Backdrop", height: 198, width: 352, tag: item.BackdropImageTags[0] }); } else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/audio.png'; background = defaultBackground; } else { background = '#555'; } } else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/video.png'; background = defaultBackground; } else { background = '#555'; } } else { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/collection.png'; background = LibraryBrowser.getMetroColor(item.Id); } else { background = '#555'; } } var cssClass = "posterItem"; if (options.transparent !== false) { cssClass += " transparentPosterItem"; } cssClass += ' ' + options.shape + 'PosterItem'; html += ''; var style = ""; if (imgUrl) { style += 'background-image:url(\'' + imgUrl + '\');'; } if (background) { style += "background-color:" + background + ";"; } html += '
'; var name = item.Name; if (item.IndexNumber != null) { name = item.IndexNumber + " - " + name; } if (item.ParentIndexNumber != null) { name = item.ParentIndexNumber + "." + name; } if (!imgUrl && !options.showTitle) { html += "
"; html += name; html += "
"; } var cssclass = options.centerText ? "posterItemText posterItemTextCentered" : "posterItemText"; if (options.showParentTitle) { html += "
"; html += item.SeriesName || item.Album || " "; html += "
"; } if (options.showTitle) { html += "
"; html += name; html += "
"; } if (options.showNewIndicator !== false) { html += LibraryBrowser.getNewIndicatorHtml(item); } html += "
"; } return html; }, getNewIndicatorHtml: function (item) { if (item.RecentlyAddedItemCount) { return '
' + item.RecentlyAddedItemCount + ' New
'; } if (!item.IsFolder && item.Type !== "Genre" && item.Type !== "Studio" && item.Type !== "Person" && item.Type !== "Artist") { var date = item.DateCreated; try { if (date && (new Date().getTime() - parseISO8601Date(date).getTime()) < 1209600000) { return "
New
"; } } catch (err) { } } return ''; }, getAveragePrimaryImageAspectRatio: function (items) { var values = []; for (var i = 0, length = items.length; i < length; i++) { var ratio = items[i].PrimaryImageAspectRatio || 0; if (!ratio) { continue; } values[values.length] = ratio; } if (!values.length) { return null; } // Use the median values.sort(function (a, b) { return a - b; }); var half = Math.floor(values.length / 2); if (values.length % 2) return values[half]; else return (values[half - 1] + values[half]) / 2.0; }, metroColors: ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"], getRandomMetroColor: function () { var index = Math.floor(Math.random() * (LibraryBrowser.metroColors.length - 1)); return LibraryBrowser.metroColors[index]; }, getMetroColor: function (str) { if (str) { var char = String(str.substr(0, 1).charCodeAt()); var sum = 0; for (var i = 0; i < char.length; i++) { sum += parseInt(char.charAt(i)); } var index = String(sum).substr(-1); return LibraryBrowser.metroColors[index]; } else { return LibraryBrowser.getRandomMetroColor(); } }, renderLinks: function (linksElem, item) { var links = []; if (item.HomePageUrl) { links.push('Website'); } var providerIds = item.ProviderIds || {}; if (providerIds.Imdb) { if (item.Type == "Movie" || item.Type == "Episode") links.push('IMDb'); else if (item.Type == "Person") links.push('IMDb'); } if (providerIds.Tmdb) { if (item.Type == "Movie") links.push('TMDB'); else if (item.Type == "Person") links.push('TMDB'); } if (providerIds.Tvdb) links.push('TVDB'); if (providerIds.Tvcom) { if (item.Type == "Episode") links.push('TV.com'); else if (item.Type == "Person") links.push('TV.com'); } if (providerIds.Musicbrainz) { if (item.Type == "MusicArtist" || item.Type == "Artist") { links.push('MusicBrainz'); } else { links.push('MusicBrainz'); } } if (providerIds.Gamesdb) links.push('GamesDB'); if (links.length) { var html = 'Links:  ' + links.join('  /  '); $(linksElem).html(html); } else { $(linksElem).hide(); } }, getPagingHtml: function (query, totalRecordCount) { var html = ''; var pageCount = Math.ceil(totalRecordCount / query.Limit); var pageNumber = (query.StartIndex / query.Limit) + 1; var dropdownHtml = ''; var recordsEnd = Math.min(query.StartIndex + query.Limit, totalRecordCount); var showControls = totalRecordCount > query.Limit; html += '
'; html += ''; var startAtDisplay = totalRecordCount ? query.StartIndex + 1 : 0; html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount; if (showControls) { html += ', page ' + dropdownHtml + ' of ' + pageCount; } html += ''; if (showControls) { html += ''; html += ''; var id = "selectPageSize" + new Date().getTime(); var options = ''; function getOption(val) { if (query.Limit == val) { return ''; } else { return ''; } } options += getOption(20); options += getOption(50); options += getOption(100); options += getOption(200); options += getOption(300); html += ''; } html += '
'; return html; }, getStarRatingHtml: function (item) { var rating = item.CommunityRating; var html = ""; for (var i = 1; i <= 10; i++) { if (rating < i - 1) { html += "
"; } else if (rating < i) { html += "
"; } else { html += "
"; } } return html; }, getFiveStarRatingHtml: function (item) { var rating = item.CommunityRating / 2; var html = ""; for (var i = 1; i <= 5; i++) { if (rating < i - 1) { html += "
"; } else if (rating < i) { html += "
"; } else { html += "
"; } } return html; }, getUserDataIconsHtml: function (item) { var html = ''; var tooltip; var pct; if (item.PlayedPercentage) { tooltip = ''; pct = item.PlayedPercentage; } else if (item.UserData && item.UserData.PlaybackPositionTicks && item.RunTimeTicks) { tooltip = DashboardPage.getDisplayText(item.UserData.PlaybackPositionTicks) + " / " + DashboardPage.getDisplayText(item.RunTimeTicks); pct = (item.UserData.PlaybackPositionTicks / item.RunTimeTicks) * 100; } if (pct) { pct = parseInt(pct); html += '' + pct + '%'; } var userData = item.UserData || {}; var itemId = item.Id; var type = item.Type; if (type == "Person") { itemId = item.Name; } else if (type == "Studio") { itemId = item.Name; } else if (type == "Genre") { itemId = item.Name; } else if (type == "Artist") { itemId = item.Name; } if (item.MediaType || item.IsFolder) { if (userData.Played) { html += 'Played'; } else { html += 'Played'; } } if (typeof userData.Likes == "undefined") { html += 'Dislike'; html += 'Like'; } else if (userData.Likes) { html += 'Dislike'; html += 'Like'; } else { html += 'Dislike'; html += 'Like'; } if (userData.IsFavorite) { html += 'Favorite'; } else { html += 'Favorite'; } return html; }, markPlayed: function (link) { var id = link.getAttribute('data-itemid'); var $link = $(link); var markAsPlayed = $link.hasClass('imgPlayedOff'); ApiClient.updatePlayedStatus(Dashboard.getCurrentUserId(), id, markAsPlayed); if (markAsPlayed) { link.src = "css/images/userdata/played.png"; $link.addClass('imgPlayed').removeClass('imgPlayedOff'); } else { link.src = "css/images/userdata/unplayed.png"; $link.addClass('imgPlayedOff').removeClass('imgPlayed'); } }, markFavorite: function (link) { var id = link.getAttribute('data-itemid'); var type = link.getAttribute('data-type'); var $link = $(link); var markAsFavorite = $link.hasClass('imgFavoriteOff'); if (type == "Person") { ApiClient.updateFavoritePersonStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); } else if (type == "Studio") { ApiClient.updateFavoriteStudioStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); } else if (type == "Artist") { ApiClient.updateFavoriteArtistStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); } else if (type == "Genre") { ApiClient.updateFavoriteGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); } else { ApiClient.updateFavoriteStatus(Dashboard.getCurrentUserId(), id, markAsFavorite); } if (markAsFavorite) { link.src = "css/images/userdata/heart_on.png"; $link.addClass('imgFavorite').removeClass('imgFavoriteOff'); } else { link.src = "css/images/userdata/heart_off.png"; $link.addClass('imgFavoriteOff').removeClass('imgFavorite'); } }, markLike: function (link) { var id = link.getAttribute('data-itemid'); var type = link.getAttribute('data-type'); var $link = $(link); if ($link.hasClass('imgLikeOff')) { LibraryBrowser.updateUserItemRating(type, id, true); link.src = "css/images/userdata/thumbs_up_on.png"; $link.addClass('imgLike').removeClass('imgLikeOff'); } else { LibraryBrowser.clearUserItemRating(type, id); link.src = "css/images/userdata/thumbs_up_off.png"; $link.addClass('imgLikeOff').removeClass('imgLike'); } $link.prev().removeClass('imgDislike').addClass('imgDislikeOff').each(function () { this.src = "css/images/userdata/thumbs_down_off.png"; }); }, markDislike: function (link) { var id = link.getAttribute('data-itemid'); var type = link.getAttribute('data-type'); var $link = $(link); if ($link.hasClass('imgDislikeOff')) { LibraryBrowser.updateUserItemRating(type, id, false); link.src = "css/images/userdata/thumbs_down_on.png"; $link.addClass('imgDislike').removeClass('imgDislikeOff'); } else { LibraryBrowser.clearUserItemRating(type, id); link.src = "css/images/userdata/thumbs_down_off.png"; $link.addClass('imgDislikeOff').removeClass('imgDislike'); } $link.next().removeClass('imgLike').addClass('imgLikeOff').each(function () { this.src = "css/images/userdata/thumbs_up_off.png"; }); }, updateUserItemRating: function (type, id, likes) { if (type == "Person") { ApiClient.updatePersonRating(Dashboard.getCurrentUserId(), id, likes); } else if (type == "Studio") { ApiClient.updateStudioRating(Dashboard.getCurrentUserId(), id, likes); } else if (type == "Artist") { ApiClient.updateArtistRating(Dashboard.getCurrentUserId(), id, likes); } else if (type == "Genre") { ApiClient.updateGenreRating(Dashboard.getCurrentUserId(), id, likes); } else { ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, likes); } }, clearUserItemRating: function (type, id) { if (type == "Person") { ApiClient.clearPersonRating(Dashboard.getCurrentUserId(), id); } else if (type == "Studio") { ApiClient.clearStudioRating(Dashboard.getCurrentUserId(), id); } else if (type == "Artist") { ApiClient.clearArtistRating(Dashboard.getCurrentUserId(), id); } else if (type == "Genre") { ApiClient.clearGenreRating(Dashboard.getCurrentUserId(), id); } else { ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), id); } }, getDetailImageHtml: function (item) { var imageTags = item.ImageTags || {}; var html = ''; var url; var useBackgroundColor; var maxwidth; if (imageTags.Primary) { if (item.Type == "Person") { url = ApiClient.getPersonImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Primary, type: "Primary" }); } else if (item.Type == "Genre") { url = ApiClient.getGenreImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Primary, type: "Primary" }); } else if (item.Type == "Studio") { url = ApiClient.getStudioImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Primary, type: "Primary" }); } else if (item.Type == "Artist") { url = ApiClient.getArtistImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Primary, type: "Primary" }); } else { url = ApiClient.getImageUrl(item.Id, { type: "Primary", maxwidth: 800, tag: item.ImageTags.Primary }); } } else if (item.BackdropImageTags && item.BackdropImageTags.length) { if (item.Type == "Person") { url = ApiClient.getPersonImageUrl(item.Name, { maxwidth: 800, tag: item.BackdropImageTags[0], type: "Backdrop" }); } else if (item.Type == "Genre") { url = ApiClient.getGenreImageUrl(item.Name, { maxwidth: 800, tag: item.BackdropImageTags[0], type: "Backdrop" }); } else if (item.Type == "Studio") { url = ApiClient.getStudioImageUrl(item.Name, { maxwidth: 800, tag: item.BackdropImageTags[0], type: "Backdrop" }); } else if (item.Type == "Artist") { url = ApiClient.getArtistImageUrl(item.Name, { maxwidth: 800, tag: item.BackdropImageTags[0], type: "Backdrop" }); } else { url = ApiClient.getImageUrl(item.Id, { type: "Backdrop", maxwidth: 800, tag: item.BackdropImageTags[0] }); } } else if (imageTags.Thumb) { if (item.Type == "Person") { url = ApiClient.getPersonImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Thumb, type: "Thumb" }); } else if (item.Type == "Genre") { url = ApiClient.getGenreImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Thumb, type: "Thumb" }); } else if (item.Type == "Studio") { url = ApiClient.getStudioImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Thumb, type: "Thumb" }); } else if (item.Type == "Artist") { url = ApiClient.getArtistImageUrl(item.Name, { maxwidth: 800, tag: imageTags.Thumb, type: "Thumb" }); } else { url = ApiClient.getImageUrl(item.Id, { type: "Thumb", maxwidth: 800, tag: item.ImageTags.Thumb }); } } else if (imageTags.Disc) { url = ApiClient.getImageUrl(item.Id, { type: "Disc", maxwidth: 800, tag: item.ImageTags.Disc }); } else if (item.MediaType == "Audio" || item.Type == "MusicAlbum") { url = "css/images/items/detail/audio.png"; useBackgroundColor = true; } else if (item.MediaType == "Game") { url = "css/images/items/detail/game.png"; useBackgroundColor = true; } else if (item.Type == "Person") { url = "css/images/items/detail/person.png"; useBackgroundColor = true; maxwidth = 125; } else if (item.Type == "Genre" || item.Type == "Studio") { url = "css/images/items/detail/video.png"; useBackgroundColor = true; maxwidth = 125; } else { url = "css/images/items/detail/video.png"; useBackgroundColor = true; maxwidth = 150; } if (url) { var style = useBackgroundColor ? "background-color:" + defaultBackground + ";" : ""; if (maxwidth) { style += "max-width:" + maxwidth + "px;"; } html += ""; } return html; }, getMiscInfoHtml: function (item) { var miscInfo = []; var text; if (item.ProductionYear && item.Type == "Series") { if (item.Status == "Continuing") { miscInfo.push(item.ProductionYear + "-Present"); } else if (item.ProductionYear) { text = item.ProductionYear; if (item.EndDate) { try { text += "-" + parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear(); } catch (e) { console.log("Error parsing date: " + item.EndDate); } } miscInfo.push(text); } } if (item.Type != "Series" && item.Type != "Episode") { if (item.ProductionYear) { miscInfo.push(item.ProductionYear); } else if (item.PremiereDate) { try { text = "-" + parseISO8601Date(item.PremiereDate, { toLocal: true }).getFullYear(); miscInfo.push(text); } catch (e) { console.log("Error parsing date: " + item.PremiereDate); } } } if (item.OfficialRating) { miscInfo.push(item.OfficialRating); } if (item.RunTimeTicks) { if (item.Type == "Audio") { miscInfo.push(DashboardPage.getDisplayText(item.RunTimeTicks)); } else { var minutes = item.RunTimeTicks / 600000000; minutes = minutes || 1; miscInfo.push(parseInt(minutes) + "min"); } } if (item.MediaType && item.DisplayMediaType && item.DisplayMediaType != item.Type) { miscInfo.push(item.DisplayMediaType); } if (item.VideoFormat && item.VideoFormat !== 'Standard') { miscInfo.push(item.VideoFormat); } return miscInfo.join('     '); }, renderOverview: function (elem, item) { if (item.Overview || item.OverviewHtml) { var overview = item.OverviewHtml || item.Overview; elem.html(overview).show().trigger('create'); $('a', elem).each(function () { $(this).attr("target", "_blank"); }); } else { elem.hide(); } }, renderStudios: function (elem, item, context) { if (item.Studios && item.Studios.length) { var html = 'Studios:  '; for (var i = 0, length = item.Studios.length; i < length; i++) { if (i > 0) { html += '  /  '; } html += '' + item.Studios[i] + ''; } elem.show().html(html).trigger('create'); } else { elem.hide(); } }, renderGenres: function (elem, item, context) { if (item.Genres && item.Genres.length) { var html = 'Genres:  '; for (var i = 0, length = item.Genres.length; i < length; i++) { if (i > 0) { html += '  /  '; } html += '' + item.Genres[i] + ''; } elem.show().html(html).trigger('create'); } else { elem.hide(); } }, renderPremiereDate: function (elem, item) { if (item.PremiereDate) { try { var date = parseISO8601Date(item.PremiereDate, { toLocal: true }); var text = new Date().getTime() > date.getTime() ? "Premiered" : "Premieres"; elem.show().html(text + '  ' + date.toDateString()); } catch (err) { elem.hide(); } } else { elem.hide(); } }, renderBudget: function (elem, item) { if (item.Budget) { elem.show().html('Budget:  $' + item.Budget + ''); } else { elem.hide(); } }, renderRevenue: function (elem, item) { if (item.Revenue) { elem.show().html('Revenue:  $' + item.Revenue + ''); } else { elem.hide(); } }, shouldDisplayGallery: function (item) { var imageTags = item.ImageTags || {}; if (imageTags.Banner) { return true; } if (imageTags.Logo) { return true; } if (imageTags.Thumb) { return true; } if (imageTags.Art) { return true; } if (imageTags.Menu) { return true; } if (imageTags.Disc) { return true; } if (imageTags.Box) { return true; } if (imageTags.BoxRear) { return true; } if (item.BackdropImageTags && item.BackdropImageTags.length) { return true; } if (item.ScreenshotImageTags && item.ScreenshotImageTags.length) { return true; } return false; }, getGalleryHtml: function (item) { var html = ''; var i, length; var imageTags = item.ImageTags || {}; if (imageTags.Banner) { html += LibraryBrowser.createGalleryImage(item, "Banner", imageTags.Banner); } if (imageTags.Logo) { html += LibraryBrowser.createGalleryImage(item, "Logo", imageTags.Logo); } if (imageTags.Thumb) { html += LibraryBrowser.createGalleryImage(item, "Thumb", imageTags.Thumb); } if (imageTags.Art) { html += LibraryBrowser.createGalleryImage(item, "Art", imageTags.Art); } if (imageTags.Menu) { html += LibraryBrowser.createGalleryImage(item, "Menu", imageTags.Menu); } if (imageTags.Box) { html += LibraryBrowser.createGalleryImage(item, "Box", imageTags.Box); } if (imageTags.BoxRear) { html += LibraryBrowser.createGalleryImage(item, "Box", imageTags.BoxRear); } if (item.BackdropImageTags) { for (i = 0, length = item.BackdropImageTags.length; i < length; i++) { html += LibraryBrowser.createGalleryImage(item, "Backdrop", item.BackdropImageTags[i], i); } } if (item.ScreenshotImageTags) { for (i = 0, length = item.ScreenshotImageTags.length; i < length; i++) { html += LibraryBrowser.createGalleryImage(item, "Screenshot", item.ScreenshotImageTags[i], i); } } if (imageTags.Disc) { html += LibraryBrowser.createGalleryImage(item, "Disc", imageTags.Disc); } return html; }, createGalleryImage: function (item, type, tag, index) { var downloadWidth = 400; var lightboxWidth = 800; var html = ''; if (typeof (index) == "undefined") index = 0; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += 'Close'; html += ''; html += '
'; return html; }, createCastImage: function (cast, context) { var html = ''; var role = cast.Role || cast.Type; html += ''; html += '
'; if (cast.PrimaryImageTag) { var imgUrl = ApiClient.getPersonImageUrl(cast.Name, { width: 185, tag: cast.PrimaryImageTag, type: "primary" }); html += ''; } else { var style = "background-color:" + defaultBackground + ";"; html += ''; } html += '
' + cast.Name + '
'; html += '
' + role + '
'; html += '
'; return html; } }; })(window, document, jQuery);