From 5385a02428ce828cbbb7cb640b71dd50f8dccd80 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 12 Dec 2011 08:58:21 -0500 Subject: [PATCH] Sequence is now namespaced --- problem.js | 27 +++++++++++++++++++++++++++ seq_module.html | 4 ++-- seq_module.js | 42 +++++++++++++++++++++--------------------- 3 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 problem.js diff --git a/problem.js b/problem.js new file mode 100644 index 0000000000..6132f4fb72 --- /dev/null +++ b/problem.js @@ -0,0 +1,27 @@ +$(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') == '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); + }); + } + }); +}); diff --git a/seq_module.html b/seq_module.html index 32987ad250..b81126c19e 100644 --- a/seq_module.html +++ b/seq_module.html @@ -5,9 +5,9 @@ % endfor - +
- +
 
diff --git a/seq_module.js b/seq_module.js index 65841db024..f11305b40d 100644 --- a/seq_module.js +++ b/seq_module.js @@ -1,48 +1,48 @@ // CRITICAL TODO: Namespace -var files=["", +var ${ id }files=["", %for t in items: ${t[1]['content']} , %endfor "" ]; -var functions=["", +var ${ id }functions=["", %for t in items: function(){ ${t[1]['js']} }, %endfor ""]; -var loc; +var ${ id }loc; -function goto(i) { - $('#content').html(files[i]); - functions[i]() - loc=i; +function ${ id }goto(i) { + $('#content').html(${ id }files[i]); + ${ id }functions[i]() + ${ id }loc=i; } -function setup_click(i) { - $('#tt_'+i).click(function(eo) { goto(i);}); +function ${ id }setup_click(i) { + $('#tt_'+i).click(function(eo) { ${ id }goto(i);}); } -function next() { - loc=loc+1; - if(loc> ${ len(items) } ) loc=${ len(items) }; - goto(loc); +function ${ id }next() { + ${ id }loc=${ id }loc+1; + if(${ id }loc> ${ len(items) } ) ${ id }loc=${ len(items) }; + ${ id }goto(${ id }loc); } -function prev() { - loc=loc-1; - if(loc<1) loc=1; - goto(loc); +function ${ id }prev() { + ${ id }loc=${ id }loc-1; + if(${ id }loc<1) ${ id }loc=1; + ${ id }goto(${ id }loc); } $(function() { var i; for(i=1; i<11; i++) { - setup_click(i); + ${ id }setup_click(i); } - $('#next').click(function(eo) { next();}); - $('#prev').click(function(eo) { prev();}); - goto(1); + $('#${ id }next').click(function(eo) { ${ id }next();}); + $('#${ id }prev').click(function(eo) { ${ id }prev();}); + ${ id }goto(1); });