diff --git a/www/common/common-interface.js b/www/common/common-interface.js index e26be89aa..070fc9bd6 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -814,13 +814,43 @@ define([ var $ok = $(ok).click(function (ev) { close(true, ev); }); var $cancel = $(cancel).click(function (ev) { close(false, ev); }); + document.body.appendChild(frame); + + var modalElements = $(frame).find('a, button, input, [tabindex]:not([tabindex="-1"]), textarea').filter(':visible'); + if (modalElements.length > 0) { + modalElements[0].focus(); + frame.addEventListener('keydown', function(e) { + if (e.keyCode === 9) { + if (e.shiftKey) { + if (document.activeElement === modalElements[0]) { + e.preventDefault(); + modalElements[modalElements.length - 1].focus(); + } + } else { + if (document.activeElement === modalElements[modalElements.length - 1]) { + e.preventDefault(); + modalElements[0].focus(); + } + } + } + else if (e.keyCode === 13) { + if (document.activeElement === $ok[0]) { + $ok.click(); + } else if (document.activeElement === $cancel[0]) { + $cancel.click(); + } + } else if (e.keyCode === 27) { + $cancel.click(); + } + }); + } + listener = listenForKeys(function () { $ok.click(); }, function () { $cancel.click(); }, frame); - document.body.appendChild(frame); setTimeout(function () { Notifier.notify(); $(frame).find('.ok').focus(); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 69cf56543..3c2699595 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -176,6 +176,7 @@ define([ $(removeBtn).attr('tabindex', '0'); $(removeBtn).on('click keydown', function(event) { if (event.type === 'click' || (event.type === 'keydown' && event.key === 'Enter')) { + event.preventDefault(); config.remove(el); } });