From 459c8e6a5759929f234c5543106601629388c34a Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Sun, 5 Mar 2023 23:13:58 +0100 Subject: [PATCH] Add shortcuts for saving --- assets/js/translation-form.js | 55 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/assets/js/translation-form.js b/assets/js/translation-form.js index 4190c81..d755f3a 100644 --- a/assets/js/translation-form.js +++ b/assets/js/translation-form.js @@ -4,6 +4,8 @@ let TranslationFormHook = { this.el.addEventListener("keyup", this.keyupHandler.bind(this)) this.title_input = this.el.querySelector("#translation-form_title") this.tunit_editor = this.el.querySelector("#tunit-editor-content") + this.save_edit_button = this.el.querySelector("#save-edit-button") + this.save_publish_button = this.el.querySelector("#save-publish-button") }, keyupHandler(e) { var push_event = true @@ -11,32 +13,39 @@ let TranslationFormHook = { var postaction = () => { } var payload = {} if (e.altKey){ - if (e.key == "ArrowDown" || e.key == "n"){ - preaction = () => { this.title_input.focus() } - postaction = () => { this.tunit_editor.focus() } - var handler = "select_next_tunit" - } else if (e.key == "ArrowUp" || e.key == "v"){ - preaction = () => { this.title_input.focus() } - postaction = () => { this.tunit_editor.focus() } - var handler = "select_previous_tunit" - } else if (e.key == "u") { - var handler = "tunit_status" - payload = {status: "untranslated"} - } else if (e.key == "p") { - var handler = "tunit_status" - payload = {status: "passable"} - } else if (e.key == "o") { - var handler = "tunit_status" - payload = {status: "done"} + if (e.ctrlKey){ + if (e.key == "s"){ + this.save_edit_button.click() + } else if (e.key == "p"){ + this.save_publish_button.click() + } } else { - push_event = false - } - if (push_event) { - preaction.call() - this.pushEventTo(this.el, handler, payload, postaction) + if (e.key == "ArrowDown" || e.key == "n"){ + preaction = () => { this.title_input.focus() } + postaction = () => { this.tunit_editor.focus() } + var handler = "select_next_tunit" + } else if (e.key == "ArrowUp" || e.key == "v"){ + preaction = () => { this.title_input.focus() } + postaction = () => { this.tunit_editor.focus() } + var handler = "select_previous_tunit" + } else if (e.key == "u") { + var handler = "tunit_status" + payload = {status: "untranslated"} + } else if (e.key == "p") { + var handler = "tunit_status" + payload = {status: "passable"} + } else if (e.key == "o") { + var handler = "tunit_status" + payload = {status: "done"} + } else { + push_event = false + } + if (push_event) { + preaction.call() + this.pushEventTo(this.el, handler, payload, postaction) + } } } - // console.info(["keyupHandler", e, this]) }, }