1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/emby-itemscontainer/emby-itemscontainer.js
2016-07-17 16:08:04 -04:00

90 lines
No EOL
2.3 KiB
JavaScript

define(['itemShortcuts', 'connectionManager', 'layoutManager', 'browser', 'registerElement'], function (itemShortcuts, connectionManager, layoutManager, browser) {
var ItemsContainerProtoType = Object.create(HTMLDivElement.prototype);
function parentWithAttribute(elem, name) {
while (!elem.getAttribute(name)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function onClick(e) {
var itemsContainer = this;
var target = e.target;
itemShortcuts.onClick.call(this, e);
}
function disableEvent(e) {
e.preventDefault();
e.stopPropagation();
return false;
}
function onContextMenu(e) {
var itemsContainer = this;
var target = e.target;
var card = parentWithAttribute(target, 'data-id');
if (card) {
//var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
//if (!itemSelectionPanel) {
// showContextMenu(card, {});
//}
itemShortcuts.showContextMenu(card, {
identify: false,
positionTo: target,
itemsContainer: itemsContainer
});
}
e.preventDefault();
e.stopPropagation();
return false;
}
function getShortcutOptions() {
return {
click: false
};
}
ItemsContainerProtoType.attachedCallback = function () {
this.addEventListener('click', onClick);
// mobile safari doesn't allow contextmenu override
if (browser.safari && browser.mobile) {
this.addEventListener('contextmenu', disableEvent);
// todo: use tap hold
} else {
this.addEventListener('contextmenu', onContextMenu);
}
itemShortcuts.on(this, getShortcutOptions());
};
ItemsContainerProtoType.detachedCallback = function () {
this.removeEventListener('click', onClick);
this.removeEventListener('contextmenu', onContextMenu);
this.removeEventListener('contextmenu', disableEvent);
itemShortcuts.off(this, getShortcutOptions());
};
document.registerElement('emby-itemscontainer', {
prototype: ItemsContainerProtoType,
extends: 'div'
});
});