diff --git a/javascript/freepost.js b/javascript/freepost.js index 7bc62b6..df13829 100644 --- a/javascript/freepost.js +++ b/javascript/freepost.js @@ -27,11 +27,13 @@ @licend The above is the entire license notice for the JavaScript code in this page. */ - -/* This is a small script to hide the "up/down" arrow when users upvote - * posts and comments. The only reason for this is to give some feedback - * to the user after clicks. +/** + * Store which keys have been pressed. + * When a key has been pressed, pressed_key[e.keyCode] will be set + * to TRUE. When a key is released, pressed_key[e.keyCode] will be + * set to FALSE. */ +var pressed_key = []; /** * Change arrows class when voting. @@ -110,5 +112,22 @@ document.addEventListener ('DOMContentLoaded', function() { vote_sections[i].children[0].addEventListener ('click', function () { vote ('up', this.parentNode) }); vote_sections[i].children[2].addEventListener ('click', function () { vote ('down', this.parentNode) }); } - -}); + + // Bind onkeydown()/onkeyup() event to keys + document.onkeydown = document.onkeyup = function(e) { + // Set the current key code as TRUE/FALSE + pressed_key[e.keyCode] = e.type == 'keydown'; + + // If Ctrl+Enter have been pressed + // Key codes: Ctrl=17, Enter=13 + if (pressed_key[17] && pressed_key[13]) + { + // Select all forms in the current page with class "shortcut-submit" + let forms = document.querySelectorAll ("form.shortcut-submit"); + + for (let i = 0; i < forms.length; i++) + forms[i].submit (); + } + } + +}); \ No newline at end of file diff --git a/template/edit_comment.twig b/template/edit_comment.twig index 51edb45..703c772 100644 --- a/template/edit_comment.twig +++ b/template/edit_comment.twig @@ -14,7 +14,10 @@ {{ item.data.text|markdown|raw }} -