From 8aee6a1dd7b5df38eb6e7d8d89ce19a1e8960b49 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 18 Jan 2019 02:27:16 +0000 Subject: [PATCH] poll widget: Add some keyboard support. We support enter/ESC for our input fields. You still need to use the mouse to vote. --- static/js/poll_widget.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/static/js/poll_widget.js b/static/js/poll_widget.js index ce42371ab9..05f22d9029 100644 --- a/static/js/poll_widget.js +++ b/static/js/poll_widget.js @@ -269,6 +269,20 @@ exports.activate = function (opts) { update_edit_controls(); }); + elem.find('input.poll-question').on('keydown', function (e) { + e.stopPropagation(); + + if (e.keyCode === 13) { + submit_question(); + return; + } + + if (e.keyCode === 27) { + abort_edit(); + return; + } + }); + elem.find('.poll-edit-question').on('click', function (e) { e.stopPropagation(); start_editing(); @@ -288,6 +302,21 @@ exports.activate = function (opts) { e.stopPropagation(); submit_option(); }); + + elem.find('input.poll-comment').on('keydown', function (e) { + e.stopPropagation(); + + if (e.keyCode === 13) { + submit_option(); + return; + } + + if (e.keyCode === 27) { + $('input.poll-comment').val(''); + return; + } + }); + } function render_results() {