jellyfin-web/dashboard-ui/scripts/photos.js

230 lines
6.4 KiB
JavaScript
Raw Normal View History

2015-04-19 08:54:20 -07:00
(function ($, document) {
2015-05-26 08:31:50 -07:00
var view = LibraryBrowser.getDefaultItemsView('Poster', 'Poster');
2015-04-19 08:54:20 -07:00
2015-07-12 12:33:00 -07:00
var data = {};
function getQuery(tab) {
var key = getSavedQueryKey(tab);
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
}
};
setQueryPerTab(tab, pageData.query);
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData.query;
}
2015-04-19 08:54:20 -07:00
2015-07-12 12:33:00 -07:00
function getSavedQueryKey(tab) {
2015-04-19 08:54:20 -07:00
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey('tab=' + tab);
2015-04-19 08:54:20 -07:00
}
2015-07-12 12:33:00 -07:00
function reloadItems(page, tabIndex) {
2015-04-19 08:54:20 -07:00
Dashboard.showLoadingMsg();
2015-07-12 12:33:00 -07:00
var query = getQuery(tabIndex);
2015-04-19 08:54:20 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
// Scroll back up so they can see the results from the beginning
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
2015-04-19 08:54:20 -07:00
var html = '';
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: false,
showLimit: false
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2015-04-19 08:54:20 -07:00
2015-05-12 21:55:19 -07:00
if (view == "Poster") {
// Poster
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-07-12 12:33:00 -07:00
shape: "square",
2015-05-12 21:55:19 -07:00
context: getParameterByName('context') || 'photos',
2015-10-25 22:29:32 -07:00
overlayText: true,
2015-05-12 21:55:19 -07:00
lazy: true,
2015-07-12 12:33:00 -07:00
coverImage: true,
2015-08-16 08:53:30 -07:00
showTitle: tabIndex == 0,
centerText: true
2015-05-12 21:55:19 -07:00
});
}
2015-04-19 08:54:20 -07:00
2015-07-12 12:33:00 -07:00
var elem = page.querySelector('.itemsContainer');
2015-06-28 07:45:21 -07:00
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2015-04-19 08:54:20 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2015-07-12 12:33:00 -07:00
reloadItems(page, tabIndex);
2015-04-19 08:54:20 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2015-07-12 12:33:00 -07:00
reloadItems(page, tabIndex);
2015-04-19 08:54:20 -07:00
});
2015-07-12 12:33:00 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(tabIndex), query);
2015-04-19 08:54:20 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-07-12 12:33:00 -07:00
function setQueryPerTab(tab, query) {
2015-04-19 08:54:20 -07:00
2015-07-12 12:33:00 -07:00
if (tab == 1) {
2015-04-19 08:54:20 -07:00
query.Recursive = true;
query.MediaTypes = 'Photo';
}
2015-07-12 12:33:00 -07:00
else if (tab == 2) {
2015-04-19 08:54:20 -07:00
query.Recursive = true;
query.MediaTypes = 'Video';
}
2015-07-12 12:33:00 -07:00
else if (tab == 0) {
2015-04-19 08:54:20 -07:00
query.Recursive = false;
query.MediaTypes = null;
}
query.ParentId = getParameterByName('parentId') || LibraryMenu.getTopParentId();
}
2015-05-09 21:29:04 -07:00
function startSlideshow(page, itemQuery, startItemId) {
2015-04-22 06:28:45 -07:00
var userId = Dashboard.getCurrentUserId();
2015-05-09 21:29:04 -07:00
var localQuery = $.extend({}, itemQuery);
2015-04-22 06:28:45 -07:00
localQuery.StartIndex = 0;
localQuery.Limit = null;
localQuery.MediaTypes = "Photo";
localQuery.Recursive = true;
localQuery.Filters = "IsNotFolder";
ApiClient.getItems(userId, localQuery).done(function (result) {
2015-05-09 21:29:04 -07:00
showSlideshow(page, result.Items, startItemId);
2015-04-22 06:28:45 -07:00
});
}
2015-05-09 21:29:04 -07:00
function showSlideshow(page, items, startItemId) {
2015-04-22 06:28:45 -07:00
2015-05-29 16:51:33 -07:00
var screenWidth = $(window).width();
var screenHeight = $(window).height();
2015-04-22 06:28:45 -07:00
var slideshowItems = items.map(function (item) {
var imgUrl = ApiClient.getScaledImageUrl(item.Id, {
tag: item.ImageTags.Primary,
2015-05-29 16:51:33 -07:00
type: 'Primary',
maxWidth: screenWidth,
maxHeight: screenHeight
2015-04-22 06:28:45 -07:00
});
return {
title: item.Name,
href: imgUrl
};
});
2015-05-09 21:29:04 -07:00
var index = items.map(function (i) {
return i.Id;
}).indexOf(startItemId);
if (index == -1) {
index = 0;
}
Dashboard.loadSwipebox().done(function () {
2015-04-22 06:28:45 -07:00
2015-05-08 20:48:43 -07:00
$.swipebox(slideshowItems, {
initialIndexOnArray: index,
hideBarsDelay: 30000
});
2015-04-22 06:28:45 -07:00
});
}
2015-05-09 21:29:04 -07:00
function onListItemClick(e) {
2015-07-12 12:33:00 -07:00
var page = $(this).parents('.page')[0];
2015-05-09 21:29:04 -07:00
var info = LibraryBrowser.getListItemInfo(this);
if (info.mediaType == 'Photo') {
2015-07-12 12:33:00 -07:00
var tab = page.querySelector('neon-animated-pages').selected;
var query = getQuery(tab);
2015-05-09 21:29:04 -07:00
Photos.startSlideshow(page, query, info.id);
return false;
}
}
2015-07-12 12:33:00 -07:00
function loadTab(page, index) {
switch (index) {
case 0:
{
reloadItems(page.querySelector('.albumTabContent'), 0);
}
break;
case 1:
{
reloadItems(page.querySelector('.photoTabContent'), 1);
}
break;
case 2:
{
reloadItems(page.querySelector('.videoTabContent'), 2);
}
break;
default:
break;
}
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#photosPage", function () {
2015-04-19 08:54:20 -07:00
var page = this;
2015-07-12 12:33:00 -07:00
var tabs = page.querySelector('paper-tabs');
2015-04-19 08:54:20 -07:00
2015-09-01 08:31:50 -07:00
var baseUrl = 'photos.html';
var topParentId = LibraryMenu.getTopParentId();
if (topParentId) {
baseUrl += '?topParentId=' + topParentId;
}
2015-04-19 08:54:20 -07:00
2015-09-01 08:31:50 -07:00
LibraryBrowser.configurePaperLibraryTabs(page, tabs, page.querySelector('neon-animated-pages'), baseUrl);
2015-04-19 08:54:20 -07:00
2015-07-12 12:33:00 -07:00
$(page.querySelector('neon-animated-pages')).on('tabchange', function () {
loadTab(page, parseInt(this.selected));
2015-04-19 08:54:20 -07:00
});
2015-07-12 12:33:00 -07:00
$(page).on('click', '.mediaItem', onListItemClick);
2015-04-19 08:54:20 -07:00
});
2015-05-09 21:29:04 -07:00
window.Photos = {
startSlideshow: startSlideshow
};
2015-04-19 08:54:20 -07:00
})(jQuery, document);