1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Comments & Pointer: Converted components to typescript

Made changes for dom and translation services for easier usage
considering types.
trans_choice updated to allow default count replacement data as per
Laravel's default behaviour.
This commit is contained in:
Dan Brown
2025-04-18 20:42:56 +01:00
parent 8d159f77e4
commit add238fe9f
4 changed files with 98 additions and 46 deletions

View File

@ -44,9 +44,11 @@ export function forEach(selector: string, callback: (el: Element) => any) {
/**
* Helper to listen to multiple DOM events
*/
export function onEvents(listenerElement: Element, events: string[], callback: (e: Event) => any): void {
for (const eventName of events) {
listenerElement.addEventListener(eventName, callback);
export function onEvents(listenerElement: Element|null, events: string[], callback: (e: Event) => any): void {
if (listenerElement) {
for (const eventName of events) {
listenerElement.addEventListener(eventName, callback);
}
}
}

View File

@ -10,6 +10,7 @@ export class Translator {
* to use. Similar format at Laravel's 'trans_choice' helper.
*/
choice(translation: string, count: number, replacements: Record<string, string> = {}): string {
replacements = Object.assign({}, replacements, {count: String(count)});
const splitText = translation.split('|');
const exactCountRegex = /^{([0-9]+)}/;
const rangeRegex = /^\[([0-9]+),([0-9*]+)]/;