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

Commit b230ffa

Browse files
committed
Go back to the old way of calculating height of blocks
1 parent 1033587 commit b230ffa

File tree

1 file changed

+12
-97
lines changed

1 file changed

+12
-97
lines changed

runestone/parsons/js/parsons.js

Lines changed: 12 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -463,103 +463,18 @@ export default class Parsons extends RunestoneBase {
463463
// item is a jQuery object
464464
// outerHeight can be unreliable if elements are not yet visible
465465
// outerHeight will return bad results if MathJax has not rendered the math
466-
if (
467-
this.options.language == "natural" ||
468-
this.options.language == "math" || true
469-
) {
470-
areaWidth = 300;
471-
maxFunction = async function(item) {
472-
if (this.options.language == "natural" || this.options.language == "math") {
473-
await this.queueMathJax(item[0])
474-
}
475-
areaWidth = Math.max(areaWidth, item.outerWidth(true));
476-
item.width(areaWidth - 22);
477-
var addition = 3.8;
478-
if (item.outerHeight(true) != 38)
479-
addition = (3.1 * (item.outerHeight(true) - 38)) / 21;
480-
areaHeight += item.outerHeight(true) + height_add * addition;
481-
}.bind(this);
482-
} else {
483-
areaWidth = 300;
484-
// This maxFunction is how Parsons areas width and height were being calculated previously,
485-
// but at some point .outerHeight and .outerWidth stopped returning correct values
486-
// causing lines to overflow and display awkwardly. - Vincent Qiu (September 2020)
487-
// maxFunction = function (item) {
488-
// var addition = 3.8;
489-
// if (item.outerHeight(true) != 38) addition = 2.1;
490-
// areaHeight += item.outerHeight(true) + height_add * addition;
491-
// areaWidth = Math.max(areaWidth, item.outerWidth(true));
492-
// };
493-
494-
// This new maxFunction is how Parsons areas width and height are being calculated now manually - Vincent Qiu (September 2020)
495-
maxFunction = function(item) {
496-
var addition = 3.8;
497-
498-
// Determine which index within the Parsons block JavaScript object contains the text lines and consequently the passed through data - Vincent Qiu (September 2020)
499-
var linesIndex;
500-
var linesItem = item[0].children;
501-
for (
502-
linesIndex = 0; linesIndex < item[0].children.length; linesIndex++
503-
) {
504-
if (
505-
item[0].children[linesIndex].className.includes("lines")
506-
) {
507-
break;
508-
}
509-
}
510-
511-
// Create a canvas and set the passed through fontSize and fontFamily in order to measure text width - Vincent Qiu (September 2020)
512-
var fontSize = linesItem[linesIndex].children[0].fontSize;
513-
var fontFamily = linesItem[linesIndex].children[0].fontFamily;
514-
var tempCanvas = document.createElement("canvas");
515-
var tempCanvasCtx = tempCanvas.getContext("2d");
516-
tempCanvasCtx.font = fontSize + " " + fontFamily;
517-
518-
// Increment Parsons area height based on number of lines of text in the current Parsons block - Vincent Qiu (September 2020)
519-
var singleHeight = 40;
520-
var additionalHeight = 20;
521-
areaHeight += Math.ceil(
522-
// For future more accurate height display, this calculation should also be conditionally based on fontFamily
523-
singleHeight +
524-
(linesItem[linesIndex].children.length - 1) *
525-
additionalHeight +
526-
height_add * addition
527-
);
528-
529-
// Determine the longest text line in the current Parsons block and calculate its width - Vincent Qiu (September 2020)
530-
var itemLength;
531-
var pixelsPerIndent;
532-
var indent;
533-
var maxInnerText;
534-
var maxInnerLength = 0;
535-
var i;
536-
var widthLimit = 475;
537-
var longCount = 0;
538-
for (i = 0; i < linesItem[linesIndex].children.length; i++) {
539-
pixelsPerIndent =
540-
linesItem[linesIndex].children[i].pixelsPerIndent;
541-
indent = linesItem[linesIndex].children[i].indent;
542-
itemLength = Math.ceil(
543-
pixelsPerIndent * indent +
544-
tempCanvasCtx.measureText(
545-
linesItem[linesIndex].children[i].innerText
546-
).width
547-
);
548-
longCount += Math.floor(itemLength / (widthLimit - 29));
549-
if (itemLength > maxInnerLength) {
550-
maxInnerText =
551-
linesItem[linesIndex].children[i].innerText;
552-
maxInnerLength = itemLength;
553-
}
554-
}
555-
areaWidth = Math.max(areaWidth, maxInnerLength + 40);
556-
// Set width limit and determine how much additional height is needed to accommodate the forced text overflow - Vincent Qiu (September 2020)
557-
if (areaWidth > widthLimit) {
558-
areaWidth = widthLimit;
559-
areaHeight += longCount * additionalHeight;
560-
}
561-
};
562-
}
466+
areaWidth = 300;
467+
maxFunction = async function(item) {
468+
if (this.options.language == "natural" || this.options.language == "math") {
469+
await this.queueMathJax(item[0])
470+
}
471+
areaWidth = Math.max(areaWidth, item.outerWidth(true));
472+
item.width(areaWidth - 22);
473+
var addition = 3.8;
474+
if (item.outerHeight(true) != 38)
475+
addition = (3.1 * (item.outerHeight(true) - 38)) / 21;
476+
areaHeight += item.outerHeight(true) + height_add * addition;
477+
}.bind(this);
563478
for (i = 0; i < blocks.length; i++) {
564479
await maxFunction($(blocks[i].view));
565480
}

0 commit comments

Comments
 (0)