Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Qualtrics.SurveyEngine.addOnload(function() {
  2. var questions = $('Questions');
  3. var qs = questions.select('div.QuestionOuter');
  4. var qarr1 = [];
  5. var qarr2 = [];
  6. for(var i=0; i<qs.length; i++) {
  7. qarr1.push(qs[i].id);
  8. qarr2[qs[i].id] = qs[i+1].id;
  9. i++;
  10. }
  11. shuffle(qarr1);
  12.  
  13. var separators = questions.select('div.Separator');
  14. var j=0;
  15.  
  16. for(i=0; i<qarr1.length; i++) {
  17. questions.insert({bottom: $(qarr1[i])});
  18. questions.insert({bottom: separators[j]});
  19. j++;
  20. questions.insert({bottom: $(qarr2[qarr1[i]])});
  21. if(j < (separators.length - 1)) {
  22. questions.insert({bottom: separators[j]});
  23. j++;
  24. }
  25. }
  26.  
  27. function shuffle(array) {
  28. var currentIndex = array.length, temporaryValue, randomIndex ;
  29.  
  30. while (0 !== currentIndex) {
  31. randomIndex = Math.floor(Math.random() * currentIndex);
  32. currentIndex -= 1;
  33. temporaryValue = array[currentIndex];
  34. array[currentIndex] = array[randomIndex];
  35. array[randomIndex] = temporaryValue;
  36. }
  37. return array;
  38. }
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement