Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 97e8ddb

Browse files
committed
✨ Allow click to add to a new block
1 parent 22492d2 commit 97e8ddb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

runestone/hparsons/js/horizontal-parsons.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,28 @@ class ParsonsInput {
31323132
}
31333133
newBlock.style.display = 'inline-block';
31343134
newBlock.classList.add('parsons-block');
3135+
newBlock.onclick = () => {
3136+
// adding the block to the input area
3137+
if (newBlock.parentElement == this._dragArea) {
3138+
let endPosition;
3139+
if (this.reusable) {
3140+
const newBlockCopy = newBlock.cloneNode(true);
3141+
this._dropArea.appendChild(newBlockCopy);
3142+
endPosition = this._getBlockPosition(newBlockCopy);
3143+
}
3144+
else {
3145+
this._dropArea.appendChild(newBlock);
3146+
endPosition = this._getBlockPosition(newBlock);
3147+
}
3148+
const inputEvent = {
3149+
'event-type': 'parsons-input',
3150+
action: 'add',
3151+
position: [-1, endPosition],
3152+
answer: this._getTextArray(),
3153+
};
3154+
this.parentElement.logEvent(inputEvent);
3155+
}
3156+
};
31353157
}
31363158
this._initSortable();
31373159
};
@@ -3311,6 +3333,7 @@ class ParsonsInput {
33113333
}
33123334
}
33133335
};
3336+
// TODO: not used for now, not sure if is working correctly
33143337
restoreAnswer(type, answer) {
33153338
if (type != 'parsons' || !Array.isArray(answer)) {
33163339
return;

0 commit comments

Comments
 (0)