- Posts: 10288
- Thank you received: 3649
Ask the community, share ideas, and connect with other LimeSurvey users!
function maxDiff(qID, randomize, disableMobileView) { // Identify some elements var thisQuestion = $('#question'+qID); var thisTable = $('table.subquestion-list:eq(0)', thisQuestion); // Assign a new question class $(thisQuestion).addClass('max-diff-array'); // Disable the mobile table view if(disableMobileView) { $(thisTable).removeClass('ls-answers').addClass('disable-mobile-view'); } // Move the columns $('thead tr:eq(0)', thisTable).prepend($('thead tr:eq(0) th:eq(1)', thisTable)); $('tr.answers-list', thisTable).each(function(i){ $('td.answer-item:eq(0)', this).prependTo(this); }); // Random rows if(randomize) { var rowsArr = []; $('tr.answers-list', thisTable).each(function(i){ $(this).attr('data-index', i); rowsArr.push(i); }); shuffleArray(rowsArr); $(rowsArr).each(function(i){ $('tbody', thisTable).append($('tr[data-index="'+this+'"]', thisTable)); }); } // Prevent clicking twice in the same row $('input:radio', thisQuestion).on('click', function () { $('input:radio', thisQuestion).prop('disabled', false); $('input:radio:checked', thisQuestion).each(function(i) { var thisRow = $(this).closest('tr.answers-list'); $('input:radio', thisRow).not(this).prop('disabled', true); }); }); // Fix up the row classes var rowClass = 1; $('tr.answers-list', thisTable).each(function(i) { $(this).addClass('array'+(2-(i%2))); }); } 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; } return array; }
.max-diff-array tbody th.answertext { text-align: center; font-weight: normal; } .max-diff-array table.disable-mobile-view > tbody > tr > td { vertical-align: middle; } .max-diff-array table.disable-mobile-view tbody td { text-align: center; }
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Call the maxDiff() function // Set the second parameter to true for randomized rows // Set the third parameter to true to disable the LS mobile table view maxDiff({QID}, true, true); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
var thisTable = $('table.subquestion-list:eq(1)', thisQuestion);
var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
$('thead tr:eq(0)', thisTable).prepend($('thead tr:eq(0) th:eq(1)', thisTable));
$('thead tr:eq(0)', thisTable).prepend($('thead tr:eq(0) th:eq(0)', thisTable));
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.