From 530f153c1775b6dc6557c9396a863586457ea007 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 2 Jun 2022 10:27:31 +0200 Subject: [PATCH] Make sure we do have a valid element before constructing --- api/js/tapandswipe.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/js/tapandswipe.ts b/api/js/tapandswipe.ts index 63712e51b6..d0e133de9a 100644 --- a/api/js/tapandswipe.ts +++ b/api/js/tapandswipe.ts @@ -100,6 +100,9 @@ export class tapAndSwipe { { this.options = {...tapAndSwipe._default, ..._options}; const element = _element||_options.element; + // Dont construct if the element is not there + if (!element || !(typeof element != 'string' && element instanceof EventTarget)) return; + this.element = (element instanceof EventTarget) ? element : document.querySelector(element); this.element.addEventListener('touchstart', this._onTouchStart.bind(this), false); this.element.addEventListener('touchend', this._ontouchEnd.bind(this), false);