Added DHContextMenu to pass on the event from clicking a contextmenuitem

This commit is contained in:
WBHarry 2025-06-28 12:59:11 +02:00
parent 9dd05cab33
commit 992afd4d94
4 changed files with 30 additions and 4 deletions

View file

@ -0,0 +1,24 @@
export default class DhContextMenu extends ContextMenu {
constructor(container, selector, menuItems, options) {
super(container, selector, menuItems, options);
/** @deprecated since v13 until v15 */
this.#jQuery = options.jQuery;
}
#jQuery;
activateListeners(menu) {
menu.addEventListener('click', this.#onClickItem.bind(this));
}
#onClickItem(event) {
event.preventDefault();
event.stopPropagation();
const element = event.target.closest('.context-item');
if (!element) return;
const item = this.menuItems.find(i => i.element === element);
item?.callback(this.#jQuery ? $(this.target) : this.target, event);
this.close();
}
}