(function ($, document, window) {
var showOverlayTimeout;
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
var elem = this.querySelector('.cardOverlayTarget');
if ($(elem).is(':visible')) {
require(["jquery", "velocity"], function ($, Velocity) {
Velocity.animate(elem, { "height": "0" },
{
complete: function () {
$(elem).hide();
}
});
});
}
}
function getOverlayHtml(item, currentUser, card, commands) {
var html = '';
html += '
';
var className = card.className.toLowerCase();
var isMiniItem = className.indexOf('mini') != -1;
var isSmallItem = isMiniItem || className.indexOf('small') != -1;
var isPortrait = className.indexOf('portrait') != -1;
var isSquare = className.indexOf('square') != -1;
var parentName = isSmallItem || isMiniItem || isPortrait ? null : item.SeriesName;
var name = LibraryBrowser.getPosterViewDisplayName(item, true);
html += '
';
var logoHeight = isSmallItem || isMiniItem ? 20 : 26;
var maxLogoWidth = isPortrait ? 100 : 200;
var imgUrl;
if (parentName && item.ParentLogoItemId) {
imgUrl = ApiClient.getScaledImageUrl(item.ParentLogoItemId, {
height: logoHeight,
type: 'logo',
tag: item.ParentLogoImageTag
});
html += '
';
}
else if (item.ImageTags.Logo) {
imgUrl = ApiClient.getScaledImageUrl(item.Id, {
height: logoHeight,
type: 'logo',
tag: item.ImageTags.Logo
});
html += '
';
}
else {
html += parentName || name;
}
html += '
';
if (parentName) {
html += '
';
html += name;
html += '
';
} else if (!isSmallItem && !isMiniItem) {
html += '
';
html += LibraryBrowser.getMiscInfoHtml(item);
html += '
';
}
if (!isMiniItem) {
html += '
';
if (isPortrait) {
html += '';
html += '
';
html += LibraryBrowser.getUserDataIconsHtml(item);
html += '
';
} else {
html += '';
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 (MediaController.canPlay(item)) {
var resumePosition = (item.UserData || {}).PlaybackPositionTicks || 0;
html += '
';
buttonCount++;
}
if (commands.indexOf('trailer') != -1) {
html += '
';
buttonCount++;
}
html += '
';
buttonCount++;
html += '
';
html += '
';
return html;
}
function onTrailerButtonClick() {
var id = this.getAttribute('data-itemid');
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), id).done(function (trailers) {
MediaController.play({ items: trailers });
});
return false;
}
function onPlayItemButtonClick() {
var id = this.getAttribute('data-itemid');
var type = this.getAttribute('data-itemtype');
var isFolder = this.getAttribute('data-isfolder') == 'true';
var mediaType = this.getAttribute('data-mediatype');
var resumePosition = parseInt(this.getAttribute('data-resumeposition'));
LibraryBrowser.showPlayMenu(this, id, type, isFolder, mediaType, resumePosition);
return false;
}
function onMoreButtonClick() {
var card = $(this).parents('.card')[0];
showContextMenu(card, {
showPlayOptions: false
});
return false;
}
function onCardTapHold(e) {
showContextMenu(this, {});
e.preventDefault();
return false;
}
function showContextMenu(card, options) {
var displayContextItem = card;
if (card.classList.contains('listviewMenuButton')) {
card = $(card).parents('.listItem,.card')[0];
}
var itemId = card.getAttribute('data-itemid');
var playlistItemId = card.getAttribute('data-playlistitemid');
var commands = card.getAttribute('data-commands').split(',');
var itemType = card.getAttribute('data-itemtype');
var mediaType = card.getAttribute('data-mediatype');
var playbackPositionTicks = parseInt(card.getAttribute('data-positionticks') || '0');
var playAccess = card.getAttribute('data-playaccess');
var locationType = card.getAttribute('data-locationtype');
var index = card.getAttribute('data-index');
var albumid = card.getAttribute('data-albumid');
var artistid = card.getAttribute('data-artistid');
Dashboard.getCurrentUser().done(function (user) {
var items = [];
if (commands.indexOf('addtocollection') != -1) {
items.push({
name: Globalize.translate('ButtonAddToCollection'),
id: 'addtocollection',
ironIcon: 'add'
});
}
if (commands.indexOf('playlist') != -1) {
items.push({
name: Globalize.translate('ButtonAddToPlaylist'),
id: 'playlist',
ironIcon: 'playlist-add'
});
}
if (commands.indexOf('delete') != -1) {
items.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete',
ironIcon: 'delete'
});
}
if (user.Policy.IsAdministrator && commands.indexOf('edit') != -1) {
items.push({
name: Globalize.translate('ButtonEdit'),
id: 'edit',
ironIcon: 'mode-edit'
});
}
if (commands.indexOf('instantmix') != -1) {
items.push({
name: Globalize.translate('ButtonInstantMix'),
id: 'instantmix',
ironIcon: 'shuffle'
});
}
items.push({
name: Globalize.translate('ButtonOpen'),
id: 'open',
ironIcon: 'folder-open'
});
if (options.showPlayOptions !== false) {
if (MediaController.canPlayByAttributes(itemType, mediaType, playAccess, locationType)) {
items.push({
name: Globalize.translate('ButtonPlay'),
id: 'play',
ironIcon: 'play-arrow'
});
if (commands.indexOf('playfromhere') != -1) {
items.push({
name: Globalize.translate('ButtonPlayAllFromHere'),
id: 'playallfromhere',
ironIcon: 'play-arrow'
});
}
}
if (mediaType == 'Video' && AppSettings.enableExternalPlayers()) {
items.push({
name: Globalize.translate('ButtonPlayExternalPlayer'),
id: 'externalplayer',
ironIcon: 'airplay'
});
}
if (playbackPositionTicks && mediaType != "Audio") {
items.push({
name: Globalize.translate('ButtonResume'),
id: 'resume',
ironIcon: 'play-arrow'
});
}
if (commands.indexOf('trailer') != -1) {
items.push({
name: Globalize.translate('ButtonPlayTrailer'),
id: 'trailer',
ironIcon: 'play-arrow'
});
}
}
if (MediaController.canQueueMediaType(mediaType, itemType)) {
items.push({
name: Globalize.translate('ButtonQueue'),
id: 'queue',
ironIcon: 'playlist-add'
});
if (commands.indexOf('queuefromhere') != -1) {
items.push({
name: Globalize.translate('ButtonQueueAllFromHere'),
id: 'queueallfromhere',
ironIcon: 'playlist-add'
});
}
}
if (commands.indexOf('shuffle') != -1) {
items.push({
name: Globalize.translate('ButtonShuffle'),
id: 'shuffle',
ironIcon: 'shuffle'
});
}
if (commands.indexOf('removefromplaylist') != -1) {
items.push({
name: Globalize.translate('ButtonRemoveFromPlaylist'),
id: 'removefromplaylist',
ironIcon: 'remove'
});
}
if (commands.indexOf('sync') != -1) {
items.push({
name: Globalize.translate('ButtonSync'),
id: 'sync',
ironIcon: 'refresh'
});
}
if (albumid) {
items.push({
name: Globalize.translate('ButtonViewAlbum'),
id: 'album',
ironIcon: 'album'
});
}
if (artistid) {
items.push({
name: Globalize.translate('ButtonViewArtist'),
id: 'artist',
ironIcon: 'person'
});
}
var href = card.getAttribute('data-href') || card.href;
if (!href) {
var links = card.getElementsByTagName('a');
if (links.length) {
href = links[0].href;
}
}
require(['actionsheet'], function () {
ActionSheetElement.show({
items: items,
positionTo: displayContextItem,
callback: function (id) {
switch (id) {
case 'addtocollection':
BoxSetEditor.showPanel([itemId]);
break;
case 'playlist':
PlaylistManager.showPanel([itemId]);
break;
case 'delete':
LibraryBrowser.deleteItem(itemId);
break;
case 'download':
{
var downloadHref = ApiClient.getUrl("Items/" + itemId + "/Download", {
api_key: ApiClient.accessToken()
});
window.location.href = downloadHref;
break;
}
case 'edit':
Dashboard.navigate('edititemmetadata.html?id=' + itemId);
break;
case 'refresh':
ApiClient.refreshItem(itemId, {
Recursive: true,
ImageRefreshMode: 'FullRefresh',
MetadataRefreshMode: 'FullRefresh',
ReplaceAllImages: false,
ReplaceAllMetadata: true
});
break;
case 'instantmix':
MediaController.instantMix(itemId);
break;
case 'shuffle':
MediaController.shuffle(itemId);
break;
case 'open':
Dashboard.navigate(href);
break;
case 'album':
Dashboard.navigate('itemdetails.html?id=' + albumid);
break;
case 'artist':
Dashboard.navigate('itembynamedetails.html?context=music&id=' + artistid);
break;
case 'play':
MediaController.play(itemId);
break;
case 'playallfromhere':
$(card).parents('.itemsContainer').trigger('playallfromhere', [index]);
break;
case 'queue':
MediaController.queue(itemId);
break;
case 'trailer':
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), itemId).done(function (trailers) {
MediaController.play({ items: trailers });
});
break;
case 'resume':
MediaController.play({
ids: [itemId],
startPositionTicks: playbackPositionTicks
});
break;
case 'queueallfromhere':
$(card).parents('.itemsContainer').trigger('queueallfromhere', [index]);
break;
case 'sync':
SyncManager.showMenu({
items: [
{
Id: itemId
}]
});
break;
case 'externalplayer':
LibraryBrowser.playInExternalPlayer(itemId);
break;
case 'removefromplaylist':
$(card).parents('.itemsContainer').trigger('removefromplaylist', [playlistItemId]);
break;
default:
break;
}
}
});
});
});
}
function onListViewMenuButtonClick(e) {
showContextMenu(this, {});
e.preventDefault();
return false;
}
function onGroupedCardClick(e) {
var card = this;
var itemId = card.getAttribute('data-itemid');
var context = card.getAttribute('data-context');
var userId = Dashboard.getCurrentUserId();
var options = {
Limit: parseInt($('.playedIndicator', card).html() || '10'),
Fields: "PrimaryImageAspectRatio,DateCreated",
ParentId: itemId,
GroupItems: false
};
var target = e.target;
if (target.tagName == 'A' || target.tagName == 'BUTTON') {
return;
}
var buttonParents = $(target).parents('a:not(.card,.cardContent),button:not(.card,.cardContent)');
if (buttonParents.length) {
return;
}
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).done(function (items) {
if (items.length == 1) {
Dashboard.navigate(LibraryBrowser.getHref(items[0], context));
return;
}
var ids = items.map(function (i) {
return i.Id;
});
showItemsOverlay({
ids: ids,
context: context
});
});
e.preventDefault();
return false;
}
function getItemsOverlay(ids, context) {
$('.detailsMenu').remove();
var html = '';
$($.mobile.activePage).append(html);
var elem = $('.detailsMenu').popup().trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
})[0];
$('.detailsMenuLeftButton', elem).on('click', function () {
var overlay = $(this).parents('.detailsMenu')[0];
setItemIntoOverlay(overlay, parseInt(overlay.getAttribute('data-index') || '0') - 1, context);
});
$('.detailsMenuRightButton', elem).on('click', function () {
var overlay = $(this).parents('.detailsMenu')[0];
setItemIntoOverlay(overlay, parseInt(overlay.getAttribute('data-index') || '0') + 1, context);
});
return elem;
}
function setItemIntoOverlay(elem, index) {
var ids = elem.getAttribute('data-ids').split(',');
var itemId = ids[index];
var userId = Dashboard.getCurrentUserId();
var context = elem.getAttribute('data-context');
elem.setAttribute('data-index', index);
if (index > 0) {
$('.detailsMenuLeftButton', elem).show();
} else {
$('.detailsMenuLeftButton', elem).hide();
}
if (index < ids.length - 1) {
$('.detailsMenuRightButton', elem).show();
} else {
$('.detailsMenuRightButton', elem).hide();
}
var promise1 = ApiClient.getItem(userId, itemId);
var promise2 = Dashboard.getCurrentUser();
$.when(promise1, promise2).done(function (response1, response2) {
var item = response1[0];
var user = response2[0];
var background = 'none';
if (AppInfo.enableDetailsMenuImages) {
var backdropUrl;
var screenWidth = $(window).width();
var backdropWidth = Math.min(screenWidth, 800);
if (item.BackdropImageTags && item.BackdropImageTags.length) {
backdropUrl = ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: backdropWidth,
tag: item.BackdropImageTags[0]
});
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
backdropUrl = ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
tag: item.ParentBackdropImageTags[0],
maxWidth: backdropWidth
});
}
if (backdropUrl) {
background = 'url(' + backdropUrl + ')';
}
}
$('.detailsMenuContent', elem).css('backgroundImage', background);
var headerHtml = LibraryBrowser.getPosterViewDisplayName(item);
$('.detailsMenuHeader', elem).removeClass('detailsMenuHeaderWithLogo');
if (AppInfo.enableDetailsMenuImages) {
var logoUrl;
var logoHeight = 30;
if (item.ImageTags && item.ImageTags.Logo) {
logoUrl = ApiClient.getScaledImageUrl(item.Id, {
type: "Logo",
index: 0,
height: logoHeight,
tag: item.ImageTags.Logo
});
}
if (logoUrl) {
headerHtml = '