- Posts: 55
- Thank you received: 3
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" data-author="BBSR-SR5"> $(document).on('ready pjax:scriptcomplete',function(){ //alert($('.modal-footer a').length) // Find the modal with the ID "bootstrap-alert-box-modal" var $modal = $('#bootstrap-alert-box-modal'); // Check if the modal is found if ($modal.length > 0) { // Find the modal footer within the modal var $modalFooter = $modal.find('.modal-footer'); var $anchors = $modalFooter.find('a'); // Check if there are exactly two anchor elements if ($anchors.length === 2) { // Detach the anchor elements from the DOM var $firstAnchor = $anchors.eq(0).detach(); var $secondAnchor = $anchors.eq(1).detach(); // Reinsert the anchor elements in reverse order into the modal footer $modalFooter.append($secondAnchor).append($firstAnchor); } } //Change warning text // Define some text strings var originalModalText = "Eine oder mehrere Pflichtfragen sind nicht beantwortet worden. Bitte beantworten Sie diese zuerst, um fortzufahren!"; var newModalText = "Sie haben auf dieser Seite mind. 1 Frage nicht beantwortet. Möchten Sie diese noch beantworten oder zur nächsten Seite weitergehen?"; // Modify the modal text var modalBody = $('.modal-body p').filter(function() { return $.trim($(this).text()) == originalModalText; }); if(modalBody.length > 0) { modalBody.text(newModalText); } //'' Randomisation Function begins here! **// //**********************************************// 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; } // Merge function function mergeArrays(array1, array2) { var mergedArray = ; var maxLength = Math.max(array1.length, array2.length); for (var i = 0; i < maxLength; i++) { if (i < array2.length) { mergedArray.push(array2[i]); } if (i < array1.length) { mergedArray.push(array1[i]); } } return mergedArray; } // Identify some elements and define variables var thisQuestion = $('#question{QID}'); var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent(); var thisTable = $('table.subquestion-list:eq(0)', thisQuestion); var orderQuestion = $(thisQuestion).nextAll('.text-short:eq(0)'); var orderInput = $(':text.form-control:eq(0)', orderQuestion); var array_res; var aOrder = ; var $headerRow = $("table thead tr").clone() // Previously set order if($.trim($(orderInput).val()) != '') { array_res = $.trim($(orderInput).val()).split(','); } // No previous order set else { // Special codes appear after var afterCode = 4; //Array for K Codes var array_k = ["b","d","g","h","i","j","l"]; //Array for N Codes var array_n = ["c","e","f","k","m","n"]; //Array for Special K Codes var array_sk = ; //Array for Special N codes var array_sn = ["a"]; //Array for super special codes var array_ss = ["o"]; // Shuffle order of "normal" arrays shuffleArray(array_k); shuffleArray(array_n); // Slice "normal" arrays and merge second part to special codes array_sk = array_sk.concat(array_k.slice(afterCode)); array_sn = array_sn.concat(array_n.slice(afterCode)); // Save only first part of "normal" arrays array_k = array_k.slice(0, afterCode); array_n = array_n.slice(0, afterCode); // Shuffle special arrays shuffleArray(array_sk); shuffleArray(array_sn); shuffleArray(array_ss); // Combine normal and special arrays array_k = array_k.concat(array_sk); array_n = array_n.concat(array_sn); // Merge arrays in order n,k,n,k... array_res = mergeArrays(array_k, array_n); //Add super special array to end of result array array_res = array_res.concat(array_ss); // Load the hidden order input $(orderInput).val(array_res); } // Loop through the answer codes $.each(array_res, function(i, val) { // Move the answer item $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion)); }); // Fix up the row background colours $('tr.answers-list', thisQuestion). each (function(i){ $(this).removeClass('ls-even ls-odd'); if(i % 2 == 0) { $(this).addClass('ls-even'); } else { $(this).addClass('ls-odd'); } }); }); //$('tr.answers-list:eq(0)', thisQuestion).append('<tr class="header-row"></tr>'); </script>[/i][/i][/i][/i]
Please Log in to join the conversation.
$('table.subquestion-list', thisQuestion).append($('table.subquestion-list thead', thisQuestion).clone());
Please Log in to join the conversation.
Please Log in to join the conversation.