jellyfin-web/dashboard-ui/scripts/librarylist.js
2016-07-18 23:57:55 -04:00

59 lines
1.6 KiB
JavaScript

define(['libraryBrowser'], function (libraryBrowser) {
function isClickable(target) {
while (target != null) {
var tagName = target.tagName || '';
if (tagName == 'A' || tagName.indexOf('BUTTON') != -1 || tagName.indexOf('INPUT') != -1) {
return true;
}
return false;
//target = target.parentNode;
}
return false;
}
function onGroupedCardClick(e, card) {
var itemId = card.getAttribute('data-id');
var context = card.getAttribute('data-context');
var userId = Dashboard.getCurrentUserId();
var playedIndicator = card.querySelector('.playedIndicator');
var playedIndicatorHtml = playedIndicator ? playedIndicator.innerHTML : null;
var options = {
Limit: parseInt(playedIndicatorHtml || '10'),
Fields: "PrimaryImageAspectRatio,DateCreated",
ParentId: itemId,
GroupItems: false
};
var target = e.target;
if (isClickable(target)) {
return;
}
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).then(function (items) {
if (items.length == 1) {
Dashboard.navigate(libraryBrowser.getHref(items[0], context));
return;
}
var url = 'itemdetails.html?id=' + itemId;
if (context) {
url += '&context=' + context;
}
Dashboard.navigate(url);
});
e.stopPropagation();
e.preventDefault();
return false;
}
});