Commit 6f4f4313 authored by Big Bad Waffle's avatar Big Bad Waffle

the renderitem helper method can now add tooltips and context menus to elements

parent da311c18
......@@ -6,11 +6,63 @@ const tplItem = `
`;
define([
'js/system/events'
], function (
events
) {
return (container, item, useEl) => {
const onHover = (el, item, e) => {
if (item)
this.hoverItem = item;
else
item = this.hoverItem;
let ttPos = null;
if (el) {
ttPos = {
x: ~~(e.clientX + 32),
y: ~~(e.clientY)
};
}
events.emit('onShowItemTooltip', item, ttPos, true);
};
const hideTooltip = (el, item, e) => {
events.emit('onHideItemTooltip', item);
};
const addTooltipEvents = (el, item) => {
let moveHandler = onHover.bind(null, el, item);
let downHandler = () => {};
if (isMobile) {
moveHandler = () => {};
downHandler = onHover.bind(null, el, item);
}
el
.on('mousedown', downHandler)
.on('mousemove', moveHandler)
.on('mouseleave', hideTooltip.bind(null, el, item));
};
const onShowContext = (item, getItemContextConfig, e) => {
if (isMobile)
hideTooltip(null, item);
const contextConfig = getItemContextConfig(item);
events.emit('onContextMenu', contextConfig, e);
e.preventDefault();
return false;
};
const addContextEvents = (el, item, getItemContextConfig) => {
el.on('contextmenu', onShowContext.bind(this, item, getItemContextConfig));
};
return (container, item, useEl, manageTooltip, getItemContextConfig) => {
const itemEl = useEl || $(tplItem).appendTo(container);
if (!item) {
......@@ -72,6 +124,12 @@ define([
if (item.has('quality'))
itemEl.addClass(`quality-${item.quality}`);
if (manageTooltip)
addTooltipEvents(itemEl, item);
if (getItemContextConfig)
addContextEvents(itemEl, item, getItemContextConfig);
return itemEl;
};
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment