Giter Club home page Giter Club logo

Comments (6)

kgar avatar kgar commented on July 2, 2024

Proof of concept via world script macro does indeed work as intended:

Hooks.on('tidy5e-sheet.renderActorSheet', (sheet, element, data) => {
  element
    .querySelector(`[data-tidy-sheet-part="resources-container"]`)
    ?.insertAdjacentHTML(
      'afterbegin',
      `<div style="display: contents;" data-tidy-render-scheme="handlebars">
        <h2 type="button" style="width: 100%;">Resources for ${data.actor.name}</h2>
      </div>`
    );
});

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on July 2, 2024

Beginning API / runtime work...

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on July 2, 2024

An initial look at registering "Inject Anywhere" content:

const api = game.modules.get('tidy5e-sheet').api ?? game.modules.get('tidy5e-sheet-kgar').api;

api.registerCharacterContent(
  api.getSheetPartSelector(api.constants.SHEET_PARTS.RESOURCE),
  'afterbegin',
  new api.models.HtmlContent({
    html: `<span class="test-emoji" style="cursor: pointer; position: absolute; bottom: 0; right: 1rem;">😊</span>`,
    onRender({ app, element, data }) {
      element
        .querySelectorAll('.test-emoji')
        .forEach((el) =>
          el.addEventListener(
            'click',
            (ev) => (ev.currentTarget.innerHTML = '💀')
          )
        );
    },
  })
);

image

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on July 2, 2024

I'm still working on the actual function parameters. I am thinking of offering these options at first:

  • a highly structured option for those who want to render HTML / Handlebars and do not have complex requirements; this approach basically leverages the API of insertAdjacentHTML()
  • an option where I prepare the markup (rendering Handlebars templates with data, putting the dynamic wrapper around the resulting HTML) but give it over to the user to distribute however they please via a callback

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on July 2, 2024

Updated preview of the API - adding an icon next to the actor sheet name field:

Hooks.once("tidy5e-sheet.ready", (api) => {
  api.registerActorContent(
    new api.models.HtmlContent({
      html: `<a title="Example Button" class="my-custom-button"><i class="fas fa-user"></i></a>`,
      injectParams: {
        selector: api.getSheetPartSelector(
          api.constants.SHEET_PARTS.NAME_CONTAINER
        ),
        position: "beforebegin",
      },
      onContentReady: (params) => {
        console.log("content ready to render", params);
        console.log("my content", params.content);
      },
      onRender: (params) => {
        params.element
          .querySelector(".my-custom-button")
          .addEventListener("click", () => alert("ðŸĪš"));
      },
    })
  );
});

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on July 2, 2024

Closing as completed.

from foundry-vtt-tidy-5e-sheets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google âĪïļ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.