2016-07-16 14:28:15 -07:00
|
|
|
|
define(['itemShortcuts', 'connectionManager', 'registerElement'], function (itemShortcuts, connectionManager) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
|
|
var ItemsContainerProtoType = Object.create(HTMLDivElement.prototype);
|
|
|
|
|
|
2016-07-16 14:28:15 -07:00
|
|
|
|
function parentWithClass(elem, className) {
|
|
|
|
|
|
|
|
|
|
while (!elem.classList || !elem.classList.contains(className)) {
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parentWithAttribute(elem, name) {
|
|
|
|
|
|
|
|
|
|
while (!elem.getAttribute(name)) {
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getItem(button) {
|
|
|
|
|
|
|
|
|
|
button = parentWithAttribute(button, 'data-id');
|
|
|
|
|
var serverId = button.getAttribute('data-serverid');
|
|
|
|
|
var id = button.getAttribute('data-id');
|
|
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
|
|
|
|
|
return apiClient.getItem(apiClient.getCurrentUserId(), id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showContextMenu(button) {
|
|
|
|
|
|
|
|
|
|
getItem(button).then(function (item) {
|
|
|
|
|
|
|
|
|
|
require(['itemContextMenu'], function (itemContextMenu) {
|
|
|
|
|
itemContextMenu.show({
|
|
|
|
|
positionTo: button,
|
|
|
|
|
item: item
|
|
|
|
|
});
|
2016-07-16 16:08:21 -07:00
|
|
|
|
|
|
|
|
|
// TODO: playallfromhere, queueallfromhere
|
2016-07-16 14:28:15 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onClick(e) {
|
|
|
|
|
|
|
|
|
|
var menuButton = parentWithClass(e.target, 'menuButton');
|
|
|
|
|
if (menuButton) {
|
|
|
|
|
showContextMenu(menuButton);
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-16 11:02:39 -07:00
|
|
|
|
ItemsContainerProtoType.attachedCallback = function () {
|
2016-07-16 14:28:15 -07:00
|
|
|
|
this.addEventListener('click', onClick);
|
2016-07-16 11:02:39 -07:00
|
|
|
|
itemShortcuts.on(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ItemsContainerProtoType.detachedCallback = function () {
|
2016-07-16 14:28:15 -07:00
|
|
|
|
this.removeEventListener('click', onClick);
|
2016-07-16 11:02:39 -07:00
|
|
|
|
itemShortcuts.off(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.registerElement('emby-itemscontainer', {
|
|
|
|
|
prototype: ItemsContainerProtoType,
|
|
|
|
|
extends: 'div'
|
|
|
|
|
});
|
|
|
|
|
});
|