Skip to content

Commit 38b0071

Browse files
authored
Merge pull request #22 from processing/davepagurek-patch-1
Add p5.Element touch events
2 parents 9586bcf + 237e600 commit 38b0071

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/data.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ function addData(p5, fn){
88
fn.touchMoved = function (...args) {
99
return this.mouseDragged(...args);
1010
};
11+
p5.Element.prototype.touchStarted = function (cb) {
12+
return this.mousePressed(cb);
13+
};
14+
p5.Element.prototype.touchEnded = function (cb) {
15+
return this.mouseReleased(cb);
16+
};
17+
p5.Element.prototype.touchMoved = function (cb) {
18+
if (cb === false) {
19+
return this.mouseMoved(false);
20+
}
21+
return this.mouseMoved(function (event) {
22+
if ((event.buttons & 1) !== 0) {
23+
return cb(event);
24+
}
25+
});
26+
};
1127

1228
fn.append = function (array, value) {
1329
array.push(value);

0 commit comments

Comments
 (0)