';
$($.mobile.activePage).append(html);
$('.playFlyout').popup({ positionTo: positionTo || "window" }).trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
}).parents(".ui-popup-container");
},
getHref: function (item, context, topParentId) {
var href = LibraryBrowser.getHrefInternal(item, context);
if (context) {
href += href.indexOf('?') == -1 ? "?context=" : "&context=";
href += context;
}
if (topParentId == null && context != 'playlists') {
topParentId = LibraryMenu.getTopParentId();
}
if (topParentId) {
href += href.indexOf('?') == -1 ? "?topParentId=" : "&topParentId=";
href += topParentId;
}
return href;
},
getHrefInternal: function (item, context) {
if (!item) {
throw new Error('item cannot be null');
}
if (item.url) {
return item.url;
}
// Handle search hints
var id = item.Id || item.ItemId;
if (item.CollectionType == 'livetv') {
return 'livetvsuggested.html';
}
if (item.CollectionType == 'channels') {
return 'channelslatest.html';
}
if (context != 'folders') {
if (item.CollectionType == 'movies') {
return 'movieslatest.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'boxsets') {
return 'collections.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'trailers') {
return 'movietrailers.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'movies') {
return 'movieslatest.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'tvshows') {
return 'tvrecommended.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'music') {
return 'musicrecommended.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'games') {
return 'gamesrecommended.html?topParentId=' + item.Id;
}
if (item.CollectionType == 'playlists') {
return 'playlists.html?topParentId=' + item.Id;
}
}
if (item.Type == 'CollectionFolder') {
return 'itemlist.html?topParentId=' + item.Id + '&parentid=' + item.Id;
}
if (item.Type == "Playlist") {
return "playlistedit.html?id=" + id;
}
if (item.Type == "TvChannel") {
return "livetvchannel.html?id=" + id;
}
if (item.Type == "Channel") {
return "channelitems.html?id=" + id;
}
if (item.Type == "ChannelFolderItem") {
return "channelitems.html?id=" + item.ChannelId + '&folderId=' + item.Id;
}
if (item.Type == "Program") {
return "livetvprogram.html?id=" + id;
}
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 == "GameSystem") {
return "itemdetails.html?id=" + id;
}
if (item.Type == "Genre") {
return "itembynamedetails.html?id=" + id;
}
if (item.Type == "MusicGenre") {
return "itembynamedetails.html?id=" + id;
}
if (item.Type == "GameGenre") {
return "itembynamedetails.html?id=" + id;
}
if (item.Type == "Studio") {
return "itembynamedetails.html?id=" + id;
}
if (item.Type == "Person") {
return "itembynamedetails.html?id=" + id;
}
if (item.Type == "Recording") {
return "livetvrecording.html?id=" + id;
}
if (item.Type == "MusicArtist") {
return "itembynamedetails.html?id=" + id;
}
if (item.IsFolder) {
return id ? "itemlist.html?parentId=" + id : "#";
}
return "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 if (type == 'Screenshot') {
options.tag = item.ScreenshotImageTags[index];
} else if (type == 'Primary') {
options.tag = item.PrimaryImageTag || item.ImageTags[type];
} else {
options.tag = item.ImageTags[type];
}
// For search hints
return ApiClient.getScaledImageUrl(item.Id || item.ItemId, options);
},
getListViewIndex: function (item, options) {
if (options.index == 'disc') {
return item.ParentIndexNumber == null ? '' : 'Disc ' + item.ParentIndexNumber;
}
var sortBy = (options.sortBy || '').toLowerCase();
var code, name;
if (sortBy.indexOf('sortname') == 0) {
if (item.Type == 'Episode') return '';
// SortName
name = (item.SortName || item.Name)[0].toUpperCase();
code = name.charCodeAt(0);
if (code < 65 || code > 90) {
return '#';
}
return name.toUpperCase();
}
if (sortBy.indexOf('officialrating') == 0) {
return item.OfficialRating || 'Unrated';
}
if (sortBy.indexOf('communityrating') == 0) {
if (item.CommunityRating == null) {
return 'Unrated';
}
return Math.floor(item.CommunityRating);
}
if (sortBy.indexOf('criticrating') == 0) {
if (item.CriticRating == null) {
return 'Unrated';
}
return Math.floor(item.CriticRating);
}
if (sortBy.indexOf('metascore') == 0) {
if (item.Metascore == null) {
return 'Unrated';
}
return Math.floor(item.Metascore);
}
if (sortBy.indexOf('albumartist') == 0) {
// SortName
if (!item.AlbumArtist) return '';
name = item.AlbumArtist[0].toUpperCase();
code = name.charCodeAt(0);
if (code < 65 || code > 90) {
return '#';
}
return name.toUpperCase();
}
return '';
},
getUserDataCssClass: function (key) {
return 'libraryItemUserData' + key.replace(new RegExp(' ', 'g'), '');
},
getListViewHtml: function (options) {
var outerHtml = "";
outerHtml += '
';
if (options.title) {
outerHtml += '
';
outerHtml += options.title;
outerHtml += '
';
}
var index = 0;
var groupTitle = '';
outerHtml += options.items.map(function (item) {
var html = '';
if (options.showIndex !== false) {
var itemGroupTitle = LibraryBrowser.getListViewIndex(item, options);
if (itemGroupTitle != groupTitle) {
html += '
';
html += itemGroupTitle;
html += '
';
groupTitle = itemGroupTitle;
}
}
var dataAttributes = LibraryBrowser.getItemDataAttributes(item, options);
var cssClass = options.smallIcon ? 'ui-li-has-icon listItem' : 'ui-li-has-thumb listItem';
if (item.UserData) {
cssClass += ' ' + LibraryBrowser.getUserDataCssClass(item.UserData.Key);
}
var href = LibraryBrowser.getHref(item, options.context);
html += '
';
return outerHtml;
},
getItemDataAttributes: function (item, options) {
var atts = [];
var itemCommands = LibraryBrowser.getItemCommands(item, options);
atts.push('data-itemid="' + item.Id + '"');
atts.push('data-commands="' + itemCommands.join(',') + '"');
atts.push('data-context="' + (options.context || '') + '"');
atts.push('data-itemtype="' + item.Type + '"');
atts.push('data-mediatype="' + (item.MediaType || '') + '"');
atts.push('data-positionticks="' + (item.UserData.PlaybackPositionTicks || 0) + '"');
atts.push('data-playaccess="' + (item.PlayAccess || '') + '"');
atts.push('data-locationtype="' + (item.LocationType || '') + '"');
if (item.IsPlaceHolder) {
atts.push('data-placeholder="true"');
}
var html = atts.join(' ');
if (html) {
html = ' ' + html;
}
return html;
},
getItemCommands: function (item, options) {
var itemCommands = [];
//if (MediaController.canPlay(item)) {
// itemCommands.push('playmenu');
//}
if (item.Type != "Recording" && item.Type != "Program") {
itemCommands.push('edit');
}
if (item.LocalTrailerCount) {
itemCommands.push('trailer');
}
if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist" || item.Type == "MusicGenre") {
itemCommands.push('instantmix');
}
if (item.IsFolder || item.Type == "MusicArtist" || item.Type == "MusicGenre") {
itemCommands.push('shuffle');
}
if (PlaylistManager.supportsPlaylists(item)) {
if (options.showRemoveFromPlaylist) {
itemCommands.push('removefromplaylist');
} else {
itemCommands.push('playlist');
}
}
if (options.playFromHere) {
itemCommands.push('playfromhere');
itemCommands.push('queuefromhere');
}
return itemCommands;
},
getPosterViewHtml: function (options) {
var items = options.items;
var currentIndexValue;
options.shape = options.shape || "portrait";
var html = "";
var primaryImageAspectRatio;
if (options.shape == 'auto' || options.shape == 'autohome') {
primaryImageAspectRatio = LibraryBrowser.getAveragePrimaryImageAspectRatio(items);
if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1.777777778) < .3) {
options.shape = options.shape == 'auto' ? 'backdrop' : 'homePageBackdrop';
} else if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1) < .33) {
options.coverImage = true;
options.shape = options.shape == 'auto' ? 'square' : 'homePageSquare';
} else if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1.3333334) < .01) {
options.coverImage = true;
options.shape = options.shape == 'auto' ? 'square' : 'homePageSquare';
} else if (primaryImageAspectRatio && primaryImageAspectRatio > 1.9) {
options.shape = 'banner';
options.coverImage = true;
} else if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 0.6666667) < .2) {
options.shape = options.shape == 'auto' ? 'portrait' : 'homePagePortrait';
} else {
options.shape = options.defaultShape || (options.shape == 'auto' ? 'portrait' : 'homePagePortrait');
}
}
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
primaryImageAspectRatio = LibraryBrowser.getAveragePrimaryImageAspectRatio([item]);
var futureDateText;
if (item.PremiereDate) {
try {
futureDateText = LibraryBrowser.getFutureDateText(parseISO8601Date(item.PremiereDate, { toLocal: true }), true);
} catch (err) {
}
}
if (options.showPremiereDateIndex && futureDateText) {
var val = futureDateText || "Unknown Date";
if (val != currentIndexValue) {
html += '
' + val + '
';
currentIndexValue = val;
}
} else if (options.timeline) {
var year = item.ProductionYear || "Unknown Year";
if (year != currentIndexValue) {
html += '
';
html += "";
}
return html;
},
getCardFooterText: function (item, options, imgUrl, forceName, footerClass, progressHtml) {
var html = '';
html += '";
return html;
},
getCardTextLines: function (lines, cssClass, forceLines) {
var html = '';
var valid = 0;
var i, length;
for (i = 0, length = lines.length; i < length; i++) {
var text = lines[i];
if (text) {
html += "
";
html += text;
html += "
";
valid++;
}
}
if (forceLines) {
while (valid < length) {
html += "
";
valid++;
}
}
return html;
},
isYesterday: function (date1) {
var today = new Date();
today.setDate(today.getDate() - 1);
return date1.getFullYear() == today.getFullYear() && date1.getDate() == today.getDate();
},
isSameDay: function (date1, date2) {
return date1.getFullYear() == date2.getFullYear() && date1.getDate() == date2.getDate();
},
getFutureDateText: function (date, includeDayNamesInFuture) {
var weekday = [];
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var currentDate = new Date();
if (LibraryBrowser.isSameDay(date, currentDate)) {
return "Today";
}
if (LibraryBrowser.isYesterday(date)) {
return "Yesterday";
}
var day = weekday[date.getDay()];
date = date.toLocaleDateString();
if (date.toLowerCase().indexOf(day.toLowerCase()) == -1) {
return day + " " + date;
}
return date;
},
getPremiereDateText: function (item, date) {
if (!date) {
var text = '';
if (item.AirTime) {
text += item.AirTime;
}
if (item.SeriesStudio) {
if (text) {
text += " on " + item.SeriesStudio;
} else {
text += item.SeriesStudio;
}
}
return text;
}
var day = LibraryBrowser.getFutureDateText(date);
if (item.AirTime) {
day += " at " + item.AirTime;
}
if (item.SeriesStudio) {
day += " on " + item.SeriesStudio;
}
return day;
},
getPosterViewDisplayName: function (item, displayAsSpecial, includeParentInfo) {
var name = item.EpisodeTitle || item.Name;
if (item.Type == "TvChannel") {
if (item.Number) {
return item.Number + ' ' + name;
}
return name;
}
if (displayAsSpecial && item.Type == "Episode" && item.ParentIndexNumber == 0) {
name = "Special - " + name;
} else if (item.Type == "Episode" && item.IndexNumber != null && item.ParentIndexNumber != null) {
var displayIndexNumber = item.IndexNumber;
var number = "E" + displayIndexNumber;
if (includeParentInfo !== false) {
number = "S" + item.ParentIndexNumber + ", " + number;
}
if (item.IndexNumberEnd) {
displayIndexNumber = item.IndexNumberEnd;
number += "-" + displayIndexNumber;
}
name = number + " - " + name;
}
return name;
},
getOfflineIndicatorHtml: function (item) {
if (item.LocationType == "Offline") {
return '
Offline
';
}
try {
var date = parseISO8601Date(item.PremiereDate, { toLocal: true });
if (item.PremiereDate && (new Date().getTime() < date.getTime())) {
return '
';
}
if (item.Type != 'TvChannel') {
if (item.UserData.PlayedPercentage >= 100 || (item.UserData && item.UserData.Played)) {
return '
';
}
}
}
return '';
},
getGroupCountIndicator: function (item) {
if (item.ChildCount) {
return '
' + item.ChildCount + '
';
}
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);
var result;
if (values.length % 2)
result = values[half];
else
result = (values[half - 1] + values[half]) / 2.0;
// If really close to 2:3 (poster image), just return 2:3
if (Math.abs(0.66666666667 - result) <= .15) {
return 0.66666666667;
}
// If really close to 16:9 (episode image), just return 16:9
if (Math.abs(1.777777778 - result) <= .15) {
return 1.777777778;
}
// If really close to 1 (square image), just return 1
if (Math.abs(1 - result) <= .15) {
return 1;
}
// If really close to 4:3 (poster image), just return 2:3
if (Math.abs(1.33333333333 - result) <= .15) {
return 1.33333333333;
}
return result;
},
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 character = String(str.substr(0, 1).charCodeAt());
var sum = 0;
for (var i = 0; i < character.length; i++) {
sum += parseInt(character.charAt(i));
}
var index = String(sum).substr(-1);
return LibraryBrowser.metroColors[index];
} else {
return LibraryBrowser.getRandomMetroColor();
}
},
renderName: function (item, nameElem, linkToElement, context) {
var name = LibraryBrowser.getPosterViewDisplayName(item, false, false);
Dashboard.setPageTitle(name);
if (linkToElement) {
nameElem.html('' + name + '').trigger('create');
} else {
nameElem.html(name);
}
},
renderParentName: function (item, parentNameElem) {
var html = [];
if (item.AlbumArtist && item.Type == "Audio") {
html.push('' + item.AlbumArtist + '');
} else if (item.AlbumArtist && item.Type == "MusicAlbum") {
html.push('' + item.AlbumArtist + '');
} else if (item.Artists && item.Artists.length && item.Type == "MusicVideo") {
html.push('' + item.Artists[0] + '');
} else if (item.SeriesName && item.Type == "Episode") {
html.push('' + item.SeriesName + '');
}
if (item.SeriesName && item.Type == "Season") {
html.push('' + item.SeriesName + '');
} else if (item.ParentIndexNumber != null && item.Type == "Episode") {
html.push('Season ' + item.ParentIndexNumber + '');
} else if (item.Album && item.Type == "Audio" && (item.AlbumId || item.ParentId)) {
html.push('' + item.Album + '');
} else if (item.Album && item.Type == "MusicVideo" && item.AlbumId) {
html.push('' + item.Album + '');
} else if (item.AlbumArtist && item.Type == "MusicAlbum") {
} else if (item.Album) {
html.push(item.Album);
}
if (html.length) {
parentNameElem.show().html(html.join(' - ')).trigger('create');
} else {
parentNameElem.hide();
}
},
renderLinks: function (linksElem, item) {
var links = [];
if (item.HomePageUrl) {
links.push('Website');
}
if (item.ExternalUrls) {
for (var i = 0, length = item.ExternalUrls.length; i < length; i++) {
var url = item.ExternalUrls[i];
links.push('' + url.Name + '');
}
}
if (links.length) {
var html = 'Links: ' + links.join(' / ');
$(linksElem).html(html).trigger('create');
} else {
$(linksElem).hide();
}
},
getDefaultPageSizeSelections: function () {
return [20, 50, 100, 200, 300, 400, 500];
},
getQueryPagingHtml: function (options) {
var startIndex = options.startIndex;
var limit = options.limit;
var totalRecordCount = options.totalRecordCount;
if (limit && options.updatePageSizeSetting !== false) {
try {
store.setItem(options.pageSizeKey || pageSizeKey, limit);
} catch (e) {
}
}
var html = '';
var recordsEnd = Math.min(startIndex + limit, totalRecordCount);
// 20 is the minimum page size
var showControls = totalRecordCount > 20 || limit < totalRecordCount;
html += '
';
html += '';
var startAtDisplay = totalRecordCount ? startIndex + 1 : 0;
html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount;
html += '';
if (showControls || options.viewButton || options.addSelectionButton || options.additionalButtonsHtml) {
html += '
';
if (showControls) {
html += '';
html += '';
}
html += (options.additionalButtonsHtml || '');
if (options.addSelectionButton) {
html += '';
}
if (options.viewButton) {
html += '';
}
html += '
';
if (showControls && options.showLimit !== false) {
var id = "selectPageSize";
var pageSizes = options.pageSizes || LibraryBrowser.getDefaultPageSizeSelections();
var optionsHtml = pageSizes.map(function (val) {
if (limit == val) {
return '';
} else {
return '';
}
}).join('');
// Add styles to defeat jquery mobile
html += '';
}
}
html += '
';
return html;
},
getPagingHtml: function (query, totalRecordCount, updatePageSizeSetting, pageSizes, showLimit) {
if (query.Limit && updatePageSizeSetting !== false) {
try {
store.setItem(pageSizeKey, query.Limit);
} catch (e) {
}
}
var html = '';
var recordsEnd = Math.min(query.StartIndex + query.Limit, totalRecordCount);
// 20 is the minimum page size
var showControls = totalRecordCount > 20 || query.Limit < totalRecordCount;
html += '
';
html += '';
var startAtDisplay = totalRecordCount ? query.StartIndex + 1 : 0;
html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount;
html += '';
if (showControls) {
html += '
';
html += '';
html += '';
html += '
';
if (showLimit !== false) {
var id = "selectPageSize" + new Date().getTime();
var options = '';
function getOption(val) {
if (query.Limit == val) {
return '';
} else {
return '';
}
}
pageSizes = pageSizes || [20, 50, 100, 200, 300, 400, 500];
for (var j = 0, length = pageSizes.length; j < length; j++) {
options += getOption(pageSizes[j]);
}
// Add styles to defeat jquery mobile
html += '';
}
}
html += '
';
return html;
},
getRatingHtml: function (item, metascore) {
var html = "";
if (item.CommunityRating) {
html += "";
html += '
';
html += item.CommunityRating.toFixed(1);
html += '
';
}
if (item.CriticRating != null) {
if (item.CriticRating >= 60) {
html += '';
} else {
html += '';
}
html += '
' + item.CriticRating + '%
';
}
if (item.Metascore && metascore !== false) {
if (item.Metascore >= 60) {
html += '
' + item.Metascore + '
';
}
else if (item.Metascore >= 40) {
html += '
' + item.Metascore + '
';
} else {
html += '
' + item.Metascore + '
';
}
}
return html;
},
getItemProgressBarHtml: function (item) {
if (item.Type == "Recording" && item.CompletionPercentage) {
return '';
}
var pct = item.PlayedPercentage;
if (pct && pct < 100) {
return '';
}
return null;
},
getUserDataIconsHtml: function (item) {
var html = '';
var userData = item.UserData || {};
var itemId = item.Id;
var type = item.Type;
if ((item.MediaType || item.IsFolder) && item.Type != "TvChannel" && item.Type != "MusicArtist") {
if (userData.Played) {
html += '';
} else {
html += '';
}
}
if (typeof userData.Likes == "undefined") {
html += '';
html += '';
}
else if (userData.Likes) {
html += '';
html += '';
}
else {
html += '';
html += '';
}
if (userData.IsFavorite) {
html += '';
} else {
html += '';
}
return html;
},
markPlayed: function (link) {
var id = link.getAttribute('data-itemid');
var $link = $(link);
var markAsPlayed = $link.hasClass('imgPlayedOff');
if (markAsPlayed) {
ApiClient.markPlayed(Dashboard.getCurrentUserId(), id);
} else {
ApiClient.markUnplayed(Dashboard.getCurrentUserId(), id);
}
if (markAsPlayed) {
link.src = "css/images/userdata/checkedon.png";
$link.addClass('imgPlayed').removeClass('imgPlayedOff');
} else {
link.src = "css/images/userdata/checkedoff.png";
$link.addClass('imgPlayedOff').removeClass('imgPlayed');
}
},
markFavorite: function (link) {
var id = link.getAttribute('data-itemid');
var $link = $(link);
var markAsFavorite = $link.hasClass('imgFavoriteOff');
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 $link = $(link);
if ($link.hasClass('imgLikeOff')) {
ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, true);
link.src = "css/images/userdata/thumbs_up_on.png";
$link.addClass('imgLike').removeClass('imgLikeOff');
} else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), 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 $link = $(link);
if ($link.hasClass('imgDislikeOff')) {
ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, false);
link.src = "css/images/userdata/thumbs_down_on.png";
$link.addClass('imgDislike').removeClass('imgDislikeOff');
} else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), 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";
});
},
getDetailImageHtml: function (item, href, preferThumb) {
var imageTags = item.ImageTags || {};
if (item.PrimaryImageTag) {
imageTags.Primary = item.PrimaryImageTag;
}
var html = '';
var url;
var imageHeight = 280;
if (preferThumb && imageTags.Thumb) {
url = ApiClient.getScaledImageUrl(item.Id, {
type: "Thumb",
maxHeight: imageHeight,
tag: item.ImageTags.Thumb
});
}
else if (imageTags.Primary) {
url = ApiClient.getScaledImageUrl(item.Id, {
type: "Primary",
maxHeight: imageHeight,
tag: item.ImageTags.Primary
});
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
url = ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
maxHeight: imageHeight,
tag: item.BackdropImageTags[0]
});
}
else if (imageTags.Thumb) {
url = ApiClient.getScaledImageUrl(item.Id, {
type: "Thumb",
maxHeight: imageHeight,
tag: item.ImageTags.Thumb
});
}
else if (imageTags.Disc) {
url = ApiClient.getScaledImageUrl(item.Id, {
type: "Disc",
maxHeight: imageHeight,
tag: item.ImageTags.Disc
});
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
url = ApiClient.getScaledImageUrl(item.AlbumId, {
type: "Primary",
maxHeight: imageHeight,
tag: item.AlbumPrimaryImageTag
});
}
else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicGenre") {
url = "css/images/items/detail/audio.png";
}
else if (item.MediaType == "Game" || item.Type == "GameGenre") {
url = "css/images/items/detail/game.png";
}
else if (item.Type == "Person") {
url = "css/images/items/detail/person.png";
}
else if (item.Type == "Genre" || item.Type == "Studio") {
url = "css/images/items/detail/video.png";
}
else if (item.Type == "TvChannel") {
url = "css/images/items/detail/tv.png";
}
else {
url = "css/images/items/detail/video.png";
}
if (!href) {
href = "itemgallery.html?id=" + item.Id;
}
var linkToGallery = LibraryBrowser.shouldDisplayGallery(item);
html += '
';
if (linkToGallery) {
html += "";
}
html += "";
if (linkToGallery) {
html += "";
}
var progressHtml = item.IsFolder ? '' : LibraryBrowser.getItemProgressBarHtml((item.Type == 'Recording' ? item : item.UserData));
if (progressHtml) {
html += '
';
html += progressHtml;
html += "
";
}
html += "
";
return html;
},
getMiscInfoHtml: function (item) {
var miscInfo = [];
var text, date;
if (item.Type == "Episode" || item.MediaType == 'Photo') {
if (item.PremiereDate) {
try {
date = parseISO8601Date(item.PremiereDate, { toLocal: true });
text = date.toLocaleDateString();
miscInfo.push(text);
}
catch (e) {
console.log("Error parsing date: " + item.PremiereDate);
}
}
}
if (item.StartDate) {
try {
date = parseISO8601Date(item.StartDate, { toLocal: true });
text = date.toLocaleDateString();
miscInfo.push(text);
if (item.Type != "Recording") {
text = LiveTvHelpers.getDisplayTime(date);
miscInfo.push(text);
}
}
catch (e) {
console.log("Error parsing date: " + item.PremiereDate);
}
}
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 {
var endYear = parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear();
if (endYear != item.ProductionYear) {
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" && item.MediaType != 'Photo') {
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);
}
}
}
var minutes;
if (item.RunTimeTicks && item.Type != "Series") {
if (item.Type == "Audio") {
miscInfo.push(Dashboard.getDisplayTime(item.RunTimeTicks));
} else {
minutes = item.RunTimeTicks / 600000000;
minutes = minutes || 1;
miscInfo.push(Math.round(minutes) + "min");
}
}
if (item.OfficialRating && item.Type !== "Season" && item.Type !== "Episode") {
miscInfo.push(item.OfficialRating);
}
if (item.Video3DFormat) {
miscInfo.push("3D");
}
if (item.MediaType == 'Photo' && item.Width && item.Height) {
miscInfo.push(item.Width + "x" + item.Height);
}
return miscInfo.join(' ');
},
renderOverview: function (elem, item) {
var overview = item.Overview || '';
elem.html(overview).trigger('create');
$('a', elem).each(function () {
$(this).attr("target", "_blank");
});
if (overview) {
elem.removeClass('empty');
} else {
elem.addClass('empty');
}
},
renderStudios: function (elem, item, context) {
if (item.Studios && item.Studios.length && item.Type != "Series") {
var prefix = item.Studios.length > 1 ? "Studios" : "Studio";
var html = prefix + ': ';
for (var i = 0, length = item.Studios.length; i < length; i++) {
if (i > 0) {
html += ' / ';
}
html += '' + item.Studios[i].Name + '';
}
elem.show().html(html).trigger('create');
} else {
elem.hide();
}
},
renderGenres: function (elem, item, context) {
var html = '';
var genres = item.Genres || [];
for (var i = 0, length = genres.length; i < length; i++) {
if (i > 0) {
html += ' / ';
}
var param = item.Type == "Audio" || item.Type == "MusicArtist" || item.Type == "MusicAlbum" ? "musicgenre" : "genre";
if (item.MediaType == "Game") {
param = "gamegenre";
}
html += '' + genres[i] + '';
}
elem.html(html).trigger('create');
},
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.toLocaleDateString());
} 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();
}
},
renderAwardSummary: function (elem, item) {
if (item.AwardSummary) {
elem.show().html('Awards: ' + item.AwardSummary);
} else {
elem.hide();
}
},
renderDetailPageBackdrop: function (page, item) {
var screenWidth = Math.max(screen.height, screen.width);
var imgUrl;
if (item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: screenWidth,
tag: item.BackdropImageTags[0]
});
$('#itemBackdrop', page).removeClass('noBackdrop').css('background-image', 'url("' + imgUrl + '")');
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
imgUrl = ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
tag: item.ParentBackdropImageTags[0],
maxWidth: screenWidth
});
$('#itemBackdrop', page).removeClass('noBackdrop').css('background-image', 'url("' + imgUrl + '")');
}
else {
$('#itemBackdrop', page).addClass('noBackdrop').css('background-image', 'none');
}
},
shouldDisplayGallery: function (item) {
var imageTags = item.ImageTags || {};
if (imageTags.Primary) {
return true;
}
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.Primary) {
html += LibraryBrowser.createGalleryImage(item, "Primary", imageTags.Primary);
}
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, "BoxRear", 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 screenWidth = Math.max(screen.height, screen.width);
var html = '';
if (typeof (index) == "undefined") index = 0;
html += '