Add the ArtBrowser open when using Foundry's editImage action
This commit is contained in:
parent
516c0d0c5e
commit
cf8c82784b
5 changed files with 47 additions and 1 deletions
25
module/hooks/getHeaderControlsDocumentSheetV2.mjs
Normal file
25
module/hooks/getHeaderControlsDocumentSheetV2.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { ArtBrowser } from "../apps/ArtBrowser.mjs";
|
||||
import { __ID__ } from "../consts.mjs";
|
||||
|
||||
Hooks.on(`getHeaderControlsDocumentSheetV2`, (sheet) => {
|
||||
|
||||
const original = sheet.options.actions.editImage;
|
||||
sheet.options.actions.editImage = async (event, target) => {
|
||||
|
||||
if (!game.settings.get(__ID__, `openForEditImage`)) {
|
||||
return original.call(sheet, event, target);
|
||||
};
|
||||
|
||||
if (target.nodeName !== `IMG`) {
|
||||
throw new Error(`The editImage action is available only for IMG elements.`);
|
||||
};
|
||||
|
||||
const src = await ArtBrowser.select(1);
|
||||
if (!src) { return };
|
||||
target.src = src;
|
||||
if (sheet.options.form.submitOnChange) {
|
||||
const submit = new Event(`submit`, { cancelable: true });
|
||||
sheet.form.dispatchEvent(submit);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
@ -2,12 +2,14 @@ import { api } from "../api.mjs";
|
|||
import { ArtSidebar } from "../apps/ArtSidebar.mjs";
|
||||
import { registerCustomComponents } from "../apps/elements/_index.mjs";
|
||||
import helpers from "../handlebarsHelpers/_index.mjs";
|
||||
import { registerUserSettings } from "../settings/user.mjs";
|
||||
|
||||
Hooks.on(`init`, () => {
|
||||
globalThis.tb = api;
|
||||
|
||||
Handlebars.registerHelper(helpers);
|
||||
registerUserSettings();
|
||||
registerCustomComponents();
|
||||
Handlebars.registerHelper(helpers);
|
||||
|
||||
// Art sidebar tab
|
||||
CONFIG.ui.sidebar.TABS.art = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue