Skip to content

Commit

Permalink
allow ctrl link enable/disable when focus is on bottom web
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGreenMagick committed Apr 28, 2020
1 parent a95c306 commit 42f1fba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
7 changes: 2 additions & 5 deletions edit_field_during_review_cloze/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 9 additions & 11 deletions edit_field_during_review_cloze/web/bottom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
42 changes: 21 additions & 21 deletions edit_field_during_review_cloze/web/global_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down Expand Up @@ -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();
}
})

0 comments on commit 42f1fba

Please sign in to comment.