Fix removal of outdated hint messages.

parent 6162dccc
...@@ -21,8 +21,18 @@ ...@@ -21,8 +21,18 @@
var parts = tex.split('\n'); var parts = tex.split('\n');
var math_container = $('#math'), var math_container = $('#math'),
math_lines = math_container.find('div.box script'), math_lines = math_container.find('div.box script');
mathjax_instances = MathJax.Hub.getAllJax('math');
// Select all mathjax instances which are inside a div.box element
var mathjax_instances = [];
var all_instances = MathJax.Hub.getAllJax('math');
for (var i = 0; i < all_instances.length; i++) {
var elem = all_instances[i];
if ($('#' + elem.inputID).parent().hasClass('box'))
mathjax_instances.push(elem);
}
var real_lines = 0, var real_lines = 0,
updated_line = -1; updated_line = -1;
...@@ -31,9 +41,8 @@ ...@@ -31,9 +41,8 @@
if (!parts[p]) if (!parts[p])
continue; continue;
// TODO: Mark updated line as "pending" (e.g. remove "wrong" // Check if we want to update an existing line or append the
// and "good" class names from element). // line.
if (real_lines < math_lines.length) { if (real_lines < math_lines.length) {
var elem = mathjax_instances[real_lines]; var elem = mathjax_instances[real_lines];
...@@ -62,32 +71,33 @@ ...@@ -62,32 +71,33 @@
real_lines++; real_lines++;
} }
QUEUE.Push(function() {
// Remove out-dated mathematical lines.
for (var p = real_lines; p < math_lines.length; p++)
$(math_lines[p].parentNode).remove();
// Remove old hints, given that at least one line is updated. // Remove old hints, given that at least one line is updated.
// Iterate over the DOM nodes until the updated line is found, // Iterate over the DOM nodes until the updated line is found,
// and remove all following hint nodes. // and remove all following hint nodes. Note that if there is
var line_count = 0, i = 0, elems = $('#math div'); // no line updated, all hints not directly following the last
// line are removed.
var elems = $('#math div');
if(updated_line == -1) if(updated_line == -1)
updated_line = real_lines + 1; updated_line = real_lines;
for(; i < elems.length; i++) { for(var i = 0, lines = 0, hints = 0; i < elems.length; i++) {
var elem = $(elems[i]); var elem = $(elems[i]);
if (line_count == updated_line) { if (lines > updated_line || hints >= updated_line) {
if (elem.hasClass('hint')) if (elem.hasClass('hint'))
elem.remove(); elem.remove();
} else if (elem.hasClass('box')) { } else if (elem.hasClass('hint'))
line_count++; hints++;
} else if (elem.hasClass('box'))
} lines++;
QUEUE.Push((function(math_lines, real_lines) {
return function() {
for (var p = real_lines; p < math_lines.length; p++) {
$(math_lines[p].parentNode).remove();
} }
}; });
})(math_lines, real_lines));
} }
window.update_math = function() { window.update_math = function() {
...@@ -190,8 +200,6 @@ ...@@ -190,8 +200,6 @@
if (!response) if (!response)
return; return;
console.log(response);
if ('step' in response) { if ('step' in response) {
window.append_input(response.step); window.append_input(response.step);
trigger_update = true; trigger_update = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment