Commit db8639e0 by Victor Shnayder

Fix preview code

- I'm starting to vaguely understand js variable scope and closures.  Long way to go though :)
parent 48de4b40
(function () { (function () {
update = function(index, input) { update = function() {
preview_div = $(input).siblings('div.equation'); preview_div = $(this).siblings('div.equation');
$.get("/preview/chemcalc/", {"formula" : input.value}, function(response) { function create_handler(saved_div) {
if (response.error) { return (function(response) {
preview_div.html("<span class='error'>" + response.error + "</span>"); if (response.error) {
} else { saved_div.html("<span class='error'>" + response.error + "</span>");
preview_div.html(response.preview); } else {
} saved_div.html(response.preview);
}); }
});
}
$.get("/preview/chemcalc/", {"formula" : this.value}, create_handler(preview_div));
} }
inputs = $('.chemicalequationinput input'); inputs = $('.chemicalequationinput input');
// update on load // update on load
inputs.each(update); inputs.each(update);
// and on every change // and on every change
inputs.bind("input", function(event) { inputs.bind("input", update);
// pass a dummy index
update(0, event.target);
});
}).call(this); }).call(this);
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