Added a commonListeners in helper to avoid repetitions

Added a "compendium-link" listener class to open compendium folder in JournalEntries
This commit is contained in:
Vlyan
2021-06-02 15:05:50 +02:00
parent aeec63dcc4
commit b1a1430114
7 changed files with 57 additions and 19 deletions

View File

@@ -289,12 +289,8 @@ export class BaseSheetL5r5e extends ActorSheet {
activateListeners(html) {
super.activateListeners(html);
// Toggle
html.find(".toggle-on-click").on("click", (event) => {
const elmt = $(event.currentTarget).data("toggle");
const tgt = html.find("." + elmt);
tgt.toggleClass("toggle-active");
});
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html);
// *** Everything below here is only needed if the sheet is editable ***
if (!this.options.editable) {

View File

@@ -160,12 +160,8 @@ export class TwentyQuestionsDialog extends FormApplication {
activateListeners(html) {
super.activateListeners(html);
// Toggle
html.find(".toggle-on-click").on("click", (event) => {
const elmt = $(event.currentTarget).data("toggle");
const tgt = html.find("." + elmt);
tgt.toggleClass("toggle-active");
});
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html);
// BT Next
html.find(".next").on("click", (event) => {

View File

@@ -362,4 +362,28 @@ export class HelpersL5r5e {
});
return { xp_used, xp_used_total };
}
/**
* Subscribe to common events from the sheet.
* @param {jQuery} html HTML content of the sheet.
*/
static commonListeners(html) {
// Toggle
html.find(".toggle-on-click").on("click", (event) => {
const elmt = $(event.currentTarget).data("toggle");
const tgt = html.find("." + elmt);
tgt.toggleClass("toggle-active");
});
// Compendium folder link
html.find(".compendium-link").on("click", (event) => {
const packId = $(event.currentTarget).data("pack");
if (packId) {
const pack = game.packs.get(packId);
if (pack) {
pack.render(true);
}
}
});
}
}

View File

@@ -88,12 +88,8 @@ export class ItemSheetL5r5e extends ItemSheet {
activateListeners(html) {
super.activateListeners(html);
// Toggle
html.find(".toggle-on-click").on("click", (event) => {
const elmt = $(event.currentTarget).data("toggle");
const tgt = html.find("." + elmt);
tgt.toggleClass("toggle-active");
});
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) {

View File

@@ -31,4 +31,20 @@ export class BaseJournalSheetL5r5e extends JournalSheet {
}
return super._updateObject(event, formData);
}
/**
* Subscribe to events from the sheet.
* @param {jQuery} html HTML content of the sheet.
*/
activateListeners(html) {
super.activateListeners(html);
// Commons
game.l5r5e.HelpersL5r5e.commonListeners(html);
// *** Everything below here is only needed if the sheet is editable ***
// if (!this.options.editable) {
// return;
// }
}
}