ds4/src/hooks/render.ts

27 lines
985 B
TypeScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
// SPDX-FileCopyrightText: 2021 Gesina Schwalbe
//
// SPDX-License-Identifier: MIT
2021-03-16 08:22:27 +01:00
/**
* @remarks The render hooks of all classes in the class hierarchy are called, so e.g. for a {@link Dialog}, both the
* "renderDialog" hook and the "renderApplication" hook are called (in this order).
*/
2022-11-04 21:47:18 +01:00
export function registerForRenderHooks(): void {
2021-03-16 08:22:27 +01:00
["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hook) => {
Hooks.on(hook, selectTargetInputOnFocus);
});
}
/**
* Select the text of input elements in given application when focused via an on focus listener.
*
* @param app - The application in which to activate the listener.
* @param html - The {@link JQuery} representing the HTML of the application.
*/
function selectTargetInputOnFocus(app: Application, html: JQuery) {
html.find("input").on("focus", (ev: JQuery.FocusEvent<HTMLInputElement>) => {
ev.currentTarget.select();
});
2021-03-16 08:22:27 +01:00
}