본문 바로가기
limesurvey_라임서베이/questionnaire

[순위결정] - ranking

by 거인과난쟁이 2023. 12. 13.

라임서베이의 순위결정 질문은 '두번 클릭' 또는 '오른쪽으로 밀어내기(슬라이딩)' 방식을 사용한다. 오른쪽으로 이동한 선택 답변들은 위-아래로 이동하면서 순위를 조정할 수 있다.

그런데, 때로는 순서앞에 1, 2, 3 등의 번호가 있으면 좋다고 느끼는 경우도 있겠다.

소스 코드를 다음과 같이 추가하면 된다:

<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete', function() {  
    var thisQuestion = $('#question{QID}');

    // Listeners on the rankable items for drag-and-drop events
    $('.sortable-list', thisQuestion).on('sort', function(e) {
      insertRankIndicators();
    });

    // Listener for changes in the select dropdown, if caused by drag-and-drop
    $('.select-item select', thisQuestion).on('change', function(e) {
      if(e.data && e.data.source == 'dragdrop') {
        insertRankIndicators();
      }
    });

    // Listener for double-click events
    $('.answer-item', thisQuestion).on('dblclick', function(event, ui) {
      setTimeout(function() {
        insertRankIndicators();
      }, 100);
    });

    // A function to insert ranking indicators
    function insertRankIndicators() {
      $('.inserted-rank', thisQuestion).remove();

      $('.sortable-rank .answer-item', thisQuestion).each(function(i) {
        $(this).prepend('<span class="inserted-rank">'+(i+1)+': </span>');
      });
    }
  });
</script>