|
259 | 259 | $(".droppable") |
260 | 260 | ); |
261 | 261 |
|
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(); |
277 | 265 | }); |
278 | 266 |
|
279 | 267 | /* ----------------------------- |
|
283 | 271 | * Triggers: jsPlumb.ready, window.load, BFCache pageshow. |
284 | 272 | * Also cleans up instances on pagehide. |
285 | 273 | */ |
286 | | - function initMatchingWithRetry(maxTries = 12, delay = 80) { |
| 274 | + function initMatchingWithRetry(maxTries = 40, delay = 100) { |
287 | 275 | let tries = 0; |
288 | 276 |
|
289 | 277 | function ready() { |
|
323 | 311 | try { MatchingDraggable.init(qid); } catch (e) {} |
324 | 312 | }); |
325 | 313 |
|
326 | | - // Final repaint in next tick (fonts/scroll may settle) |
| 314 | + // Extra repaints to cover slow layouts (tests tool, fonts, etc.) |
327 | 315 | setTimeout(repaintAllJsPlumbInstances, 0); |
| 316 | + setTimeout(repaintAllJsPlumbInstances, 300); |
| 317 | + setTimeout(repaintAllJsPlumbInstances, 800); |
328 | 318 | } |
329 | 319 |
|
330 | 320 | ready(); |
|
0 commit comments