Make sure we do have a valid element before constructing

This commit is contained in:
Hadi Nategh 2022-06-02 10:27:31 +02:00
parent 4b9e733b94
commit 530f153c17

View File

@ -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);