Exercises: Fix draggable shuffle answer order BT#17725

pull/4101/head
Julio Montoya 5 years ago
parent a7d243b8ee
commit 5074fa6f6f
  1. 42
      main/template/default/exercise/submit.js.tpl
  2. 41
      main/template/rainbow/exercise/submit.js.tpl

@ -222,33 +222,35 @@ jsPlumb.ready(function () {
}
});
$(function () {
DraggableAnswer.init(
$(".exercise-draggable-answer"),
$(".droppable")
);
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
$(function () {
// if shuffle answers
if ('{{ shuffle_answers }}' == '1') {
$('.exercise-draggable-answer').each(function(){
// get current ul
var $ul = $(this);
// get array of list items in current ul
var $liArr = $ul.children('li');
// sort array of list items in current ul randomly
$liArr.sort(function(a,b){
// Get a random number between 0 and 10
var temp = parseInt( Math.random()*100 );
// Get 1 or 0, whether temp is odd or even
var isOddOrEven = temp%2;
// Get +1 or -1, whether temp greater or smaller than 5
var isPosOrNeg = temp>5 ? 1 : -1;
// Return -1, 0, or +1
return( isOddOrEven*isPosOrNeg );
})
// append list items to ul
.appendTo($ul);
var li = $ul.find('.touch-items');
var liContents = [];
li.each(function() {
liContents.push($(this));
});
shuffleArray(liContents);
$ul.empty().html(liContents);
});
}
DraggableAnswer.init(
$(".exercise-draggable-answer"),
$(".droppable")
);
});
</script>

@ -222,33 +222,34 @@ jsPlumb.ready(function () {
}
});
$(function () {
DraggableAnswer.init(
$(".exercise-draggable-answer"),
$(".droppable")
);
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
$(function () {
// if shuffle answers
if ('{{ shuffle_answers }}' == '1') {
$('.exercise-draggable-answer').each(function(){
// get current ul
var $ul = $(this);
// get array of list items in current ul
var $liArr = $ul.children('li');
// sort array of list items in current ul randomly
$liArr.sort(function(a,b){
// Get a random number between 0 and 10
var temp = parseInt( Math.random()*100 );
// Get 1 or 0, whether temp is odd or even
var isOddOrEven = temp%2;
// Get +1 or -1, whether temp greater or smaller than 5
var isPosOrNeg = temp>5 ? 1 : -1;
// Return -1, 0, or +1
return( isOddOrEven*isPosOrNeg );
})
// append list items to ul
.appendTo($ul);
var li = $ul.find('.touch-items');
var liContents = [];
li.each(function() {
liContents.push($(this));
});
shuffleArray(liContents);
$ul.empty().html(liContents);
});
}
DraggableAnswer.init(
$(".exercise-draggable-answer"),
$(".droppable")
);
});
</script>

Loading…
Cancel
Save