Support events other than 'contextmenu'

This commit is contained in:
Andrew Henry
2018-11-23 09:05:01 -08:00
parent a7948ce83e
commit 94cdce3551

View File

@ -13,15 +13,21 @@ class ContextMenuRegistry {
this._allActions.push(actionDefinition); this._allActions.push(actionDefinition);
} }
attachTo(targetElement, objectPath) { attachTo(targetElement, objectPath, eventName) {
eventName = eventName || 'contextmenu';
if (eventName !== 'contextmenu' && eventName !== 'click') {
throw `'${eventName}' event not supported for context menu`;
}
let showContextMenu = (event) => { let showContextMenu = (event) => {
this._showContextMenuForObjectPath(event, objectPath); this._showContextMenuForObjectPath(event, objectPath);
}; };
targetElement.addEventListener('contextmenu', showContextMenu); targetElement.addEventListener(eventName, showContextMenu);
return function detach() { return function detach() {
targetElement.removeEventListener('contextMenu', showContextMenu); targetElement.removeEventListener(eventName, showContextMenu);
} }
} }