Better/more AJAXy problem rendering
This commit is contained in:
@@ -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//swfobject/swfobject.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>
|
||||
<!-- 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>
|
||||
|
||||
29
problem.html
29
problem.html
@@ -2,35 +2,6 @@
|
||||
${ problem['html'] }
|
||||
<br>
|
||||
<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:
|
||||
<input id="check_${ id }" type="button" value="${ check_button }" >
|
||||
% endif
|
||||
|
||||
60
problem.js
60
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();
|
||||
});
|
||||
|
||||
1
problem_ajax.html
Normal file
1
problem_ajax.html
Normal file
@@ -0,0 +1 @@
|
||||
<div id="main_${id}"></div>
|
||||
Reference in New Issue
Block a user