From 0b078e92f3283c5c0b3a08dec858ca447e36a1a8 Mon Sep 17 00:00:00 2001 From: Diya Solanki Date: Tue, 19 Nov 2024 00:10:18 +0530 Subject: [PATCH] Removed touchStarted/Ended --- src/core/main.js | 2 +- src/events/mouse.js | 19 +----- src/events/touch.js | 26 +------- test/unit/events/touch.js | 124 -------------------------------------- 4 files changed, 4 insertions(+), 167 deletions(-) diff --git a/src/core/main.js b/src/core/main.js index 0e2492a158..c0c9948e07 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -65,7 +65,7 @@ class p5 { pointerdown: null, pointerup: null, pointermove: null, - pointercancle:null, + pointercancel:null, dragend: null, dragover: null, click: null, diff --git a/src/events/mouse.js b/src/events/mouse.js index 58404fd79b..32feca2d9e 100644 --- a/src/events/mouse.js +++ b/src/events/mouse.js @@ -1071,12 +1071,7 @@ function mouse(p5, fn){ if (executeDefault === false) { e.preventDefault(); } - } else if (typeof context.touchMoved === 'function') { - executeDefault = context.touchMoved(e); - if (executeDefault === false) { - e.preventDefault(); - } - } + } } }; @@ -1237,12 +1232,7 @@ function mouse(p5, fn){ if (executeDefault === false) { e.preventDefault(); } - } else if (typeof context.touchStarted === 'function') { - executeDefault = context.touchStarted(e); - if (executeDefault === false) { - e.preventDefault(); - } - } + } }; /** @@ -1401,11 +1391,6 @@ function mouse(p5, fn){ if (executeDefault === false) { e.preventDefault(); } - } else if (typeof context.touchEnded === 'function') { - executeDefault = context.touchEnded(e); - if (executeDefault === false) { - e.preventDefault(); - } } }; diff --git a/src/events/touch.js b/src/events/touch.js index 9a9254a511..facc8b9f4d 100644 --- a/src/events/touch.js +++ b/src/events/touch.js @@ -275,20 +275,10 @@ function touch(p5, fn){ * */ fn._ontouchstart = function(e) { - const context = this._isGlobal ? window : this; - let executeDefault; this.mouseIsPressed = true; this._updateTouchCoords(e); this._updateNextMouseCoords(e); this._updateMouseCoords(); // reset pmouseXY at the start of each touch event - - if (typeof context.touchStarted === 'function') { - executeDefault = context.touchStarted(e); - if (executeDefault === false) { - e.preventDefault(); - } - this._touchstart = true; - } }; /** @@ -451,12 +441,7 @@ function touch(p5, fn){ let executeDefault; this._updateTouchCoords(e); this._updateNextMouseCoords(e); - if (typeof context.touchMoved === 'function') { - executeDefault = context.touchMoved(e); - if (executeDefault === false) { - e.preventDefault(); - } - } else if (typeof context.mouseDragged === 'function') { + if (typeof context.mouseDragged === 'function') { executeDefault = context.mouseDragged(e); if (executeDefault === false) { e.preventDefault(); @@ -622,15 +607,6 @@ function touch(p5, fn){ this.mouseIsPressed = false; this._updateTouchCoords(e); this._updateNextMouseCoords(e); - const context = this._isGlobal ? window : this; - let executeDefault; - if (typeof context.touchEnded === 'function') { - executeDefault = context.touchEnded(e); - if (executeDefault === false) { - e.preventDefault(); - } - this._touchend = true; - } }; } diff --git a/test/unit/events/touch.js b/test/unit/events/touch.js index 72d3dd20c6..d7d5f12b9b 100644 --- a/test/unit/events/touch.js +++ b/test/unit/events/touch.js @@ -56,128 +56,4 @@ suite('Touch Events', function() { assert.strictEqual(myp5.touches[0].id, 35); }); }); - - suite('touchStarted', function() { - test('touchStarted should be fired when a touch is registered', function() { - let count = 0; - myp5.touchStarted = function() { - count += 1; - }; - window.dispatchEvent(new TouchEvent('touchstart')); - assert.strictEqual(count, 1); - }); - - test('should be fired when a touch starts over the element', function() { - let count = 0; - let div = myp5.createDiv(); - let divTouchStarted = function() { - count += 1; - }; - div.touchStarted(divTouchStarted); - div.elt.dispatchEvent(new TouchEvent('touchstart')); - assert.strictEqual(count, 1); - }); - - // NOTE: Required review of parallel sketches test method - test('touchStarted functions on multiple instances must run once', async function() { - let sketchFn = function(sketch, resolve, reject) { - let count = 0; - sketch.touchStarted = function() { - count += 1; - }; - - sketch.finish = function() { - resolve(count); - }; - }; - let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches - await sketches.setup; //wait for all sketches to setup - window.dispatchEvent(new TouchEvent('touchstart')); - sketches.end(); //resolve all sketches by calling their finish functions - let counts = await sketches.result; - assert.deepEqual(counts, [1, 1]); - }); - }); - - suite('touchMoved', function() { - test('touchMoved should be fired when a touchmove is registered', function() { - let count = 0; - myp5.touchMoved = function() { - count += 1; - }; - window.dispatchEvent(touchEvent2); - assert.strictEqual(count, 1); - }); - - test('should be fired when a touchmove is registered over the element', function() { - let count = 0; - let div = myp5.createDiv(); - let divTouchMoved = function() { - count += 1; - }; - div.touchMoved(divTouchMoved); - div.elt.dispatchEvent(touchEvent2); - assert.strictEqual(count, 1); - }); - - test('touchMoved functions on multiple instances must run once', async function() { - let sketchFn = function(sketch, resolve, reject) { - let count = 0; - sketch.touchMoved = function() { - count += 1; - }; - - sketch.finish = function() { - resolve(count); - }; - }; - let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches - await sketches.setup; //wait for all sketches to setup - window.dispatchEvent(touchEvent2); - sketches.end(); //resolve all sketches by calling their finish functions - let counts = await sketches.result; - assert.deepEqual(counts, [1, 1]); - }); - }); - - suite('touchEnded', function() { - test('touchEnded must run when a touch is registered', function() { - let count = 0; - myp5.touchEnded = function() { - count += 1; - }; - window.dispatchEvent(new TouchEvent('touchend')); - assert.strictEqual(count, 1); - }); - - test('should be fired when a touch starts over the element', function() { - let count = 0; - let div = myp5.createDiv(); - let divTouchEnded = function() { - count += 1; - }; - div.touchEnded(divTouchEnded); - div.elt.dispatchEvent(new TouchEvent('touchend')); - assert.strictEqual(count, 1); - }); - - test('touchEnded functions on multiple instances must run once', async function() { - let sketchFn = function(sketch, resolve, reject) { - let count = 0; - sketch.touchEnded = function() { - count += 1; - }; - - sketch.finish = function() { - resolve(count); - }; - }; - let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches - await sketches.setup; //wait for all sketches to setup - window.dispatchEvent(new TouchEvent('touchend')); - sketches.end(); //resolve all sketches by calling their finish functions - let counts = await sketches.result; - assert.deepEqual(counts, [1, 1]); - }); - }); });