From 2b17fb626b17b69b7485ecef6a0a00c0d9bad05d Mon Sep 17 00:00:00 2001 From: kimth Date: Sun, 9 Sep 2012 10:53:32 -0400 Subject: [PATCH 01/14] Translate between 6.002x subscript convention and standard Latex --- .../xmodule/xmodule/js/src/capa/display.coffee | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index e27b46d04e..51a7de1ba4 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -299,8 +299,24 @@ class @Problem target = "display_#{element.id.replace(/^input_/, '')}" if jax = MathJax.Hub.getAllJax(target)[0] - MathJax.Hub.Queue ['Text', jax, $(element).val()], + eqn = @latexify($(element).val()) + MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] + + latexify: (eqn) -> + ### + Translate 6.002x conventions for subscripts to standard Latex, e.g. + 'R3' --> 'R_{3}' + 'vGS' --> 'v_{GS}' + 'K/2*(vIN-VT)^2' --> 'K/2*(v_{IN}-V_{T})^2' + ### + subscript_replace = (match) -> + # Default keywords are taken from capa/calc.py + default_keywords = ['sin', 'cos', 'tan', 'sqrt', 'log10', 'log2', 'ln', 'arccos', 'arcsin', 'arctan', 'abs', 'pi'] + if match in default_keywords + return match + return match[0] + '_{' + match.substr(1) + '}' + return eqn.replace(/[A-Za-z]\w+/g, subscript_replace) updateMathML: (jax, element) => try From 4881d54a49150c3a90fd53a0fae9323955fa5d7f Mon Sep 17 00:00:00 2001 From: kimth Date: Sun, 9 Sep 2012 13:12:51 -0400 Subject: [PATCH 02/14] Need to escape keywords such as 'in' from MathJax --- .../xmodule/js/src/capa/display.coffee | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 51a7de1ba4..e57a0e78bc 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -299,24 +299,40 @@ class @Problem target = "display_#{element.id.replace(/^input_/, '')}" if jax = MathJax.Hub.getAllJax(target)[0] - eqn = @latexify($(element).val()) + eqn = @mathjax_preprocessor($(element).val()) + #eqn = $(element).val() MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] - latexify: (eqn) -> + mathjax_preprocessor: (eqn) -> ### Translate 6.002x conventions for subscripts to standard Latex, e.g. 'R3' --> 'R_{3}' 'vGS' --> 'v_{GS}' 'K/2*(vIN-VT)^2' --> 'K/2*(v_{IN}-V_{T})^2' ### - subscript_replace = (match) -> - # Default keywords are taken from capa/calc.py - default_keywords = ['sin', 'cos', 'tan', 'sqrt', 'log10', 'log2', 'ln', 'arccos', 'arcsin', 'arctan', 'abs', 'pi'] - if match in default_keywords + + # Default keywords are taken from capa/calc.py + default_keywords = ['sin', 'cos', 'tan', 'sqrt', 'log10', 'log2', 'ln', 'arccos', 'arcsin', 'arctan', 'abs', 'pi'] + + # Escape keywords are strings that have special meaning in 6.002x that should not be processed by Jax + escape_keywords = ['in'] + + # First, perform subscript insertion + replace_subscript = (match) -> + if match in default_keywords or match in escape_keywords return match - return match[0] + '_{' + match.substr(1) + '}' - return eqn.replace(/[A-Za-z]\w+/g, subscript_replace) + else + return match[0] + '_{' + match.substr(1) + '}' + eqn = eqn.replace(/[A-Za-z]\w+/g, replace_subscript) + + # Second, escape 6.002x-specific keywords from MathJax + replace_escape_keyword = (match) -> + return '"' + match + '"' # Force MathJax plain text + for escape_keyword in escape_keywords + eqn = eqn.replace(escape_keyword, replace_escape_keyword) + + return eqn updateMathML: (jax, element) => try From f9c31f3f420255e9afbcaa2c4a5f07758c5adecb Mon Sep 17 00:00:00 2001 From: kimth Date: Sun, 9 Sep 2012 13:16:22 -0400 Subject: [PATCH 03/14] Add comments --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index e57a0e78bc..9fad72579d 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -310,6 +310,9 @@ class @Problem 'R3' --> 'R_{3}' 'vGS' --> 'v_{GS}' 'K/2*(vIN-VT)^2' --> 'K/2*(v_{IN}-V_{T})^2' + + ... and also escape specific 6.002x-related keywords from MathJax, + such as 'in' (parsed by MathJax as the set symbol) ### # Default keywords are taken from capa/calc.py @@ -318,7 +321,7 @@ class @Problem # Escape keywords are strings that have special meaning in 6.002x that should not be processed by Jax escape_keywords = ['in'] - # First, perform subscript insertion + # First, perform subscript insertion, but watch out for keywords replace_subscript = (match) -> if match in default_keywords or match in escape_keywords return match From eab11bca428cdc061de065eb27ff877c8400a7a0 Mon Sep 17 00:00:00 2001 From: kimth Date: Sun, 9 Sep 2012 14:04:52 -0400 Subject: [PATCH 04/14] Mathjax preprocessor is course-specific --- .../lib/xmodule/xmodule/js/src/capa/display.coffee | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 9fad72579d..63e04b8505 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -7,6 +7,11 @@ class @Problem @url = @el.data('url') @render() + # TODO: Each course should be able to customize the MathJax preprocessor + # through a generic plug-in + if (@id).search('6.002x') >= 0 + @mathjax_preprocessor = @mathjax_preprocessor_for_6002x + $: (selector) -> $(selector, @el) @@ -299,12 +304,15 @@ class @Problem target = "display_#{element.id.replace(/^input_/, '')}" if jax = MathJax.Hub.getAllJax(target)[0] - eqn = @mathjax_preprocessor($(element).val()) - #eqn = $(element).val() + eqn = $(element).val() + if @mathjax_preprocessor + eqn = @mathjax_preprocessor(eqn) + MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] - mathjax_preprocessor: (eqn) -> + # TODO: The 6.002x preprocessor should not be baked into capa/display.coffee, but should be a plug-in + mathjax_preprocessor_for_6002x: (eqn) -> ### Translate 6.002x conventions for subscripts to standard Latex, e.g. 'R3' --> 'R_{3}' From 48543ba3c2e5222f231b899ba3b6e05e347ab937 Mon Sep 17 00:00:00 2001 From: kimth Date: Sun, 9 Sep 2012 15:08:32 -0400 Subject: [PATCH 05/14] Match only exact excape keywords, e.g. in but not sin, arcsin --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 63e04b8505..3c1d972d11 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -341,7 +341,8 @@ class @Problem replace_escape_keyword = (match) -> return '"' + match + '"' # Force MathJax plain text for escape_keyword in escape_keywords - eqn = eqn.replace(escape_keyword, replace_escape_keyword) + escape_keyword_patt = RegExp('\\b'+escape_keyword+'\\b') + eqn = eqn.replace(escape_keyword_patt, replace_escape_keyword) return eqn From e6397665ab4d09cf53aa59660568ba02ac742bfb Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 14:12:01 -0400 Subject: [PATCH 06/14] MathJax preprocessor comes from external plugin --- common/lib/capa/capa/capa_problem.py | 2 +- .../capa/templates/textinput_dynamath.html | 6 +-- .../xmodule/js/src/capa/display.coffee | 48 +++---------------- 3 files changed, 10 insertions(+), 46 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index f386c9fe24..326cf92e86 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -382,10 +382,10 @@ class LoncapaProblem(object): original_path = sys.path for script in scripts: - sys.path = original_path + self._extract_system_path(script) stype = script.get('type') + if stype: if 'javascript' in stype: continue # skip javascript diff --git a/common/lib/capa/capa/templates/textinput_dynamath.html b/common/lib/capa/capa/templates/textinput_dynamath.html index 645153fd92..c6d0ac347f 100644 --- a/common/lib/capa/capa/templates/textinput_dynamath.html +++ b/common/lib/capa/capa/templates/textinput_dynamath.html @@ -1,7 +1,7 @@ ### -### version of textline.html which does dynammic math +### version of textline.html which does dynamic math ### -
+
% if state == 'unsubmitted':
% elif state == 'correct': @@ -20,7 +20,7 @@ style="display:none;" % endif /> - +

