Commit 64f0b75c6541753da39013f00e1473660fdcffd3
1 parent
7c0e56ca
Exists in
master
and in
1 other branch
- added accesskey to radio and checkboxes (shortcuts depend on the
browser/OS combination). - always use shift+enter to submit radio, checkbox, text and textarea.
Showing
5 changed files
with
11 additions
and
18 deletions
Show diff stats
BUGS.md
@@ -8,13 +8,13 @@ BUGS: | @@ -8,13 +8,13 @@ BUGS: | ||
8 | TODO: | 8 | TODO: |
9 | 9 | ||
10 | - configuração e linha de comando. | 10 | - configuração e linha de comando. |
11 | -- logging | ||
12 | - como gerar uma sequencia de perguntas? | 11 | - como gerar uma sequencia de perguntas? |
13 | - generators not working: bcrypt (ver blog) | 12 | - generators not working: bcrypt (ver blog) |
14 | -- implementar navegacao radio/checkbox. cursor cima/baixo, espaco selecciona, enter submete. | ||
15 | 13 | ||
16 | SOLVED: | 14 | SOLVED: |
17 | 15 | ||
16 | +- implementar navegacao radio/checkbox. cursor cima/baixo, espaco selecciona, enter submete. | ||
17 | +- logging | ||
18 | - textarea tem codigo para preencher o texto, mas ja não é necessário porque pergunta não é reloaded. | 18 | - textarea tem codigo para preencher o texto, mas ja não é necessário porque pergunta não é reloaded. |
19 | - gravar answers -> db | 19 | - gravar answers -> db |
20 | - como gerar key para secure cookie. | 20 | - como gerar key para secure cookie. |
README.md
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | 3 | ||
4 | ## Requirements | 4 | ## Requirements |
5 | 5 | ||
6 | -We will need to install python3.6, pip and sqlite3 python package. | 6 | +We will need to install python3.6 with sqlite3 support. |
7 | This can be done using the system package management, downloaded from [http://www.python.org](), or compiled from sources. | 7 | This can be done using the system package management, downloaded from [http://www.python.org](), or compiled from sources. |
8 | 8 | ||
9 | - Installing from the system package management: | 9 | - Installing from the system package management: |
@@ -18,12 +18,12 @@ This can be done using the system package management, downloaded from [http://ww | @@ -18,12 +18,12 @@ This can be done using the system package management, downloaded from [http://ww | ||
18 | - `./configure --prefix=$HOME/.local/bin` | 18 | - `./configure --prefix=$HOME/.local/bin` |
19 | - `make && make install` | 19 | - `make && make install` |
20 | 20 | ||
21 | -To install pip (if not yet installed): | 21 | +Next install pip (if not yet installed): |
22 | 22 | ||
23 | python36 -m ensurepip --user | 23 | python36 -m ensurepip --user |
24 | 24 | ||
25 | This will install pip in your account under `~/.local/bin`. | 25 | This will install pip in your account under `~/.local/bin`. |
26 | -In the end you should be able to run `pip3 --version` and `python3 -c "import sqlite3"` without errors (sometimes `pip3` is `pip`, `pip3.6` or `pip-3.6` are used). | 26 | +In the end you should be able to run `pip3 --version` and `python3 -c "import sqlite3"` without errors (sometimes `pip3` is `pip`, `pip3.6` or `pip-3.6`). |
27 | 27 | ||
28 | Install additional python packages locally on the user area: | 28 | Install additional python packages locally on the user area: |
29 | 29 | ||
@@ -39,7 +39,6 @@ Note: If you want to always install python modules on the user account, edit the | @@ -39,7 +39,6 @@ Note: If you want to always install python modules on the user account, edit the | ||
39 | [global] | 39 | [global] |
40 | user = yes | 40 | user = yes |
41 | 41 | ||
42 | - | ||
43 | ## Installation | 42 | ## Installation |
44 | 43 | ||
45 | Replace USER by your bitbucket username: | 44 | Replace USER by your bitbucket username: |
@@ -60,7 +59,6 @@ First we need to create a database: | @@ -60,7 +59,6 @@ First we need to create a database: | ||
60 | 59 | ||
61 | We also need certificates for https. Generate selfsigned certificates using openssl: | 60 | We also need certificates for https. Generate selfsigned certificates using openssl: |
62 | 61 | ||
63 | - mkdir certs | ||
64 | cd certs | 62 | cd certs |
65 | openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes | 63 | openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes |
66 | cd .. | 64 | cd .. |
templates/learn.html
@@ -98,20 +98,14 @@ $.fn.extend({ | @@ -98,20 +98,14 @@ $.fn.extend({ | ||
98 | } | 98 | } |
99 | }); | 99 | }); |
100 | 100 | ||
101 | +// Processes the response given by the served after an answer is submitted. | ||
101 | function updateQuestion(response){ | 102 | function updateQuestion(response){ |
102 | - | ||
103 | switch (response["method"]) { | 103 | switch (response["method"]) { |
104 | case "new_question": | 104 | case "new_question": |
105 | $("#question_div").html(response["params"]); | 105 | $("#question_div").html(response["params"]); |
106 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); | 106 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); |
107 | 107 | ||
108 | - $("input:text").keypress(function (e) { | ||
109 | - if (e.keyCode == 13) { | ||
110 | - e.preventDefault(); | ||
111 | - getQuestion(); | ||
112 | - } | ||
113 | - }); | ||
114 | - $("textarea").keydown(function (e) { | 108 | + $("textarea, input:text, input:radio, input:checkbox").keydown(function (e) { |
115 | if (e.keyCode == 13 && e.shiftKey) { | 109 | if (e.keyCode == 13 && e.shiftKey) { |
116 | e.preventDefault(); | 110 | e.preventDefault(); |
117 | getQuestion(); | 111 | getQuestion(); |
@@ -129,6 +123,8 @@ function updateQuestion(response){ | @@ -129,6 +123,8 @@ function updateQuestion(response){ | ||
129 | } | 123 | } |
130 | } | 124 | } |
131 | 125 | ||
126 | +// Send answer and receive a response. | ||
127 | +// The response can be a new_question or a shake if the answer is wrong. | ||
132 | function getQuestion() { | 128 | function getQuestion() { |
133 | $.ajax({ | 129 | $.ajax({ |
134 | type: "POST", | 130 | type: "POST", |
@@ -144,7 +140,6 @@ function getQuestion() { | @@ -144,7 +140,6 @@ function getQuestion() { | ||
144 | $(document).ready(function() { | 140 | $(document).ready(function() { |
145 | var audio = new Audio('/static/sounds/intro.mp3'); | 141 | var audio = new Audio('/static/sounds/intro.mp3'); |
146 | audio.play(); | 142 | audio.play(); |
147 | - // getQuestion(); | ||
148 | $("#submit").click(getQuestion); | 143 | $("#submit").click(getQuestion); |
149 | }); | 144 | }); |
150 | </script> | 145 | </script> |
templates/question-checkbox.html
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <div class="list-group"> | 6 | <div class="list-group"> |
7 | {% for n,opt in enumerate(question['options']) %} | 7 | {% for n,opt in enumerate(question['options']) %} |
8 | <a class="list-group-item"> | 8 | <a class="list-group-item"> |
9 | - <input type="checkbox" id="{{ n }}" name="answer" value="{{ n }}"> | 9 | + <input type="checkbox" id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}"> |
10 | <label for="{{ n }}">{{ md(opt) }}</label> | 10 | <label for="{{ n }}">{{ md(opt) }}</label> |
11 | </a> | 11 | </a> |
12 | {% end %} | 12 | {% end %} |
templates/question-radio.html
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <div class="list-group"> | 6 | <div class="list-group"> |
7 | {% for n,opt in enumerate(question['options']) %} | 7 | {% for n,opt in enumerate(question['options']) %} |
8 | <a class="list-group-item"> | 8 | <a class="list-group-item"> |
9 | - <input type="radio" id="{{ n }}" name="answer" value="{{ n }}"> | 9 | + <input type="radio" id="{{ n }}" accesskey="{{ n+1 }}" name="answer" value="{{ n }}"> |
10 | <label for="{{ n }}">{{ md(opt) }}</label> | 10 | <label for="{{ n }}">{{ md(opt) }}</label> |
11 | </a> | 11 | </a> |
12 | {% end %} | 12 | {% end %} |