From 42f1fba68619095096f9234e708263c068b25bc3 Mon Sep 17 00:00:00 2001 From: BlueGreenMagick Date: Tue, 28 Apr 2020 12:25:10 +0900 Subject: [PATCH] allow ctrl link enable/disable when focus is on bottom web --- edit_field_during_review_cloze/reviewer.py | 7 +--- edit_field_during_review_cloze/web/bottom.js | 20 ++++----- .../web/global_card.js | 42 +++++++++---------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/edit_field_during_review_cloze/reviewer.py b/edit_field_during_review_cloze/reviewer.py index 6af19ca..2b284da 100644 --- a/edit_field_during_review_cloze/reviewer.py +++ b/edit_field_during_review_cloze/reviewer.py @@ -101,10 +101,7 @@ def myRevHtml(reviewer, _old): def myRevBottomHTML(reviewer, _old): - ctrl = bool_to_str(config["ctrl_click"]) - script = BOTTOMJS % ({"ctrl": ctrl}) - - return _old(reviewer) + script + return _old(reviewer) + BOTTOMJS def edit(txt, extra, context, field, fullname): @@ -193,7 +190,7 @@ def myLinkHandler(reviewer, url, _old): return encoded_val = base64.b64encode(val.encode("utf-8")).decode("ascii") reviewer.web.eval( - """ + """ (function(){ var encoded_val = "%s"; var nid = %d; diff --git a/edit_field_during_review_cloze/web/bottom.js b/edit_field_during_review_cloze/web/bottom.js index 5610a4a..1c88b4d 100644 --- a/edit_field_during_review_cloze/web/bottom.js +++ b/edit_field_during_review_cloze/web/bottom.js @@ -3,21 +3,19 @@ So this code catches ctrl key presses when focus in on bottom.web */ -CTRL = "%(ctrl)s"; - -if(typeof EFDRConctrlkey != "function" && CTRL){ - window.EFDRConctrlkey = function(){ - window.addEventListener('keydown',function(event){ - if(["ControlLeft", "MetaLeft"].includes(event.code)){ +if (typeof EFDRConctrlkey != "function") { + window.EFDRConctrlkey = function () { + window.addEventListener('keydown', function (event) { + if (["ControlLeft", "MetaLeft"].includes(event.code)) { pycmd("EFDRC!ctrldown"); - } + } }) - window.addEventListener('keyup',function(event){ - if(["ControlLeft", "MetaLeft"].includes(event.code)){ + window.addEventListener('keyup', function (event) { + if (["ControlLeft", "MetaLeft"].includes(event.code)) { pycmd("EFDRC!ctrlup"); - } - }) + } + }) } EFDRConctrlkey() } \ No newline at end of file diff --git a/edit_field_during_review_cloze/web/global_card.js b/edit_field_during_review_cloze/web/global_card.js index 71886ad..ecca355 100644 --- a/edit_field_during_review_cloze/web/global_card.js +++ b/edit_field_during_review_cloze/web/global_card.js @@ -101,24 +101,30 @@ EFDRC.handlePaste = function (e) { } EFDRC.ctrldown = function () { - els = document.querySelectorAll("[data-EFDRC='true']"); - for (var e = 0; e < els.length; e++) { - var el = els[e]; - el.setAttribute("contenteditable", "true"); - if (el.hasAttribute("data-EFDRCnotctrl")) { - el.removeAttribute("data-EFDRCnotctrl"); + EFDRC.ctrlLinkEnable(); + if (EFDRC.CTRL) { + els = document.querySelectorAll("[data-EFDRC='true']"); + for (var e = 0; e < els.length; e++) { + var el = els[e]; + el.setAttribute("contenteditable", "true"); + if (el.hasAttribute("data-EFDRCnotctrl")) { + el.removeAttribute("data-EFDRCnotctrl"); + } } } } EFDRC.ctrlup = function () { - var els = document.querySelectorAll("[data-EFDRC='true']"); - for (var e = 0; e < els.length; e++) { - var el = els[e]; - if (el == document.activeElement) { - el.setAttribute("data-EFDRCnotctrl", "true"); - } else { - el.setAttribute("contenteditable", "false"); + EFDRC.ctrlLinkDisable(); + if (EFDRC.CTRL) { + var els = document.querySelectorAll("[data-EFDRC='true']"); + for (var e = 0; e < els.length; e++) { + var el = els[e]; + if (el == document.activeElement) { + el.setAttribute("data-EFDRCnotctrl", "true"); + } else { + el.setAttribute("contenteditable", "false"); + } } } } @@ -294,18 +300,12 @@ EFDRC.ctrlLinkDisable = function () { window.addEventListener('keydown', function (event) { if (["ControlLeft", "MetaLeft"].includes(event.code)) { - EFDRC.ctrlLinkEnable(); - if (EFDRC.CTRL) { - EFDRC.ctrldown(); - } + EFDRC.ctrldown(); } }) window.addEventListener('keyup', function (event) { if (["ControlLeft", "MetaLeft"].includes(event.code)) { - EFDRC.ctrlLinkDisable(); - if (EFDRC.CTRL) { - EFDRC.ctrlup(); - } + EFDRC.ctrlup(); } })