MOBILE-3438 question: ddimageortext infinite elements not positioned
parent
294fbadf6f
commit
d58e8f3352
|
@ -133,10 +133,8 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
const dragNode = this.doc.cloneNewDragItem(i, dragItemNo);
|
const dragNode = this.doc.cloneNewDragItem(i, dragItemNo);
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (!this.readOnly) {
|
|
||||||
// Make the item draggable.
|
// Make the item draggable.
|
||||||
this.draggableForQuestion(dragNode, group, choice);
|
this.draggableForQuestion(dragNode, group, choice);
|
||||||
}
|
|
||||||
|
|
||||||
// If the draggable item needs to be created more than once, create the rest of copies.
|
// If the draggable item needs to be created more than once, create the rest of copies.
|
||||||
if (dragNode.classList.contains('infinite')) {
|
if (dragNode.classList.contains('infinite')) {
|
||||||
|
@ -146,9 +144,8 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
while (dragsToCreate > 0) {
|
while (dragsToCreate > 0) {
|
||||||
const newDragNode = this.doc.cloneNewDragItem(i, dragItemNo);
|
const newDragNode = this.doc.cloneNewDragItem(i, dragItemNo);
|
||||||
i++;
|
i++;
|
||||||
if (!this.readOnly) {
|
|
||||||
this.draggableForQuestion(newDragNode, group, choice);
|
this.draggableForQuestion(newDragNode, group, choice);
|
||||||
}
|
|
||||||
dragsToCreate--;
|
dragsToCreate--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,6 +333,7 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
drag.setAttribute('group', String(group));
|
drag.setAttribute('group', String(group));
|
||||||
drag.setAttribute('choice', String(choice));
|
drag.setAttribute('choice', String(choice));
|
||||||
|
|
||||||
|
if (!this.readOnly) {
|
||||||
// Listen to click events.
|
// Listen to click events.
|
||||||
drag.addEventListener('click', (e) => {
|
drag.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -348,6 +346,7 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called when a drop zone is clicked.
|
* Function called when a drop zone is clicked.
|
||||||
|
@ -391,14 +390,9 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
getUnplacedChoiceForDrop(choice: number, drop: HTMLElement): HTMLElement {
|
getUnplacedChoiceForDrop(choice: number, drop: HTMLElement): HTMLElement {
|
||||||
const dragItems = this.getChoicesForDrop(choice, drop);
|
const dragItems = this.getChoicesForDrop(choice, drop);
|
||||||
|
|
||||||
for (let x = 0; x < dragItems.length; x++) {
|
return dragItems.find((dragItem) => {
|
||||||
const dragItem = dragItems[x];
|
return (!dragItem.classList.contains('placed') && !dragItem.classList.contains('beingdragged'));
|
||||||
if (this.readOnly || (!dragItem.classList.contains('placed') && !dragItem.classList.contains('beingdragged'))) {
|
}) || null;
|
||||||
return dragItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -534,7 +528,7 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
if (originInputId && originInputId != targetInputId) {
|
if (originInputId && originInputId != targetInputId) {
|
||||||
// Remove it from the previous place.
|
// Remove it from the previous place.
|
||||||
const originInputNode = <HTMLInputElement> this.doc.topNode().querySelector('input#' + originInputId);
|
const originInputNode = <HTMLInputElement> this.doc.topNode().querySelector('input#' + originInputId);
|
||||||
originInputNode.setAttribute('value', '');
|
originInputNode.setAttribute('value', '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now position the draggable and set it to the input.
|
// Now position the draggable and set it to the input.
|
||||||
|
@ -543,7 +537,10 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
drag.style.top = position[1] - 1 + 'px';
|
drag.style.top = position[1] - 1 + 'px';
|
||||||
drag.classList.add('placed');
|
drag.classList.add('placed');
|
||||||
|
|
||||||
|
if (drag.getAttribute('choice')) {
|
||||||
inputNode.setAttribute('value', drag.getAttribute('choice'));
|
inputNode.setAttribute('value', drag.getAttribute('choice'));
|
||||||
|
}
|
||||||
|
|
||||||
drag.setAttribute('inputid', targetInputId);
|
drag.setAttribute('inputid', targetInputId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +576,7 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
const inputId = drag.getAttribute('inputid');
|
const inputId = drag.getAttribute('inputid');
|
||||||
if (inputId) {
|
if (inputId) {
|
||||||
const inputNode = <HTMLInputElement> this.doc.topNode().querySelector('input#' + inputId);
|
const inputNode = <HTMLInputElement> this.doc.topNode().querySelector('input#' + inputId);
|
||||||
inputNode.setAttribute('value', '');
|
inputNode.setAttribute('value', '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the element to its original position.
|
// Move the element to its original position.
|
||||||
|
@ -656,6 +653,7 @@ export class AddonQtypeDdImageOrTextQuestion {
|
||||||
|
|
||||||
if (choice > 0) {
|
if (choice > 0) {
|
||||||
const dragItem = this.getUnplacedChoiceForDrop(choice, dropZone);
|
const dragItem = this.getUnplacedChoiceForDrop(choice, dropZone);
|
||||||
|
|
||||||
if (dragItem !== null) {
|
if (dragItem !== null) {
|
||||||
this.placeDragInDrop(dragItem, dropZone);
|
this.placeDragInDrop(dragItem, dropZone);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue