Skip to content

Commit 5be6045

Browse files
Merge pull request #7077 from christianbeeznest/GH-6307
Exercise: Fix drag-matching bullets layout in tests tool - refs #6307
2 parents a00bb3d + 44f2d5a commit 5be6045

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

public/main/template/default/exercise/submit.js.html.twig

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,9 @@
259259
$(".droppable")
260260
);
261261
262-
// Auto-detect matching questions and init jsPlumb per question (early init)
263-
(function autoInitMatching() {
264-
// We infer question ids from classes like 'window{qid}_question'
265-
var qids = {};
266-
$('[class]').each(function () {
267-
var classes = (this.className || '').toString().split(/\s+/);
268-
classes.forEach(function (c) {
269-
var m = c.match(/^window(\d+)_question$/);
270-
if (m) { qids[m[1]] = true; }
271-
});
272-
});
273-
Object.keys(qids).forEach(function (qid) {
274-
MatchingDraggable.init(qid);
275-
});
276-
})();
262+
// Use the layout-aware initializer so endpoints are placed
263+
// only when the question area has its final size.
264+
initMatchingWithRetry();
277265
});
278266
279267
/* -----------------------------
@@ -283,7 +271,7 @@
283271
* Triggers: jsPlumb.ready, window.load, BFCache pageshow.
284272
* Also cleans up instances on pagehide.
285273
*/
286-
function initMatchingWithRetry(maxTries = 12, delay = 80) {
274+
function initMatchingWithRetry(maxTries = 40, delay = 100) {
287275
let tries = 0;
288276
289277
function ready() {
@@ -323,8 +311,10 @@
323311
try { MatchingDraggable.init(qid); } catch (e) {}
324312
});
325313
326-
// Final repaint in next tick (fonts/scroll may settle)
314+
// Extra repaints to cover slow layouts (tests tool, fonts, etc.)
327315
setTimeout(repaintAllJsPlumbInstances, 0);
316+
setTimeout(repaintAllJsPlumbInstances, 300);
317+
setTimeout(repaintAllJsPlumbInstances, 800);
328318
}
329319
330320
ready();

0 commit comments

Comments
 (0)