(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 (MediaController.canPlay(item)) { var resumePosition = (item.UserData || {}).PlaybackPositionTicks || 0; var onPlayClick = 'LibraryBrowser.showPlayMenu(this, \'' + item.Id + '\', \'' + item.Type + '\', ' + item.IsFolder + ', \'' + 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++; } 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 onMenuCommand(command, elem) { var id = elem.getAttribute('data-itemid'); var page = $(elem).parents('.page'); if (command == 'SplitVersions') { splitVersions(id, page); } } function splitVersions(id, page) { Dashboard.confirm("Are you sure you wish to split the media sources into separate items?", "Split Media Apart", function (confirmResult) { if (confirmResult) { Dashboard.showLoadingMsg(); $.ajax({ type: "DELETE", url: ApiClient.getUrl("Videos/" + id + "/AlternateSources") }).done(function () { Dashboard.hideLoadingMsg(); $('.itemsContainer', page).trigger('needsrefresh'); }); } }); } function getContextMenuOptions(elem) { var items = []; var id = elem.getAttribute('data-itemid'); 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 }); var versionCount = parseInt(elem.getAttribute('data-mediasourcecount') || '0'); if (versionCount > 1) { items.push({ type: 'divider' }); items.push({ type: 'header', text: 'Manage' }); items.push({ type: 'command', text: 'Split Versions Apart', name: 'SplitVersions' }); } return items; } $.fn.createPosterItemMenus = function (options) { options = options || {}; function onShowTimerExpired(elem) { if ($(elem).hasClass('hasContextMenu')) { return; } if ($('.itemSelectionPanel:visible', elem).length) { 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); }); 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; if (options.contextMenu !== false) { Dashboard.getCurrentUser().done(function (user) { if (user.Configuration.IsAdministrator) { sequence.createContextMenu({ getOptions: getContextMenuOptions, command: onMenuCommand, selector: '.posterItem' }); } }); } return this.on('mouseenter', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverIn) .on('mouseleave', '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem', onHoverOut); }; function toggleSelections(page) { Dashboard.showLoadingMsg(); var selectionCommands = $('.selectionCommands', page); if (selectionCommands.is(':visible')) { selectionCommands.hide(); $('.itemSelectionPanel', page).hide(); } else { selectionCommands.show(); $('.itemSelectionPanel', page).show(); $('.chkItemSelect:checked', page).checked(false).checkboxradio('refresh'); } Dashboard.hideLoadingMsg(); } function hideSelections(page) { $('.selectionCommands', page).hide(); $('.itemSelectionPanel', page).hide(); } function getSelectedItems(page) { var selection = $('.chkItemSelect:checked', page); return selection.parents('.posterItem') .map(function () { return this.getAttribute('data-itemid'); }).get(); } function combineVersions(page) { var selection = getSelectedItems(page); if (selection.length < 2) { Dashboard.alert({ message: "Please select two or more items to group together.", title: "Error" }); return; } var names = $('.chkItemSelect:checked', page).parents('.posterItem').get().reverse().map(function (e) { return $('.posterItemText', e).html(); }).join('
'); var msg = "The following titles will be grouped into one item:

" + names; msg += "

Media Browser clients will automatically choose the optimal version to play based on device and network performance. Are you sure you wish to continue?"; Dashboard.confirm(msg, "Group Versions", function (confirmResult) { if (confirmResult) { Dashboard.showLoadingMsg(); $.ajax({ type: "POST", url: ApiClient.getUrl("Videos/MergeVersions", { Ids: selection.join(',') }) }).done(function () { Dashboard.hideLoadingMsg(); hideSelections(); $('.itemsContainer', page).trigger('needsrefresh'); }); } }); } $(document).on('pageinit', ".libraryPage", function () { var page = this; $('.btnToggleSelections', page).on('click', function () { toggleSelections(page); }); $('.btnMergeVersions', page).on('click', function () { combineVersions(page); }); }); })(jQuery, document, window);