From 44f2d5ab09802f5a4e3ac195211a40648e405f6b Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Tue, 18 Nov 2025 20:02:09 -0500 Subject: [PATCH] Exercise: Fix drag-matching bullets layout in tests tool - refs #6307 --- .../default/exercise/submit.js.html.twig | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/public/main/template/default/exercise/submit.js.html.twig b/public/main/template/default/exercise/submit.js.html.twig index 4346d024b0a..a446c9b8b34 100644 --- a/public/main/template/default/exercise/submit.js.html.twig +++ b/public/main/template/default/exercise/submit.js.html.twig @@ -259,21 +259,9 @@ $(".droppable") ); - // Auto-detect matching questions and init jsPlumb per question (early init) - (function autoInitMatching() { - // We infer question ids from classes like 'window{qid}_question' - var qids = {}; - $('[class]').each(function () { - var classes = (this.className || '').toString().split(/\s+/); - classes.forEach(function (c) { - var m = c.match(/^window(\d+)_question$/); - if (m) { qids[m[1]] = true; } - }); - }); - Object.keys(qids).forEach(function (qid) { - MatchingDraggable.init(qid); - }); - })(); + // Use the layout-aware initializer so endpoints are placed + // only when the question area has its final size. + initMatchingWithRetry(); }); /* ----------------------------- @@ -283,7 +271,7 @@ * Triggers: jsPlumb.ready, window.load, BFCache pageshow. * Also cleans up instances on pagehide. */ - function initMatchingWithRetry(maxTries = 12, delay = 80) { + function initMatchingWithRetry(maxTries = 40, delay = 100) { let tries = 0; function ready() { @@ -323,8 +311,10 @@ try { MatchingDraggable.init(qid); } catch (e) {} }); - // Final repaint in next tick (fonts/scroll may settle) + // Extra repaints to cover slow layouts (tests tool, fonts, etc.) setTimeout(repaintAllJsPlumbInstances, 0); + setTimeout(repaintAllJsPlumbInstances, 300); + setTimeout(repaintAllJsPlumbInstances, 800); } ready();