';
}
}
if (options.showArtist) {
if (item.Artists && item.Artists.length) {
var artistLinksHtml = LibraryBrowser.getArtistLinksHtml(item.Artists);
html += '
' + artistLinksHtml + '
';
}
else {
html += '
';
}
}
if (options.showArtist) {
if (item.AlbumArtist) {
html += '
';
return html;
},
getArtistLinksHtml: function (artists) {
var html = [];
for (var i = 0, length = artists.length; i < length; i++) {
var artist = artists[i];
html.push('' + artist + '');
}
html = html.join(' / ');
return html;
},
showPlayMenu: function (positionTo, itemId, itemType, mediaType, resumePositionTicks) {
var isPlaying = MediaPlayer.isPlaying();
if (!isPlaying && !resumePositionTicks && mediaType != "Audio") {
MediaPlayer.playById(itemId);
return;
}
$('.playFlyout').popup("close").remove();
var 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 == "Channel") {
return "livetvchannel.html?id=" + 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?genre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
if (item.Type == "MusicGenre") {
return "itembynamedetails.html?musicgenre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
if (item.Type == "GameGenre") {
return "itembynamedetails.html?gamegenre=" + 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 == "Recording") {
return "livetvrecording.html?id=" + id;
}
if (item.Type == "MusicArtist") {
return "itembynamedetails.html?musicartist=" + 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 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.getImageUrl(item.Id || item.ItemId, options);
},
getPosterViewHtml: function (options) {
var items = options.items;
var currentIndexValue;
options.shape = options.shape || "portrait";
var html = "";
var primaryImageAspectRatio = options.shape == 'auto' ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null;
if (options.shape == 'auto') {
if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1.777777778) < .3) {
options.shape = 'backdrop';
}
else if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1) < .3) {
options.shape = 'square';
}
else {
options.shape = 'portrait';
}
}
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio([item]) : null;
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 += '
' + year + '
';
currentIndexValue = year;
}
}
var imgUrl = null;
var background = null;
var width = null;
var height = null;
var forceName = false;
if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
maxwidth: 576,
tag: item.BackdropImageTags[0]
});
}
else if (options.preferThumb && item.ImageTags && item.ImageTags.Thumb) {
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Thumb",
maxwidth: 576,
tag: item.ImageTags.Thumb
});
}
else if (options.preferThumb && item.SeriesThumbImageTag) {
imgUrl = ApiClient.getImageUrl(item.SeriesId, {
type: "Thumb",
maxwidth: 576,
tag: item.SeriesThumbImageTag
});
}
else if (options.preferThumb && item.ParentThumbItemId) {
imgUrl = ApiClient.getThumbImageUrl(item.ParentThumbItemId, {
type: "Thumb",
maxwidth: 576
});
}
else if (options.preferThumb && item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
maxwidth: 576,
tag: item.BackdropImageTags[0]
});
forceName = true;
}
else if (item.ImageTags && item.ImageTags.Primary) {
height = 400;
width = primaryImageAspectRatio ? Math.round(height * primaryImageAspectRatio) : null;
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Primary",
height: height,
width: width,
tag: item.ImageTags.Primary
});
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
height = 400;
width = primaryImageAspectRatio ? Math.round(height * primaryImageAspectRatio) : null;
imgUrl = ApiClient.getImageUrl(item.AlbumId, {
type: "Primary",
height: height,
width: width,
tag: item.AlbumPrimaryImageTag
});
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
maxwidth: 576,
tag: item.BackdropImageTags[0]
});
}
else if (item.ImageTags && item.ImageTags.Thumb) {
imgUrl = ApiClient.getImageUrl(item.Id, {
type: "Thumb",
maxwidth: 576,
tag: item.ImageTags.Thumb
});
}
else if (item.SeriesThumbImageTag) {
imgUrl = ApiClient.getImageUrl(item.SeriesId, {
type: "Thumb",
maxwidth: 576,
tag: item.SeriesThumbImageTag
});
}
else if (item.ParentThumbItemId) {
imgUrl = ApiClient.getThumbImageUrl(item, {
type: "Thumb",
maxwidth: 576
});
}
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 if (item.Type == "Recording" || item.Type == "Program" || item.Type == "Channel") {
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/collection.png';
}
background = defaultBackground;
}
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 if (item.Type == "Person") {
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/person.png';
}
background = defaultBackground;
}
else {
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/collection.png';
}
background = defaultBackground;
}
var cssClass = "posterItem";
if (options.transparent !== false) {
cssClass += " transparentPosterItem";
}
if (options.borderless) {
cssClass += " borderlessPosterItem";
}
cssClass += ' ' + options.shape + 'PosterItem';
html += '';
// Ribbon
if (item.MediaType == "Video" && item.Video3DFormat) {
// This would be much better if specified in the json payload
// Another nice thing to have in the payload would be 720 vs 1080
// Then, rather than "HD" it could display the specific HD format
// "HD" doesn't do much good if you have the 720p and 1080p version
var format = "SD";
var ribbonColor = "ribbon-red";
if (item.IsHD) {
format = "HD";
ribbonColor = "ribbon-blue";
}
if (item.Video3DFormat) {
format = "3D";
ribbonColor = "ribbon-3d";
}
html += '
';
return html;
}
};
})(window, document, jQuery, screen, localStorage);
(function ($, document, window) {
var showOverlayTimeout;
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
$('.posterItemOverlayTarget:visible', this).each(function () {
var elem = this;
$(this).animate({ "height": "0" }, "fast", function () {
$(elem).hide();
});
});
$('.posterItemOverlayTarget:visible', this).stop().animate({ "height": "0" }, function () {
$(this).hide();
});
}
function getOverlayHtml(item, currentUser, posterItem) {
var html = '';
html += '
';
var isSmallItem = $(posterItem).hasClass('smallBackdropPosterItem');
var isPortrait = $(posterItem).hasClass('portraitPosterItem');
var isSquare = $(posterItem).hasClass('squarePosterItem');
var parentName = isSmallItem || isPortrait ? null : item.SeriesName;
var name = LibraryBrowser.getPosterViewDisplayName(item, true);
html += '
';
var logoHeight = isSmallItem ? 20 : 26;
var maxLogoWidth = isPortrait ? 100 : 200;
var imgUrl;
if (parentName && item.ParentLogoItemId) {
imgUrl = ApiClient.getImageUrl(item.ParentLogoItemId, {
height: logoHeight * 2,
type: 'logo',
tag: item.ParentLogoImageTag
});
html += '';
}
else if (item.ImageTags.Logo) {
imgUrl = LibraryBrowser.getImageUrl(item, 'Logo', 0, {
height: logoHeight * 2,
});
html += '';
}
else {
html += parentName || name;
}
html += '
';
if (parentName) {
html += '
';
html += name;
html += '
';
} else if (!isSmallItem) {
html += '
';
html += LibraryBrowser.getMiscInfoHtml(item);
html += '
';
}
html += '
';
html += '';
html += LibraryBrowser.getRatingHtml(item, false);
html += '';
if (isPortrait) {
html += '';
html += LibraryBrowser.getUserDataIconsHtml(item);
html += '';
} else {
html += '';
html += LibraryBrowser.getUserDataIconsHtml(item);
html += '';
}
html += '
';
html += '
';
var buttonMargin = isPortrait || isSquare ? "margin:0 4px 0 0;" : "margin:0 10px 0 0;";
var buttonCount = 0;
if (MediaPlayer.canPlay(item, currentUser)) {
var resumePosition = (item.UserData || {}).PlaybackPositionTicks || 0;
var onPlayClick = 'LibraryBrowser.showPlayMenu(this, \'' + item.Id + '\', \'' + item.Type + '\', \'' + item.MediaType + '\', ' + resumePosition + ');return false;';
html += '';
buttonCount++;
if (item.MediaType == "Audio" || item.Type == "MusicAlbum") {
html += '';
buttonCount++;
}
}
if (item.LocalTrailerCount && item.PlayAccess == 'Full') {
html += '';
buttonCount++;
}
if (currentUser.Configuration.IsAdministrator && item.Type != "Recording" && item.Type != "Program") {
html += '';
buttonCount++;
}
if (!isPortrait || buttonCount < 3) {
html += '';
}
html += '
';
html += '
';
return html;
}
function onTrailerButtonClick() {
var id = this.getAttribute('data-itemid');
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), id).done(function (trailers) {
MediaPlayer.play(trailers);
});
return false;
}
function onRemoteControlButtonClick() {
var id = this.getAttribute('data-itemid');
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
RemoteControl.showMenuForItem({
item: item
});
});
return false;
}
function onMenuCommand(command, elem) {
var id = elem.getAttribute('data-itemid');
}
function getMenuOptions(elem) {
var items = [];
var id = elem.getAttribute('data-itemid');
var mediatype = elem.getAttribute('data-mediatype');
items.push({ type: 'header', text: 'Edit' });
items.push({ type: 'link', text: 'Details', url: 'edititemmetadata.html?id=' + id });
items.push({ type: 'link', text: 'Images', url: 'edititemimages.html?id=' + id });
if (mediatype == 'Video' && elem.getAttribute('data-locationtype') == 'FileSystem') {
items.push({ type: 'divider' });
items.push({ type: 'header', text: 'Manage' });
items.push({ type: 'command', text: 'Alternate Editions', name: 'AlternateEditions' });
}
return items;
}
$.fn.createPosterItemHoverMenu = function () {
function onShowTimerExpired(elem) {
if ($(elem).hasClass('hasContextMenu')) {
return;
}
var innerElem = $('.posterItemOverlayTarget', elem);
var id = elem.getAttribute('data-itemid');
var promise1 = ApiClient.getItem(Dashboard.getCurrentUserId(), id);
var promise2 = Dashboard.getCurrentUser();
$.when(promise1, promise2).done(function (response1, response2) {
var item = response1[0];
var user = response2[0];
innerElem.html(getOverlayHtml(item, user, elem)).trigger('create');
$('.btnPlayTrailer', innerElem).on('click', onTrailerButtonClick);
$('.btnRemoteControl', innerElem).on('click', onRemoteControlButtonClick);
});
innerElem.show().each(function () {
this.style.height = 0;
}).animate({ "height": "100%" }, "fast");
}
function onHoverIn() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
var elem = this;
showOverlayTimeout = setTimeout(function () {
onShowTimerExpired(elem);
}, 1000);
}
// https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)) {
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
return this;
}
var sequence = this;
Dashboard.getCurrentUser().done(function (user) {
if (user.Configuration.IsAdministrator) {
sequence.createContextMenu({
getOptions: getMenuOptions,
command: onMenuCommand,
selector: '.posterItem'
});
}
});
return this.on('mouseenter', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverIn)
.on('mouseleave', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverOut);
};
})(jQuery, document, window);