aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2017-03-17 20:49:30 +1100
committerYingtong Li <runassudo@yingtongli.me>2017-03-17 20:49:30 +1100
commitaa7c45a633c949199bc82406a3ab94a786d87ba8 (patch)
tree1c09ba6b31e309aee891d7438dd27ccf7998ab18
parent93523382c61667cac4d07cac60a567e7eb2c22d5 (diff)
Fix a couple bugs
- Disable next question button when reaching last question - Fix display of drawing responses when mismatched orientation
-rw-r--r--pblive/templates/question_admin.html4
-rw-r--r--pblive/templates/question_draw.html23
2 files changed, 21 insertions, 6 deletions
diff --git a/pblive/templates/question_admin.html b/pblive/templates/question_admin.html
index f6100de..4367df7 100644
--- a/pblive/templates/question_admin.html
+++ b/pblive/templates/question_admin.html
@@ -37,5 +37,7 @@
<button class="ui primary button" onclick="socket.emit('reveal_answers', {{ question_num }});">Reveal responses</button>
{% endif %}
{% endblock %}
- <button class="ui button" onclick="socket.emit('goto_question', {{ question_num + 1 }});">Next question</button>
+ {% if question_num < session.questions|length - 1 %}
+ <button class="ui button" onclick="socket.emit('goto_question', {{ question_num + 1 }});">Next question</button>
+ {% endif %}
</p>
diff --git a/pblive/templates/question_draw.html b/pblive/templates/question_draw.html
index 2a1f3a7..64bb35c 100644
--- a/pblive/templates/question_draw.html
+++ b/pblive/templates/question_draw.html
@@ -64,11 +64,16 @@
}
function up(e) {
e.preventDefault();
- paint = false;
- // Submit image
- redraw(false);
- socket.emit('answer', {{ question_num }}, context.canvas.toDataURL('image/png'));
- redraw(true);
+ if (paint) {
+ paint = false;
+ // Submit image
+ // Because we can only capture the whole canvas, we resize the canvas here to fit the image
+ init_canvas();
+ redraw(false);
+ socket.emit('answer', {{ question_num }}, context.canvas.toDataURL('image/png'));
+ resize_canvas();
+ redraw(true);
+ }
}
$('#draw_canvas').mousedown(down);
@@ -123,6 +128,14 @@
redraw(true);
}
+ function init_canvas() {
+ document.getElementById('draw_canvas').width = image.width;
+ document.getElementById('draw_canvas').height = image.height;
+
+ // Recalculate scale
+ canvasAR = context.canvas.width / context.canvas.height;
+ scale = (canvasAR > imageAR) ? (context.canvas.height / image.height) : (context.canvas.width / image.width); // image dim * scale = canvas dim
+ }
window.onresize = resize_canvas;
resize_canvas();
}
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.