special A key handling, fixed all inputs

This commit is contained in:
antelle 2017-05-19 23:57:49 +02:00
parent 13519a3d5d
commit 11dc8bef67
4 changed files with 19 additions and 16 deletions

View File

@ -14,6 +14,9 @@ const KeyHandler = {
init: function() {
$(document).bind('keypress', this.keypress.bind(this));
$(document).bind('keydown', this.keydown.bind(this));
this.shortcuts[Keys.DOM_VK_A] = [{ handler: this.handleAKey, thisArg: this, shortcut: this.SHORTCUT_ACTION,
modal: true, noPrevent: true }];
},
onKey: function(key, handler, thisArg, shortcut, modal, noPrevent) {
let keyShortcuts = this.shortcuts[key];
@ -40,28 +43,31 @@ const KeyHandler = {
const code = e.keyCode || e.which;
const keyShortcuts = this.shortcuts[code];
if (keyShortcuts && keyShortcuts.length) {
keyShortcuts.forEach(function(sh) {
for (const sh of keyShortcuts) {
if (this.modal && !sh.modal) {
e.stopPropagation();
return;
continue;
}
const isActionKey = this.isActionKey(e);
switch (sh.shortcut) {
case this.SHORTCUT_ACTION:
if (!isActionKey) { return; }
if (!isActionKey) { continue; }
break;
case this.SHORTCUT_OPT:
if (!e.altKey) { return; }
if (!e.altKey) { continue; }
break;
default:
if (e.metaKey || e.ctrlKey || e.altKey) { return; }
if (e.metaKey || e.ctrlKey || e.altKey) { continue; }
break;
}
sh.handler.call(sh.thisArg, e, code);
if (isActionKey && !sh.noPrevent) {
e.preventDefault();
}
}, this);
if (e.isImmediatePropagationStopped()) {
break;
}
}
}
},
keypress: function(e) {
@ -77,6 +83,13 @@ const KeyHandler = {
},
reg: function() {
IdleTracker.regUserAction();
},
handleAKey: function(e) {
if (e.target.tagName.toLowerCase() === 'input' && ['password', 'text'].indexOf(e.target.type) >= 0) {
e.stopImmediatePropagation();
} else {
e.preventDefault();
}
}
};

View File

@ -56,8 +56,6 @@ const KeyChangeView = Backbone.View.extend({
const code = e.keyCode || e.which;
if (code === Keys.DOM_VK_RETURN) {
this.accept();
} else if (code === Keys.DOM_VK_A) {
e.stopImmediatePropagation();
}
},

View File

@ -131,12 +131,6 @@ const ListSearchView = Backbone.View.extend({
}
e.target.blur();
break;
case Keys.DOM_VK_A:
if (e.metaKey || e.ctrlKey) {
e.stopPropagation();
return;
}
return;
default:
return;
}

View File

@ -390,8 +390,6 @@ const OpenView = Backbone.View.extend({
this.openDb();
} else if (code === Keys.DOM_VK_CAPS_LOCK) {
this.toggleCapsLockWarning(false);
} else if (code === Keys.DOM_VK_A) {
e.stopImmediatePropagation();
}
},