Commit ad08f22f1ad3b605e78933b6dc6075f534c0e1b9

Authored by Miguel Barão
1 parent e3803ea8
Exists in master and in 1 other branch dev

- allow clicking anywhere in the row of the topic list and of options of radio a…

…nd checkbox questions
static/js/topic.js
@@ -71,6 +71,23 @@ function new_question(type, question, tries, progress) { @@ -71,6 +71,23 @@ function new_question(type, question, tries, progress) {
71 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); 71 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress);
72 MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); 72 MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]);
73 73
  74 + if (type == "radio") {
  75 + $(".list-group-item").click(function () {
  76 + var index = $(this).index();
  77 + $("div.list-group input:radio").eq(index).prop("checked", true);
  78 +
  79 + // $('a.list-group-item-primary').removeClass('list-group-item-primary');
  80 + // $(this).addClass('list-group-item-primary');
  81 + });
  82 + }
  83 + else if (type == "checkbox") {
  84 + $(".list-group-item").click(function () {
  85 + var index = $(this).index();
  86 + $("div.list-group input:checkbox").eq(index).trigger("click");
  87 + });
  88 + }
  89 +
  90 +
74 // enable shift+enter to submit 91 // enable shift+enter to submit
75 $("input:text, input:radio, input:checkbox").keydown(function (e) { 92 $("input:text, input:radio, input:checkbox").keydown(function (e) {
76 if (e.keyCode == 13) { 93 if (e.keyCode == 13) {
templates/question-checkbox.html
@@ -7,7 +7,8 @@ @@ -7,7 +7,8 @@
7 {% for n,opt in enumerate(question['options']) %} 7 {% for n,opt in enumerate(question['options']) %}
8 <a class="list-group-item list-group-item-action"> 8 <a class="list-group-item list-group-item-action">
9 <div class="custom-control custom-checkbox"> 9 <div class="custom-control custom-checkbox">
10 - <input type="checkbox" class="custom-control-input" id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}"> 10 + <input type="checkbox" class="custom-control-input"
  11 + id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}">
11 <label for="{{ n }}" class="custom-control-label">{{ md(opt)[3:-5] }}</label> 12 <label for="{{ n }}" class="custom-control-label">{{ md(opt)[3:-5] }}</label>
12 </div> 13 </div>
13 </a> 14 </a>
templates/question-radio.html
@@ -7,7 +7,8 @@ @@ -7,7 +7,8 @@
7 {% for n,opt in enumerate(question['options']) %} 7 {% for n,opt in enumerate(question['options']) %}
8 <a class="list-group-item list-group-item-action"> 8 <a class="list-group-item list-group-item-action">
9 <div class="custom-control custom-radio"> 9 <div class="custom-control custom-radio">
10 - <input type="radio" class="custom-control-input" id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}"> 10 + <input type="radio" class="custom-control-input"
  11 + id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}">
11 <label for="{{ n }}" class="custom-control-label">{{ md(opt)[3:-5] }}</label> 12 <label for="{{ n }}" class="custom-control-label">{{ md(opt)[3:-5] }}</label>
12 </div> 13 </div>
13 </a> 14 </a>