';
}
}
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 += '
';
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;
}
$.fn.createPosterItemHoverMenu = function () {
function onShowTimerExpired(elem) {
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;
}
return this.on('mouseenter', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverIn).on('mouseleave', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverOut);
};
})(jQuery, document, window);