aboutsummaryrefslogtreecommitdiff
path: root/amd/src
diff options
context:
space:
mode:
authorJean-Michel Vedrine <vedrine@vedrine.org>2018-02-02 16:53:59 +0100
committerJean-Michel Vedrine <vedrine@vedrine.org>2018-02-02 16:53:59 +0100
commit8ad4a477c15f928323da24aff4188bd7f0dca1d9 (patch)
tree0f0e488eaacefc304154d6e68e1e2a41cb148cb5 /amd/src
parentec3cabf60551be0c589b11fa5db8de302645988e (diff)
Ajax dynamic formula display
Diffstat (limited to 'amd/src')
-rw-r--r--amd/src/display.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/amd/src/display.js b/amd/src/display.js
new file mode 100644
index 0000000..e2131b7
--- /dev/null
+++ b/amd/src/display.js
@@ -0,0 +1,28 @@
+define(['jquery', 'core/config', 'core/notification'], function($, config, notification) {
+ return {
+ init: function() {
+ $(".algebra_answer").on('input paste keyup', null, null, function() {
+ // Convert answer id to valid javascript name.
+ var id = $(this).attr('id');
+ var display = id.replace(':', '_');
+ var varnames = $('#' + display + '_vars').html();
+ var currentanswer = $(this).val();
+ var params = {
+ vars: varnames,
+ expr: currentanswer,
+ sesskey: config.sesskey,
+ };
+ $.post(config.wwwroot + '/question/type/algebra/ajax.php', params, null, 'json')
+ .done(function(data) {
+ // Replace TeX form in page.
+ $('#' + display + '_display').html("<span class=\"filter_mathjaxloader_equation\">" + data +"</span>");
+ // MathJax update.
+ MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
+ })
+ .fail(function(jqXHR, status, error) {
+ notification.exception(error);
+ });
+ });
+ }
+ };
+}); \ No newline at end of file