diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-10-21 14:22:31 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2014-01-21 12:04:03 +0100 |
commit | 31926b2fe46dcbe24f02d6a12e855b009cc45243 (patch) | |
tree | d02ddcc42595a3cd6d759d74371cd1d94f42c961 /install | |
parent | 67d58b96452a14474b68d56b7ddcaf12f1de2c65 (diff) | |
download | freeipa.git-31926b2fe46dcbe24f02d6a12e855b009cc45243.tar.gz freeipa.git-31926b2fe46dcbe24f02d6a12e855b009cc45243.tar.xz freeipa.git-31926b2fe46dcbe24f02d6a12e855b009cc45243.zip |
Dialog keyboard behavior
https://fedorahosted.org/freeipa/ticket/3904
Diffstat (limited to 'install')
-rw-r--r-- | install/ui/src/freeipa/dialog.js | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/install/ui/src/freeipa/dialog.js b/install/ui/src/freeipa/dialog.js index 29f480c5..337d2e61 100644 --- a/install/ui/src/freeipa/dialog.js +++ b/install/ui/src/freeipa/dialog.js @@ -224,7 +224,8 @@ IPA.dialog = function(spec) { } that.dom_node = $('<div/>', { - 'class': 'rcue-dialog-background' + 'class': 'rcue-dialog-background', + keydown: that.on_key_down }); var container_node = $('<div/>', { @@ -362,6 +363,39 @@ IPA.dialog = function(spec) { }; /** + * Default keyboard behavior + * + * - close on escape if enabled by `close_on_escape` + * - makes sure that tabbing doesn't leave the dialog + */ + that.on_key_down = function(event) { + + if ( that.close_on_escape && !event.isDefaultPrevented() && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE ) { + event.preventDefault(); + that.close(); + return; + } + + // prevent tabbing out of dialogs + if ( event.keyCode !== $.ui.keyCode.TAB ) { + return; + } + + var tabbables = that.dom_node.find(":tabbable"), + first = tabbables.filter(":first"), + last = tabbables.filter(":last"); + + if ( ( event.target === last[0] || event.target === that.dialog_node[0] ) && !event.shiftKey ) { + first.focus( 1 ); + event.preventDefault(); + } else if ( ( event.target === first[0] || event.target === that.dialog_node[0] ) && event.shiftKey ) { + last.focus( 1 ); + event.preventDefault(); + } + }; + + /** * Show message in dialog's message container * @param {string} message */ |