From 407415000fb52993695e88b87059195f0fdef7b3 Mon Sep 17 00:00:00 2001 From: Thorin-Oakenpants Date: Sat, 19 Oct 2024 19:32:18 +0000 Subject: [PATCH] handle undefined touches[0] --- tests/pointerevent.html | 49 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/tests/pointerevent.html b/tests/pointerevent.html index 8af359a7..79be741b 100644 --- a/tests/pointerevent.html +++ b/tests/pointerevent.html @@ -58,9 +58,7 @@
1: START
-

2: CLICK
-
MOUSE
middle or
context
-
TOUCH | PEN
tap + drag a bit
tap again
+

2: CLICK

context click
(if you can)

otherwise

keep stabbing
and moving
3: FINISH
@@ -126,11 +124,16 @@ altitudeAngle: "number", azimuthAngle: "number", } -// events we want to catch data on +// events let oDataEvents = { 'pointer': ['down','enter','leave','move','over','out','up'], 'touch': ['cancel','end','move','start'], } +let oNonDataEvents = { + 'mouse': ['down','enter','leave','move','out','over','up'], + 'pointer': ['cancel'], + //'touch': ['cancel'], +} function finish() { // check all events have been recorded @@ -172,6 +175,10 @@ try { let touch = event.touches[0] + // touchcancel + touchend don't have touch data + if (undefined == touch) { + touch = event.changedTouches[0] + } aList.forEach(function(k){ let value try { @@ -183,14 +190,7 @@ } oTemp[input][type][k] = value } catch(e) { - // touchcancel and touchend don't have values except for force - // so don't record them if we catch a TypeError - // this means we can now properly compare valid matches in screen/client X/Y - if (e.name == 'TypeError' && k !== 'force') { - // record nothing - } else { - oTemp[input][type][k] = e.name - } + oTemp[input][type][k] = e.name } }) @@ -205,13 +205,11 @@ // if all tests are the same value just display one value let aSet = new Set(), aArray = [] for (const p of Object.keys(oTemp[input]).sort()) { // sort so array is in order when needed - if (undefined !== oTemp[input][p][k]) { - let x = oTemp[input][p][k] - // force is variable - if ('force' == k) {if (!aStable.includes(x)) {x = 'float'}} - aSet.add(x) - aArray.push(x) - } + let x = oTemp[input][p][k] + // force is variable + if ('force' == k) {if ('number' == typeof x && !aStable.includes(x)) {x = 'float'}} + aSet.add(x) + aArray.push(x) } let fp = aArray if (1 == aSet.size) {aArray = Array.from(aSet); fp = aArray[0]} @@ -299,7 +297,7 @@ let x = oTemp[input][p][k] // active pen pressure is variable between 0-1 if ('pressure' == k || 'mozPressure' == k) { - if (!aStable.includes(x)) {x = 'float'} + if ('number' == typeof x && !aStable.includes(x)) {x = 'float'} } aSet.add(x) aArray.push(x) @@ -346,17 +344,14 @@ function start() { let target = dom.target - // just record the event happening - let oEvents = { - 'mouse': ['down','enter','leave','move','out','over','up'], - 'pointer': ['cancel'] - } - for (const k of Object.keys(oEvents)) { - let list = oEvents[k] + // record the event happening + for (const k of Object.keys(oNonDataEvents)) { + let list = oNonDataEvents[k] list.forEach(function(type){ target.addEventListener(k + type, (event) => {addEvent(k + type)}) }) } + // record data on these events for (const k of Object.keys(oDataEvents)) { let list = oDataEvents[k] dom[k +'events'].innerHTML = ' [' + list.join('|') +'] '