Skip to content

Commit 989ae32

Browse files
committed
fix(mathjax): stop refreshMath binding on formula equation inputs
1 parent ea22077 commit 989ae32

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

xblocks_contrib/problem/assets/spec/display_spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ data-url='/problem/quiz/'> \
9191
it("bind the math input", function () {
9292
expect($("input.math")).toHandleWith("keyup", this.problem.refreshMath);
9393
});
94+
95+
it("does not bind refreshMath to formula equation inputs", function () {
96+
// Formula-equation inputs are exclusively managed by formula_equation_preview.js.
97+
$.ajax.and.callFake(function (settings) {
98+
if (settings.url.match(/.+\/problem_get$/)) {
99+
settings.success({
100+
html: readFixtures("problem_content.html") +
101+
'<section class="formulaequationinput"><input type="text" id="input_formula_1" />' +
102+
'<div id="input_formula_1_preview" class="equation"></div></section>',
103+
});
104+
}
105+
});
106+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
107+
MathJax.typesetClear.calls.reset();
108+
$(".formulaequationinput input").trigger("keyup");
109+
expect(MathJax.typesetClear).not.toHaveBeenCalled();
110+
});
94111
});
95112

96113
describe("bind_with_custom_input_id", function () {

xblocks_contrib/problem/assets/static/js/display.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ Problem.prototype.bind = function () {
119119
this.submitAnswersAndSubmitButton(true);
120120
}
121121
Collapsible.setCollapsibles(this.el);
122-
this.$("input.math, .formulaequationinput input").keyup(this.refreshMath);
122+
// Formula equation inputs use formula_equation_preview.js to manage their server-rendered preview.
123+
this.$("input.math").keyup(this.refreshMath);
123124
if (isMathJaxTypesetReady()) {
124-
this.$("input.math, .formulaequationinput input").each(function (index, element) {
125+
this.$("input.math").each(function (index, element) {
125126
return MathJax.startup.promise.then(() => that.refreshMath(null, element));
126127
});
127128
}

0 commit comments

Comments
 (0)