Commit ab0cb29c by Piotr Mitros

Better/more AJAXy problem rendering

parent 1f609974
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script type="text/javascript" src="/static/lib/jquery-ui-1.8.16.custom.min.js"></script> <script type="text/javascript" src="/static/lib/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/static/lib//swfobject/swfobject.js"></script> <script type="text/javascript" src="/static/lib//swfobject/swfobject.js"></script>
<script type="text/javascript" src="/static/js/video_player.js"></script> <script type="text/javascript" src="/static/js/video_player.js"></script>
<script type="text/javascript" src="/static/js/schematic.js"></script>
<style type="text/css">#slider { margin: 10px; }</style> <style type="text/css">#slider { margin: 10px; }</style>
<!-- Warning: Do not upgrade FancyBox. V2.0 is under a non-free CC license --> <!-- Warning: Do not upgrade FancyBox. V2.0 is under a non-free CC license -->
<script type="text/javascript" src="/static/lib/fancybox/jquery.fancybox-1.3.4.js"></script> <script type="text/javascript" src="/static/lib/fancybox/jquery.fancybox-1.3.4.js"></script>
......
...@@ -2,35 +2,6 @@ ...@@ -2,35 +2,6 @@
${ problem['html'] } ${ problem['html'] }
<br> <br>
<input type="hidden" name="problem_id" value="${ problem['name'] }"> <input type="hidden" name="problem_id" value="${ problem['name'] }">
<script>$(function() {
$('#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' */ {
// Possible cleanup: Move from getJSON to just load
$.getJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) {
$('#main_${ id }').html(json);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
});
}
});
});
</script>
% if check_button: % if check_button:
<input id="check_${ id }" type="button" value="${ check_button }" > <input id="check_${ id }" type="button" value="${ check_button }" >
% endif % endif
$(function() { function ${ id }_load() {
$('#check_${ id }').click(function() { $('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }',
var submit_data={}; function() {
$.each($("[id^=input_${ id }_]"), function(index,value){ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
submit_data[value.id]=value.value;
}); $('#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') == 'Check') { if($('#check_${ id }').attr('value').substring(0,5) != 'Reset') {
$.getJSON('/modx/problem/${ id }/problem_check', $.getJSON('/modx/problem/${ id }/problem_check',
submit_data, submit_data,
function(json) { function(json) {
for(p in json) { for(p in json) {
if(json[p]=='correct') if(json[p]=='correct')
$("#status_"+p).attr("class", "ui-icon ui-icon-check"); $("#status_"+p).attr("class", "ui-icon ui-icon-check");
if(json[p]=='incorrect') if(json[p]=='incorrect')
$("#status_"+p).attr("class", "ui-icon ui-icon-close"); $("#status_"+p).attr("class", "ui-icon ui-icon-close");
$('#check_${ id }').attr("value", "Reset"); $('#check_${ id }').attr("value", "Reset");
} }
}); });
} else /* if 'Reset' */ { } else /* if 'Reset' */ {
// Possible cleanup: Move from getJSON to just load $.getJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) {
$.getJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) { ${ id }_load();
$('#main_${ id }').html(json); //$('#main_${ id }').html(json);
}); //MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
} });
}); }
});
});
}
$(function() {
${ id }_load();
}); });
<div id="main_${id}"></div>
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