mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Fix broken event handlers in sketchpad; change Array.from()
This commit is contained in:
parent
a7eacb1e7c
commit
4b080ca4c5
5
.changeset/poor-singers-destroy.md
Normal file
5
.changeset/poor-singers-destroy.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@jspsych/plugin-sketchpad": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed broken event handlers in the sketchpad plugin.
|
@ -409,11 +409,11 @@ class SketchpadPlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sketchpad.addEventListener("pointerdown", this.start_draw);
|
this.sketchpad.addEventListener("pointerdown", this.start_draw.bind(this));
|
||||||
this.sketchpad.addEventListener("pointermove", this.move_draw);
|
this.sketchpad.addEventListener("pointermove", this.move_draw.bind(this));
|
||||||
this.sketchpad.addEventListener("pointerup", this.end_draw);
|
this.sketchpad.addEventListener("pointerup", this.end_draw.bind(this));
|
||||||
this.sketchpad.addEventListener("pointerleave", this.end_draw);
|
this.sketchpad.addEventListener("pointerleave", this.end_draw.bind(this));
|
||||||
this.sketchpad.addEventListener("pointercancel", this.end_draw);
|
this.sketchpad.addEventListener("pointercancel", this.end_draw.bind(this));
|
||||||
|
|
||||||
if (this.params.key_to_draw !== null) {
|
if (this.params.key_to_draw !== null) {
|
||||||
document.addEventListener("keydown", (e) => {
|
document.addEventListener("keydown", (e) => {
|
||||||
@ -452,16 +452,22 @@ class SketchpadPlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.params.show_undo_button) {
|
if (this.params.show_undo_button) {
|
||||||
this.display.querySelector("#sketchpad-undo").addEventListener("click", this.undo);
|
this.display.querySelector("#sketchpad-undo").addEventListener("click", this.undo.bind(this));
|
||||||
if (this.params.show_redo_button) {
|
if (this.params.show_redo_button) {
|
||||||
this.display.querySelector("#sketchpad-redo").addEventListener("click", this.redo);
|
this.display
|
||||||
|
.querySelector("#sketchpad-redo")
|
||||||
|
.addEventListener("click", this.redo.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.params.show_clear_button) {
|
if (this.params.show_clear_button) {
|
||||||
this.display.querySelector("#sketchpad-clear").addEventListener("click", this.clear);
|
this.display
|
||||||
|
.querySelector("#sketchpad-clear")
|
||||||
|
.addEventListener("click", this.clear.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
const color_btns = Array.from(this.display.querySelectorAll(".sketchpad-color-select"));
|
const color_btns = Array.prototype.slice.call(
|
||||||
|
this.display.querySelectorAll(".sketchpad-color-select")
|
||||||
|
);
|
||||||
for (const btn of color_btns) {
|
for (const btn of color_btns) {
|
||||||
btn.addEventListener("click", (e) => {
|
btn.addEventListener("click", (e) => {
|
||||||
const target = e.target as HTMLButtonElement;
|
const target = e.target as HTMLButtonElement;
|
||||||
|
Loading…
Reference in New Issue
Block a user