Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit da90154

Browse files
committed
Speculative fix for parsons height problems
* Give a little extra space * Render mathjax before getting box height * use jQuery outerHeight for all languages * TODO: remove the else clause if this works in the wild
1 parent b986057 commit da90154

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

runestone/parsons/js/parsons.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export default class Parsons extends RunestoneBase {
395395
this.solution = solution;
396396
}
397397
// Based on the blocks, create the source and answer areas
398-
initializeAreas(sourceBlocks, answerBlocks, options) {
398+
async initializeAreas(sourceBlocks, answerBlocks, options) {
399399
// Create blocks property as the sum of the two
400400
var blocks = [];
401401
var i, block;
@@ -448,23 +448,29 @@ export default class Parsons extends RunestoneBase {
448448
var areaWidth, areaHeight;
449449
// Establish the width and height of the droppable areas
450450
var item, maxFunction;
451-
areaHeight = 6;
451+
areaHeight = 20;
452452
var height_add = 0;
453453
if (this.options.numbered != undefined) {
454454
height_add = 1;
455455
}
456+
// Warning -- all of this is just a bit of pixie dust discovered by trial
457+
// and error to try to get the height of the drag and drop boxes.
458+
// item is a jQuery object
459+
// outerHeight can be unreliable if elements are not yet visible
460+
// outerHeight will return bad results if MathJax has not rendered the math
456461
if (
457462
this.options.language == "natural" ||
458-
this.options.language == "math"
463+
this.options.language == "math" || true
459464
) {
460465
areaWidth = 300;
461-
maxFunction = function (item) {
466+
maxFunction = async function (item) {
467+
await this.queueMathJax(item[0])
462468
item.width(areaWidth - 22);
463469
var addition = 3.8;
464470
if (item.outerHeight(true) != 38)
465-
addition = (2.1 * (item.outerHeight(true) - 38)) / 21;
471+
addition = (3.1 * (item.outerHeight(true) - 38)) / 21;
466472
areaHeight += item.outerHeight(true) + height_add * addition;
467-
};
473+
}.bind(this);
468474
} else {
469475
areaWidth = 300;
470476
// This maxFunction is how Parsons areas width and height were being calculated previously,
@@ -549,7 +555,7 @@ export default class Parsons extends RunestoneBase {
549555
};
550556
}
551557
for (i = 0; i < blocks.length; i++) {
552-
maxFunction($(blocks[i].view));
558+
await maxFunction($(blocks[i].view));
553559
}
554560
this.areaWidth = areaWidth;
555561
if (this.options.numbered != undefined) {
@@ -684,7 +690,7 @@ export default class Parsons extends RunestoneBase {
684690
}
685691
}
686692
// Based on the data, load
687-
loadData(data) {
693+
async loadData(data) {
688694
var sourceHash = data.source;
689695
if (sourceHash == undefined) {
690696
// maintain backwards compatibility
@@ -712,7 +718,7 @@ export default class Parsons extends RunestoneBase {
712718
answerHash == undefined ||
713719
answerHash.length == 1
714720
) {
715-
this.initializeAreas(this.blocksFromSource(), [], options);
721+
await this.initializeAreas(this.blocksFromSource(), [], options);
716722
} else {
717723
this.initializeAreas(
718724
this.blocksFromHash(sourceHash),

0 commit comments

Comments
 (0)