home » zplus/freepost.git
Author zPlus <-> 2017-03-27 19:24:54
Committer zPlus <-> 2017-03-27 19:24:54
Commit b1531cb (patch)
Tree a3f7c87
Parent(s)

Fix #40 Ctrl+Enter to submit post/comment


commits diff: 6097029..b1531cb
6 files changed, 46 insertions, 11 deletionsdownload


Diffstat
-rw-r--r-- javascript/freepost.js 31
-rw-r--r-- template/edit_comment.twig 5
-rw-r--r-- template/edit_post.twig 5
-rw-r--r-- template/post.twig 5
-rw-r--r-- template/reply.twig 5
-rw-r--r-- template/submit.twig 6

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+25/-6 M   javascript/freepost.js
index 7bc62b6..df13829
old size: 4K - new size: 5K
@@ -27,11 +27,13 @@
27 27 @licend The above is the entire license notice for the JavaScript code in this page.
28 28 */
29 29
30 -
31 - /* This is a small script to hide the "up/down" arrow when users upvote
32 - * posts and comments. The only reason for this is to give some feedback
33 - * to the user after clicks.
30 + /**
31 + * Store which keys have been pressed.
32 + * When a key has been pressed, pressed_key[e.keyCode] will be set
33 + * to TRUE. When a key is released, pressed_key[e.keyCode] will be
34 + * set to FALSE.
34 35 */
36 + var pressed_key = [];
35 37
36 38 /**
37 39 * Change arrows class when voting.
@@ -110,5 +112,22 @@ document.addEventListener ('DOMContentLoaded', function() {
110 112 vote_sections[i].children[0].addEventListener ('click', function () { vote ('up', this.parentNode) });
111 113 vote_sections[i].children[2].addEventListener ('click', function () { vote ('down', this.parentNode) });
112 114 }
113 -
114 - });
115 +
116 + // Bind onkeydown()/onkeyup() event to keys
117 + document.onkeydown = document.onkeyup = function(e) {
118 + // Set the current key code as TRUE/FALSE
119 + pressed_key[e.keyCode] = e.type == 'keydown';
120 +
121 + // If Ctrl+Enter have been pressed
122 + // Key codes: Ctrl=17, Enter=13
123 + if (pressed_key[17] && pressed_key[13])
124 + {
125 + // Select all forms in the current page with class "shortcut-submit"
126 + let forms = document.querySelectorAll ("form.shortcut-submit");
127 +
128 + for (let i = 0; i < forms.length; i++)
129 + forms[i].submit ();
130 + }
131 + }
132 +
133 + });
133 < \ No newline at end of file

+4/-1 M   template/edit_comment.twig
index 51edb45..703c772
old size: 815B - new size: 978B
@@ -14,7 +14,10 @@
14 14 {{ item.data.text|markdown|raw }}
15 15 </div>
16 16
17 - <form action="" method="post">
17 + {# "shortcut-submit" is a class used exclusively from javascript
18 + # to submit the form when a key (Ctrl+Enter) is pressed.
19 + #}
20 + <form action="" method="post" class="shortcut-submit">
18 21 <input type="hidden" name="comment" value="{{ item.data.hashId }}" />
19 22
20 23 <div style="margin: 2em 0;">

+4/-1 M   template/edit_post.twig
index 8ff85a2..e88954e
old size: 1K - new size: 1K
@@ -1,7 +1,10 @@
1 1 {% include 'header.twig' %}
2 2
3 3 <div class="edit">
4 - <form action="" method="post" class="submit">
4 + {# "shortcut-submit" is a class used exclusively from javascript
5 + # to submit the form when a key (Ctrl+Enter) is pressed.
6 + #}
7 + <form action="" method="post" class="submit shortcut-submit">
5 8 <input type="hidden" name="post" value="{{ item.data.hashId }}" />
6 9
7 10 <h3>Title <em>(required)</em></h3>

+4/-1 M   template/post.twig
index cad9509..6e60c4f
old size: 2K - new size: 2K
@@ -36,7 +36,10 @@
36 36 </div>
37 37
38 38 {% if user %}
39 - <form action="" method="post" class="new_comment">
39 + {# "shortcut-submit" is a class used exclusively from javascript
40 + # to submit the form when a key (Ctrl+Enter) is pressed.
41 + #}
42 + <form action="" method="post" class="new_comment shortcut-submit">
40 43 <textarea name="new_comment" required="required" class="form-control" placeholder="Write a comment"></textarea>
41 44 <input type="submit" value="Add comment" class="button button_info" />
42 45 </form>

+4/-1 M   template/reply.twig
index 5cd3bcf..7ff15fe
old size: 950B - new size: 1K
@@ -12,7 +12,10 @@
12 12 {{ comment.text|markdown|raw }}
13 13 </div>
14 14
15 - <form action="" method="post">
15 + {# "shortcut-submit" is a class used exclusively from javascript
16 + # to submit the form when a key (Ctrl+Enter) is pressed.
17 + #}
18 + <form action="" method="post" class="shortcut-submit">
16 19 <input type="hidden" name="parent_comment" value="{{ comment.hashId }}" />
17 20
18 21 <div style="margin: 2em 0;">

+5/-1 M   template/submit.twig
index 7c63464..42ac21f
old size: 577B - new size: 721B
@@ -1,6 +1,10 @@
1 1 {% include 'header.twig' %}
2 2
3 - <form action="" method="post" class="submit">
3 +
4 + {# "shortcut-submit" is a class used exclusively from javascript
5 + # to submit the form when a key (Ctrl+Enter) is pressed.
6 + #}
7 + <form action="" method="post" class="submit shortcut-submit">
4 8 <h3>Title <em>(required)</em></h3>
5 9 <div>
6 10 <input type="text" name="title" class="form-control" />