From 84229ec8c8b96a5ced411ff45f9865811797c3b9 Mon Sep 17 00:00:00 2001 From: Fanyo Siliadin Date: Thu, 13 Jun 2019 17:22:19 +0200 Subject: [PATCH 1/2] update deprecated clickEvent.initMouseEvent to MouseEvent constructor --- lib/fastclick.js | 15 +++++++++++++-- package-lock.json | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 package-lock.json diff --git a/lib/fastclick.js b/lib/fastclick.js index 225ff660..cf2f91f6 100644 --- a/lib/fastclick.js +++ b/lib/fastclick.js @@ -302,8 +302,19 @@ touch = event.changedTouches[0]; // Synthesise a click event, with an extra attribute so it can be tracked - clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); + clickEvent = new MouseEvent(this.determineEventType(targetElement), { + bubbles: true, + cancelable: true, + screenX: touch.screenX, + screenY: touch.screenY, + clientX: touch.clientX, + clientY: touch.clientY, + ctrlKey: false, + shiftKey: false, + altKey: false, + metaKey: false, + relatedTarget: null + }); clickEvent.forwardedTouchEvent = true; targetElement.dispatchEvent(clickEvent); }; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..5ed8e1dd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "fastclick", + "version": "1.0.6", + "lockfileVersion": 1 +} From 62f7e1b58ef68db74e51d92aad8aa2c92428d94b Mon Sep 17 00:00:00 2001 From: Fanyo Siliadin Date: Thu, 13 Jun 2019 17:34:50 +0200 Subject: [PATCH 2/2] allow event if targetElement does not exist in the DOM anymore --- lib/fastclick.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/fastclick.js b/lib/fastclick.js index cf2f91f6..6bca5fca 100644 --- a/lib/fastclick.js +++ b/lib/fastclick.js @@ -645,6 +645,12 @@ return true; } + // If the target element does not exist in the DOM anymore, + // this.targetElement does not refer to anything so we should allow the event since actual target is obviously different + if (!document.contains(this.targetElement)) { + return true; + } + if (event.forwardedTouchEvent) { return true; }