2016-07-18 14:50:00 -04:00
|
|
|
|
define(['itemShortcuts', 'connectionManager', 'layoutManager', 'browser', 'dom', 'registerElement'], function (itemShortcuts, connectionManager, layoutManager, browser, dom) {
|
2016-07-16 14:02:39 -04:00
|
|
|
|
|
|
|
|
|
var ItemsContainerProtoType = Object.create(HTMLDivElement.prototype);
|
|
|
|
|
|
2016-07-16 17:28:15 -04:00
|
|
|
|
function onClick(e) {
|
|
|
|
|
|
2016-07-17 12:59:14 -04:00
|
|
|
|
var itemsContainer = this;
|
2016-07-17 14:55:07 -04:00
|
|
|
|
var target = e.target;
|
2016-07-17 12:59:14 -04:00
|
|
|
|
|
2016-07-18 23:57:55 -04:00
|
|
|
|
var multiSelect = itemsContainer.multiSelect;
|
|
|
|
|
|
|
|
|
|
if (multiSelect) {
|
|
|
|
|
if (multiSelect.onContainerClick.call(itemsContainer, e) === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemShortcuts.onClick.call(itemsContainer, e);
|
2016-07-17 14:55:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableEvent(e) {
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onContextMenu(e) {
|
|
|
|
|
|
|
|
|
|
var itemsContainer = this;
|
|
|
|
|
|
|
|
|
|
var target = e.target;
|
2016-07-18 14:50:00 -04:00
|
|
|
|
var card = dom.parentWithAttribute(target, 'data-id');
|
2016-07-18 02:45:29 -04:00
|
|
|
|
|
2016-07-17 14:55:07 -04:00
|
|
|
|
if (card) {
|
|
|
|
|
|
|
|
|
|
//var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
|
|
|
|
|
|
|
|
|
|
//if (!itemSelectionPanel) {
|
|
|
|
|
// showContextMenu(card, {});
|
|
|
|
|
//}
|
|
|
|
|
|
2016-07-17 16:08:04 -04:00
|
|
|
|
itemShortcuts.showContextMenu(card, {
|
|
|
|
|
identify: false,
|
|
|
|
|
positionTo: target,
|
|
|
|
|
itemsContainer: itemsContainer
|
2016-07-17 14:55:07 -04:00
|
|
|
|
});
|
|
|
|
|
|
2016-07-18 02:45:29 -04:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-17 14:55:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getShortcutOptions() {
|
|
|
|
|
return {
|
|
|
|
|
click: false
|
|
|
|
|
};
|
2016-07-16 17:28:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 22:55:07 -04:00
|
|
|
|
ItemsContainerProtoType.enableHoverMenu = function (enabled) {
|
|
|
|
|
|
|
|
|
|
var current = this.hoverMenu;
|
|
|
|
|
|
2016-07-19 15:51:22 -04:00
|
|
|
|
if (!enabled) {
|
|
|
|
|
if (current) {
|
|
|
|
|
current.destroy();
|
|
|
|
|
this.hoverMenu = null;
|
|
|
|
|
}
|
2016-07-17 22:55:07 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
require(['itemHoverMenu'], function (ItemHoverMenu) {
|
|
|
|
|
self.hoverMenu = new ItemHoverMenu(self);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-18 02:45:29 -04:00
|
|
|
|
ItemsContainerProtoType.enableMultiSelect = function (enabled) {
|
|
|
|
|
|
|
|
|
|
var current = this.multiSelect;
|
|
|
|
|
|
2016-07-19 15:51:22 -04:00
|
|
|
|
if (!enabled) {
|
|
|
|
|
if (current) {
|
|
|
|
|
current.destroy();
|
|
|
|
|
this.multiSelect = null;
|
|
|
|
|
}
|
2016-07-18 02:45:29 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
require(['multiSelect'], function (MultiSelect) {
|
2016-07-18 23:57:55 -04:00
|
|
|
|
self.multiSelect = new MultiSelect({
|
|
|
|
|
container: self,
|
|
|
|
|
bindOnClick: false
|
|
|
|
|
});
|
2016-07-18 02:45:29 -04:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-16 14:02:39 -04:00
|
|
|
|
ItemsContainerProtoType.attachedCallback = function () {
|
2016-07-18 02:45:29 -04:00
|
|
|
|
|
2016-07-16 17:28:15 -04:00
|
|
|
|
this.addEventListener('click', onClick);
|
2016-07-17 14:55:07 -04:00
|
|
|
|
|
2016-07-18 02:45:29 -04:00
|
|
|
|
if (browser.mobile) {
|
2016-07-17 14:55:07 -04:00
|
|
|
|
this.addEventListener('contextmenu', disableEvent);
|
|
|
|
|
} else {
|
|
|
|
|
this.addEventListener('contextmenu', onContextMenu);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 22:55:07 -04:00
|
|
|
|
if (layoutManager.desktop) {
|
|
|
|
|
this.enableHoverMenu(true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 02:45:29 -04:00
|
|
|
|
if (layoutManager.desktop || layoutManager.mobile) {
|
|
|
|
|
this.enableMultiSelect(true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 14:55:07 -04:00
|
|
|
|
itemShortcuts.on(this, getShortcutOptions());
|
2016-07-16 14:02:39 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ItemsContainerProtoType.detachedCallback = function () {
|
2016-07-18 02:45:29 -04:00
|
|
|
|
|
|
|
|
|
this.enableHoverMenu(false);
|
|
|
|
|
this.enableMultiSelect(false);
|
2016-07-16 17:28:15 -04:00
|
|
|
|
this.removeEventListener('click', onClick);
|
2016-07-17 14:55:07 -04:00
|
|
|
|
this.removeEventListener('contextmenu', onContextMenu);
|
|
|
|
|
this.removeEventListener('contextmenu', disableEvent);
|
|
|
|
|
itemShortcuts.off(this, getShortcutOptions());
|
2016-07-16 14:02:39 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.registerElement('emby-itemscontainer', {
|
|
|
|
|
prototype: ItemsContainerProtoType,
|
|
|
|
|
extends: 'div'
|
|
|
|
|
});
|
|
|
|
|
});
|