% if state == 'unsubmitted': unanswered diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 3c1d972d11..1c09ad2a13 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -7,11 +7,6 @@ class @Problem @url = @el.data('url') @render() - # TODO: Each course should be able to customize the MathJax preprocessor - # through a generic plug-in - if (@id).search('6.002x') >= 0 - @mathjax_preprocessor = @mathjax_preprocessor_for_6002x - $: (selector) -> $(selector, @el) @@ -305,47 +300,12 @@ class @Problem if jax = MathJax.Hub.getAllJax(target)[0] eqn = $(element).val() - if @mathjax_preprocessor - eqn = @mathjax_preprocessor(eqn) + if window.mathjax_preprocessor + eqn = window.mathjax_preprocessor(eqn) MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] - # TODO: The 6.002x preprocessor should not be baked into capa/display.coffee, but should be a plug-in - mathjax_preprocessor_for_6002x: (eqn) -> - ### - Translate 6.002x conventions for subscripts to standard Latex, e.g. - 'R3' --> 'R_{3}' - 'vGS' --> 'v_{GS}' - 'K/2*(vIN-VT)^2' --> 'K/2*(v_{IN}-V_{T})^2' - - ... and also escape specific 6.002x-related keywords from MathJax, - such as 'in' (parsed by MathJax as the set symbol) - ### - - # Default keywords are taken from capa/calc.py - default_keywords = ['sin', 'cos', 'tan', 'sqrt', 'log10', 'log2', 'ln', 'arccos', 'arcsin', 'arctan', 'abs', 'pi'] - - # Escape keywords are strings that have special meaning in 6.002x that should not be processed by Jax - escape_keywords = ['in'] - - # First, perform subscript insertion, but watch out for keywords - replace_subscript = (match) -> - if match in default_keywords or match in escape_keywords - return match - else - return match[0] + '_{' + match.substr(1) + '}' - eqn = eqn.replace(/[A-Za-z]\w+/g, replace_subscript) - - # Second, escape 6.002x-specific keywords from MathJax - replace_escape_keyword = (match) -> - return '"' + match + '"' # Force MathJax plain text - for escape_keyword in escape_keywords - escape_keyword_patt = RegExp('\\b'+escape_keyword+'\\b') - eqn = eqn.replace(escape_keyword_patt, replace_escape_keyword) - - return eqn - updateMathML: (jax, element) => try $("##{element.id}_dynamath").val(jax.root.toMathML '') @@ -361,6 +321,10 @@ class @Problem @answers = @inputs.serialize() inputtypeSetupMethods: + + textinputdynamath: (element) => + @mathjax_preprocessor = window.mathjax_preprocessor + javascriptinput: (element) => data = $(element).find(".javascriptinput_data") From 5862d04b65245388e3d2622631e3a45821d86ad2 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 15:16:40 -0400 Subject: [PATCH 07/14] Set up mathjax_preprocessor --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 1c09ad2a13..13701e659b 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -6,6 +6,7 @@ class @Problem @element_id = @el.attr('id') @url = @el.data('url') @render() + @mathjax_preprocessor = false $: (selector) -> $(selector, @el) @@ -300,12 +301,12 @@ class @Problem if jax = MathJax.Hub.getAllJax(target)[0] eqn = $(element).val() - if window.mathjax_preprocessor - eqn = window.mathjax_preprocessor(eqn) + if @mathjax_preprocessor + eqn = @mathjax_preprocessor(eqn) MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] - + updateMathML: (jax, element) => try $("##{element.id}_dynamath").val(jax.root.toMathML '') @@ -323,7 +324,7 @@ class @Problem inputtypeSetupMethods: textinputdynamath: (element) => - @mathjax_preprocessor = window.mathjax_preprocessor + @mathjax_preprocessor = window.mathjax_preprocessor javascriptinput: (element) => From 9931b5ae3f936dae08ad511b7c14be062dd4fd23 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 16:20:06 -0400 Subject: [PATCH 08/14] Mimic javascriptinput displayClass --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 13701e659b..43633bb713 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -324,7 +324,9 @@ class @Problem inputtypeSetupMethods: textinputdynamath: (element) => - @mathjax_preprocessor = window.mathjax_preprocessor + preprocessorClass = window['MathjaxPreprocessorFor6002x'] + preprocessor = new preprocessorClass() + alert preprocessor.fn javascriptinput: (element) => From 971fe53deced6a660de45b8e4a29e02e0a393b79 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 17:42:15 -0400 Subject: [PATCH 09/14] Another step towards Javascriptinput-style script loading --- .../capa/templates/textinput_dynamath.html | 41 ++++++++++--------- .../xmodule/js/src/capa/display.coffee | 19 ++++++--- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/common/lib/capa/capa/templates/textinput_dynamath.html b/common/lib/capa/capa/templates/textinput_dynamath.html index c6d0ac347f..be37af481c 100644 --- a/common/lib/capa/capa/templates/textinput_dynamath.html +++ b/common/lib/capa/capa/templates/textinput_dynamath.html @@ -2,6 +2,10 @@ ### version of textline.html which does dynamic math ###

+ +
+
+ % if state == 'unsubmitted':
% elif state == 'correct': @@ -15,27 +19,26 @@
% endif - -
-

- % if state == 'unsubmitted': - unanswered - % elif state == 'correct': - correct - % elif state == 'incorrect': - incorrect - % elif state == 'incomplete': - incomplete - % endif -

+ +

+ % if state == 'unsubmitted': + unanswered + % elif state == 'correct': + correct + % elif state == 'incorrect': + incorrect + % elif state == 'incomplete': + incomplete + % endif +

-

+

-
`{::}`
+
`{::}`
diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 43633bb713..a589179240 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -297,12 +297,17 @@ class @Problem refreshMath: (event, element) => element = event.target unless element - target = "display_#{element.id.replace(/^input_/, '')}" + elid = element.id.replace(/^input_/,'') + + target = "display_" + elid + + preprocessor_tag = "inputtype_" + elid + mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag] if jax = MathJax.Hub.getAllJax(target)[0] eqn = $(element).val() - if @mathjax_preprocessor - eqn = @mathjax_preprocessor(eqn) + if mathjax_preprocessor + eqn = mathjax_preprocessor(eqn) MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] @@ -324,9 +329,13 @@ class @Problem inputtypeSetupMethods: textinputdynamath: (element) => - preprocessorClass = window['MathjaxPreprocessorFor6002x'] + data = $(element).find('.textinputdynamath_data') + + preprocessorClassName = data.data('preprocessor') + preprocessorClass = window[preprocessorClassName] + preprocessor = new preprocessorClass() - alert preprocessor.fn + return preprocessor.fn javascriptinput: (element) => From bd72fbdfd8ee4783f15baff82bdf48e09dd8fad7 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 19:42:40 -0400 Subject: [PATCH 10/14] Allow textinputdynamath to specify its Mathjax preprocessor per-problem --- common/lib/capa/capa/inputtypes.py | 8 ++++++++ .../capa/capa/templates/textinput_dynamath.html | 6 ++++-- .../xmodule/xmodule/js/src/capa/display.coffee | 15 ++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index d9b864c5bc..187d2fd422 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -326,8 +326,16 @@ def textline_dynamath(element, value, status, render_template, msg=''): count = int(eid.split('_')[-2]) - 1 # HACK size = element.get('size') hidden = element.get('hidden', '') # if specified, then textline is hidden and id is stored in div of name given by hidden + + # Preprocessor to insert between raw input and Mathjax + preprocessor = {'class_name': element.get('preprocessorClassName',''), + 'script_src': element.get('preprocessorSrc','')} + if '' in preprocessor.values(): + preprocessor = None + context = {'id': eid, 'value': value, 'state': status, 'count': count, 'size': size, 'msg': msg, 'hidden': hidden, + 'preprocessor': preprocessor, } html = render_template("textinput_dynamath.html", context) return etree.XML(html) diff --git a/common/lib/capa/capa/templates/textinput_dynamath.html b/common/lib/capa/capa/templates/textinput_dynamath.html index be37af481c..856c29b3a0 100644 --- a/common/lib/capa/capa/templates/textinput_dynamath.html +++ b/common/lib/capa/capa/templates/textinput_dynamath.html @@ -3,8 +3,10 @@ ###
-
-
+ % if preprocessor is not None: +
+
+ % endif % if state == 'unsubmitted':
diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index a589179240..177a1e8806 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -6,7 +6,6 @@ class @Problem @element_id = @el.attr('id') @url = @el.data('url') @render() - @mathjax_preprocessor = false $: (selector) -> $(selector, @el) @@ -301,6 +300,7 @@ class @Problem target = "display_" + elid + # MathJax preprocessor is loaded by 'setupInputTypes' preprocessor_tag = "inputtype_" + elid mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag] @@ -308,7 +308,6 @@ class @Problem eqn = $(element).val() if mathjax_preprocessor eqn = mathjax_preprocessor(eqn) - MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] @@ -329,13 +328,19 @@ class @Problem inputtypeSetupMethods: textinputdynamath: (element) => + ### + Return: function (eqn) -> eqn that preprocesses the user formula input before + it is fed into MathJax. Return 'false' if no preprocessor specified + ### data = $(element).find('.textinputdynamath_data') preprocessorClassName = data.data('preprocessor') preprocessorClass = window[preprocessorClassName] - - preprocessor = new preprocessorClass() - return preprocessor.fn + if typeof(preprocessorClass) == 'undefined' + return false + else + preprocessor = new preprocessorClass() + return preprocessor.fn javascriptinput: (element) => From 474b5377b93e63e035938e4926883bb2c12b67c8 Mon Sep 17 00:00:00 2001 From: kimth Date: Tue, 11 Sep 2012 18:25:08 -0400 Subject: [PATCH 11/14] Consolidate class names --- common/lib/capa/capa/templates/textinput_dynamath.html | 4 ++-- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/capa/capa/templates/textinput_dynamath.html b/common/lib/capa/capa/templates/textinput_dynamath.html index 856c29b3a0..d1de22ef27 100644 --- a/common/lib/capa/capa/templates/textinput_dynamath.html +++ b/common/lib/capa/capa/templates/textinput_dynamath.html @@ -1,10 +1,10 @@ ### ### version of textline.html which does dynamic math ### -
+
% if preprocessor is not None: -
+
% endif diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 177a1e8806..7df98d4be0 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -327,12 +327,12 @@ class @Problem inputtypeSetupMethods: - textinputdynamath: (element) => + 'text-input-dynamath': (element) => ### Return: function (eqn) -> eqn that preprocesses the user formula input before it is fed into MathJax. Return 'false' if no preprocessor specified ### - data = $(element).find('.textinputdynamath_data') + data = $(element).find('.text-input-dynamath_data') preprocessorClassName = data.data('preprocessor') preprocessorClass = window[preprocessorClassName] From 2105755120b8068f25ed70768bda03554794f1c3 Mon Sep 17 00:00:00 2001 From: kimth Date: Wed, 12 Sep 2012 18:24:52 -0400 Subject: [PATCH 12/14] MathJax initial render needs to be properly queued --- .../lib/xmodule/xmodule/js/src/capa/display.coffee | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 7df98d4be0..54ffd4dafa 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -12,6 +12,7 @@ class @Problem bind: => MathJax.Hub.Queue ["Typeset", MathJax.Hub] + window.update_schematics() problem_prefix = @element_id.replace(/problem_/,'') @@ -23,7 +24,11 @@ class @Problem @$('section.action input.reset').click @reset @$('section.action input.show').click @show @$('section.action input.save').click @save - @$('input.math').keyup(@refreshMath).each(@refreshMath) + + # Dynamath + @$('input.math').keyup(@refreshMath) + @$('input.math').each (index, element) => + MathJax.Hub.Queue [@refreshMath, null, element] updateProgress: (response) => if response.progress_changed @@ -297,7 +302,6 @@ class @Problem refreshMath: (event, element) => element = event.target unless element elid = element.id.replace(/^input_/,'') - target = "display_" + elid # MathJax preprocessor is loaded by 'setupInputTypes' @@ -308,9 +312,10 @@ class @Problem eqn = $(element).val() if mathjax_preprocessor eqn = mathjax_preprocessor(eqn) - MathJax.Hub.Queue ['Text', jax, eqn], - [@updateMathML, jax, element] + MathJax.Hub.Queue(['Text', jax, eqn], [@updateMathML, jax, element]) + return # Explicit return for CoffeeScript + updateMathML: (jax, element) => try $("##{element.id}_dynamath").val(jax.root.toMathML '') From a55f37cd9dde8419c4dbfb786658923c6f9e0328 Mon Sep 17 00:00:00 2001 From: kimth Date: Thu, 13 Sep 2012 11:04:37 -0400 Subject: [PATCH 13/14] Problem js runs MathJax only over its own contents rather than full page --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 54ffd4dafa..c152c382ff 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -11,7 +11,8 @@ class @Problem $(selector, @el) bind: => - MathJax.Hub.Queue ["Typeset", MathJax.Hub] + @el.find('.problem > div').each (index, element) => + MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] window.update_schematics() @@ -267,7 +268,9 @@ class @Problem showMethod = @inputtypeShowAnswerMethods[cls] showMethod(inputtype, display, answers) if showMethod? - MathJax.Hub.Queue ["Typeset", MathJax.Hub] + @el.find('.problem > div').each (index, element) => + MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] + @$('.show').val 'Hide Answer' @el.addClass 'showed' @updateProgress response From d2d1ac71fe5510af61b788491aa0c31871388944 Mon Sep 17 00:00:00 2001 From: kimth Date: Thu, 13 Sep 2012 11:12:41 -0400 Subject: [PATCH 14/14] Use Coffeescript existential operator --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index c152c382ff..7376418dff 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -344,7 +344,7 @@ class @Problem preprocessorClassName = data.data('preprocessor') preprocessorClass = window[preprocessorClassName] - if typeof(preprocessorClass) == 'undefined' + if not preprocessorClass? return false else preprocessor = new preprocessorClass()