Skip to content

Commit 57cc0a2

Browse files
authored
Merge pull request #4398 from dpalou/MOBILE-4648
MOBILE-4648 qtype: Retrieve drop zone info from data-set attribute
2 parents 5b18cbf + 77412ec commit 57cc0a2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/addons/qtype/ddimageortext/component/ddimageortext.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { AddonModQuizQuestionBasicData, CoreQuestionBaseComponent } from '@featu
1818
import { CoreQuestionHelper } from '@features/question/services/question-helper';
1919
import { AddonQtypeDdImageOrTextQuestion } from '../classes/ddimageortext';
2020
import { CoreSharedModule } from '@/core/shared.module';
21+
import { CoreText } from '@singletons/text';
2122

2223
/**
2324
* Component to render a drag-and-drop onto image question.
@@ -88,8 +89,14 @@ export class AddonQtypeDdImageOrTextComponent
8889
if (this.question.amdArgs[1] !== undefined) {
8990
this.question.readOnly = !!this.question.amdArgs[1];
9091
}
91-
if (this.question.amdArgs[2] !== undefined) {
92-
this.drops = <unknown[]> this.question.amdArgs[2];
92+
93+
// Try to get drop info from data attribute (Moodle 5.1+). If not found, fallback to old way of retrieving it.
94+
const dropZones = ddArea.querySelector<HTMLElement>('.dropzones');
95+
const placeInfo = dropZones?.dataset.placeInfo ?
96+
CoreText.parseJSON(dropZones.dataset.placeInfo, null) :
97+
this.question.amdArgs[2];
98+
if (placeInfo) {
99+
this.drops = <unknown[]> placeInfo;
93100
}
94101
}
95102

src/addons/qtype/ddmarker/component/ddmarker.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { CoreSites } from '@services/sites';
2121
import { AddonQtypeDdMarkerQuestion } from '../classes/ddmarker';
2222
import { CoreSharedModule } from '@/core/shared.module';
2323
import { CoreWait } from '@singletons/wait';
24+
import { CoreText } from '@singletons/text';
2425

2526
/**
2627
* Component to render a drag-and-drop markers question.
@@ -111,8 +112,14 @@ export class AddonQtypeDdMarkerComponent
111112
}
112113
nextIndex++;
113114

114-
if (this.question.amdArgs[nextIndex] !== undefined) {
115-
this.dropZones = <unknown[]> this.question.amdArgs[nextIndex];
115+
// Try to get drop zones from data attribute (Moodle 5.1+). If not found, fallback to old way of retrieving it.
116+
const dropZones = ddArea.querySelector<HTMLElement>('.dropzones');
117+
const visibleDropZones = dropZones?.dataset.visibledDropzones ?
118+
CoreText.parseJSON(dropZones.dataset.visibledDropzones, null) :
119+
this.question.amdArgs[nextIndex];
120+
121+
if (visibleDropZones) {
122+
this.dropZones = <unknown[]> visibleDropZones;
116123
}
117124
}
118125

0 commit comments

Comments
 (0)