]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/dom.ts
Comments & Pointer: Converted components to typescript
[bookstack] / resources / js / services / dom.ts
index 779b4854773ba2bc1b47be2bca6bec658c2a05e1..537af816a907ad6e7a98ed4c1643fdc91ce40f8f 100644 (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);
+        }
     }
 }