@@ -3050,14 +3050,14 @@ class ParsonsInput {
30503050 this.parentElement = parentElement;
30513051 this.el.id = 'regextool-' + this.parentElement.toolNumber + '-parsons-input';
30523052 const dragTip = document.createElement('div');
3053- dragTip.innerText = 'Drag from the blocks below to form your code';
3053+ dragTip.innerText = 'Drag or click the blocks below to form your code: ';
30543054 dragTip.classList.add('hparsons-tip');
30553055 this.el.append(dragTip);
30563056 this._dragArea = document.createElement('div');
30573057 this.el.appendChild(this._dragArea);
30583058 this._dragArea.classList.add('drag-area');
30593059 const dropTip = document.createElement('div');
3060- dropTip.innerText = 'Your code:';
3060+ dropTip.innerText = 'Your code (click on a block to remove it) :';
30613061 dropTip.classList.add('hparsons-tip');
30623062 this.el.append(dropTip);
30633063 this._dropArea = document.createElement('div');
@@ -3133,30 +3133,49 @@ class ParsonsInput {
31333133 newBlock.style.display = 'inline-block';
31343134 newBlock.classList.add('parsons-block');
31353135 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- }
3136+ this._onBlockClicked(newBlock);
31563137 };
31573138 }
31583139 this._initSortable();
31593140 };
3141+ _onBlockClicked = (block) => {
3142+ if (block.parentElement == this._dragArea) {
3143+ let endPosition;
3144+ if (this.reusable) {
3145+ const blockCopy = block.cloneNode(true);
3146+ blockCopy.onclick = () => this._onBlockClicked(blockCopy);
3147+ this._dropArea.appendChild(blockCopy);
3148+ endPosition = this._getBlockPosition(blockCopy);
3149+ }
3150+ else {
3151+ this._dropArea.appendChild(block);
3152+ endPosition = this._getBlockPosition(block);
3153+ }
3154+ const inputEvent = {
3155+ 'event-type': 'parsons-input',
3156+ action: 'add',
3157+ position: [-1, endPosition],
3158+ answer: this._getTextArray(),
3159+ };
3160+ this.parentElement.logEvent(inputEvent);
3161+ }
3162+ else {
3163+ const startPosition = this._getBlockPosition(block);
3164+ if (this.reusable) {
3165+ this._dropArea.removeChild(block);
3166+ }
3167+ else {
3168+ this._dragArea.appendChild(block);
3169+ }
3170+ const inputEvent = {
3171+ 'event-type': 'parsons-input',
3172+ action: 'remove',
3173+ position: [startPosition, -1],
3174+ answer: this._getTextArray(),
3175+ };
3176+ this.parentElement.logEvent(inputEvent);
3177+ }
3178+ };
31603179 _initSortable = () => {
31613180 this._dragSortable.destroy();
31623181 this._dropSortable.destroy();
@@ -3171,6 +3190,10 @@ class ParsonsInput {
31713190 direction: 'horizontal',
31723191 animation: 150,
31733192 draggable: '.parsons-block',
3193+ onClone: (event) => {
3194+ const newBlock = event.clone;
3195+ newBlock.onclick = () => this._onBlockClicked(newBlock);
3196+ }
31743197 });
31753198 this._dropSortable = new Sortable(this._dropArea, {
31763199 group: 'shared',
0 commit comments