Commit 5c5dc427 by Albert (AJ) St. Aubin Committed by GitHub

Merge pull request #126 from edx-solutions/aj/TNL-6668_keyboard_help_focus

Aj/tnl 6668 keyboard help focus
parents 7dcf1e6a cab18591
...@@ -504,7 +504,6 @@ function DragAndDropTemplates(configuration) { ...@@ -504,7 +504,6 @@ function DragAndDropTemplates(configuration) {
} }
} }
var progress_text = progress_template.replace('{possible}', formatNumber(ctx.weighted_max_score)); var progress_text = progress_template.replace('{possible}', formatNumber(ctx.weighted_max_score));
return h('div.problem-progress', { return h('div.problem-progress', {
id: configuration.url_name + '-problem-progress', id: configuration.url_name + '-problem-progress',
attributes: {role: 'status'} attributes: {role: 'status'}
...@@ -626,7 +625,6 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -626,7 +625,6 @@ function DragAndDropBlock(runtime, element, configuration) {
var M = 77; var M = 77;
var $selectedItem; var $selectedItem;
var $focusedElement;
var init = function() { var init = function() {
// Load the current user state, and load the image, then render the block. // Load the current user state, and load the image, then render the block.
...@@ -706,11 +704,11 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -706,11 +704,11 @@ function DragAndDropBlock(runtime, element, configuration) {
} }
}; };
var keyboardEventDispatcher = function(evt) { var keyboardEventDispatcher = function(evt, focusId) {
if (evt.which === TAB) { if (evt.which === TAB) {
trapFocus(evt); trapFocus(evt);
} else if (evt.which === ESC) { } else if (evt.which === ESC) {
hideKeyboardHelp(evt); hideKeyboardHelp(evt, focusId);
} }
}; };
...@@ -788,6 +786,7 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -788,6 +786,7 @@ function DragAndDropBlock(runtime, element, configuration) {
}; };
var showKeyboardHelp = function(evt) { var showKeyboardHelp = function(evt) {
var focusId = document.activeElement;
evt.preventDefault(); evt.preventDefault();
// Show dialog // Show dialog
...@@ -795,15 +794,17 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -795,15 +794,17 @@ function DragAndDropBlock(runtime, element, configuration) {
$keyboardHelpDialog.find('.modal-window-overlay').show(); $keyboardHelpDialog.find('.modal-window-overlay').show();
$keyboardHelpDialog.find('.modal-window').show().focus(); $keyboardHelpDialog.find('.modal-window').show().focus();
// Handle focus
$focusedElement = $(':focus');
// Set up event handlers // Set up event handlers
$(document).on('keydown', keyboardEventDispatcher); $(document).on('keydown', function(evt) {
$keyboardHelpDialog.find('.modal-dismiss-button').on('click', hideKeyboardHelp); keyboardEventDispatcher(evt, focusId);
});
$keyboardHelpDialog.find('.modal-dismiss-button').on('click', function(evt) {
hideKeyboardHelp(evt, focusId)
});
}; };
var hideKeyboardHelp = function(evt) { var hideKeyboardHelp = function(evt, focusId) {
evt.preventDefault(); evt.preventDefault();
// Hide dialog // Hide dialog
...@@ -811,12 +812,12 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -811,12 +812,12 @@ function DragAndDropBlock(runtime, element, configuration) {
$keyboardHelpDialog.find('.modal-window-overlay').hide(); $keyboardHelpDialog.find('.modal-window-overlay').hide();
$keyboardHelpDialog.find('.modal-window').hide(); $keyboardHelpDialog.find('.modal-window').hide();
// Handle focus
$focusedElement.focus();
// Remove event handlers // Remove event handlers
$(document).off('keydown', keyboardEventDispatcher); $(document).off('keydown');
$keyboardHelpDialog.find('.modal-dismiss-button').off(); $keyboardHelpDialog.find('.modal-dismiss-button').off();
// Handle focus
$(focusId).focus();
}; };
/** Asynchronously load the main background image used for this block. */ /** Asynchronously load the main background image used for this block. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment