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:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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*]+)]/;
|
||||
|
Reference in New Issue
Block a user