Fix the issue with ContextMenus being completely non-functional in v13 (closes #91)
This commit is contained in:
parent
9177b7cc2d
commit
b36fe27182
2 changed files with 24 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { __ID__, filePath } from "../consts.mjs";
|
import { __ID__, filePath } from "../consts.mjs";
|
||||||
import { deleteItemFromElement, editItemFromElement } from "./utils.mjs";
|
import { createContextMenuOption, deleteItemFromElement, editItemFromElement } from "./utils.mjs";
|
||||||
import { config } from "../config.mjs";
|
import { config } from "../config.mjs";
|
||||||
import { Logger } from "../utils/Logger.mjs";
|
import { Logger } from "../utils/Logger.mjs";
|
||||||
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
||||||
|
|
@ -226,7 +226,7 @@ export class PlayerSheet extends
|
||||||
this.element,
|
this.element,
|
||||||
`[data-item-uuid]`,
|
`[data-item-uuid]`,
|
||||||
[
|
[
|
||||||
{
|
createContextMenuOption({
|
||||||
label: _loc(`taf.misc.edit`),
|
label: _loc(`taf.misc.edit`),
|
||||||
condition: (el) => {
|
condition: (el) => {
|
||||||
const itemUuid = el.dataset.itemUuid;
|
const itemUuid = el.dataset.itemUuid;
|
||||||
|
|
@ -234,8 +234,8 @@ export class PlayerSheet extends
|
||||||
return this.isEditable && itemExists;
|
return this.isEditable && itemExists;
|
||||||
},
|
},
|
||||||
onClick: editItemFromElement,
|
onClick: editItemFromElement,
|
||||||
},
|
}),
|
||||||
{
|
createContextMenuOption({
|
||||||
label: _loc(`taf.misc.delete`),
|
label: _loc(`taf.misc.delete`),
|
||||||
condition: (el) => {
|
condition: (el) => {
|
||||||
const itemUuid = el.dataset.itemUuid;
|
const itemUuid = el.dataset.itemUuid;
|
||||||
|
|
@ -243,7 +243,7 @@ export class PlayerSheet extends
|
||||||
return this.isEditable && itemExists;
|
return this.isEditable && itemExists;
|
||||||
},
|
},
|
||||||
onClick: deleteItemFromElement,
|
onClick: deleteItemFromElement,
|
||||||
},
|
}),
|
||||||
],
|
],
|
||||||
{ jQuery: false, fixed: true },
|
{ jQuery: false, fixed: true },
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,25 @@ This file contains utility methods used by Applications in order to be
|
||||||
DRYer
|
DRYer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function that takes a v14-compatible ContextMenuEntry option
|
||||||
|
* and adjusts it for v13 if required
|
||||||
|
*
|
||||||
|
* @param {ContextMenuEntry} option The v14+ compatible menu entry option
|
||||||
|
* @returns {ContextMenuEntry} The v14+ or <v13 menu option object
|
||||||
|
*/
|
||||||
|
export function createContextMenuOption(option) {
|
||||||
|
if (game.release.generation < 14) {
|
||||||
|
return {
|
||||||
|
name: option.label,
|
||||||
|
visible: option.condition,
|
||||||
|
callback: (target) => option.onClick(null, target),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return option;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Event} _event The click event
|
* @param {Event} _event The click event
|
||||||
* @param {HTMLElement} target The element to operate on
|
* @param {HTMLElement} target The element to operate on
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue