diff --git a/main.html b/main.html index 81326ee995..6cd23f8f68 100644 --- a/main.html +++ b/main.html @@ -9,6 +9,7 @@ + diff --git a/problem.html b/problem.html index cf8a6c633f..1004ebd597 100644 --- a/problem.html +++ b/problem.html @@ -2,35 +2,6 @@ ${ problem['html'] }
- % if check_button: % endif diff --git a/problem.js b/problem.js index 6132f4fb72..902d13c194 100644 --- a/problem.js +++ b/problem.js @@ -1,27 +1,37 @@ -$(function() { - $('#check_${ id }').click(function() { - var submit_data={}; - $.each($("[id^=input_${ id }_]"), function(index,value){ - submit_data[value.id]=value.value; - }); +function ${ id }_load() { + $('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }', + function() { + MathJax.Hub.Queue(["Typeset",MathJax.Hub]); - if($('#check_${ id }').attr('value') == 'Check') { - $.getJSON('/modx/problem/${ id }/problem_check', - submit_data, - function(json) { - for(p in json) { - if(json[p]=='correct') - $("#status_"+p).attr("class", "ui-icon ui-icon-check"); - if(json[p]=='incorrect') - $("#status_"+p).attr("class", "ui-icon ui-icon-close"); - $('#check_${ id }').attr("value", "Reset"); - } - }); - } else /* if 'Reset' */ { - // Possible cleanup: Move from getJSON to just load - $.getJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) { - $('#main_${ id }').html(json); - }); - } - }); + $('#check_${ id }').click(function() { + var submit_data={}; + $.each($("[id^=input_${ id }_]"), function(index,value){ + submit_data[value.id]=value.value; + }); + + if($('#check_${ id }').attr('value').substring(0,5) != 'Reset') { + $.getJSON('/modx/problem/${ id }/problem_check', + submit_data, + function(json) { + for(p in json) { + if(json[p]=='correct') + $("#status_"+p).attr("class", "ui-icon ui-icon-check"); + if(json[p]=='incorrect') + $("#status_"+p).attr("class", "ui-icon ui-icon-close"); + $('#check_${ id }').attr("value", "Reset"); + } + }); + } else /* if 'Reset' */ { + $.getJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) { + ${ id }_load(); + //$('#main_${ id }').html(json); + //MathJax.Hub.Queue(["Typeset",MathJax.Hub]); + }); + } + }); + }); +} + +$(function() { + ${ id }_load(); }); diff --git a/problem_ajax.html b/problem_ajax.html new file mode 100644 index 0000000000..fb8a98c765 --- /dev/null +++ b/problem_ajax.html @@ -0,0 +1 @@ +