Commit b426335e by Tim Krones

DRY out logic for conditionally executing handlers based on key that was

pressed.
parent 57d26a4a
...@@ -50,21 +50,15 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -50,21 +50,15 @@ function DragAndDropBlock(runtime, element, configuration) {
$(document).on('keydown mousedown touchstart', closePopup); $(document).on('keydown mousedown touchstart', closePopup);
$(document).on('keypress', function(evt) { $(document).on('keypress', function(evt) {
if (evt.which === QUESTION_MARK) { runOnKey(evt, QUESTION_MARK, showKeyboardHelp);
showKeyboardHelp(evt);
}
}); });
$element.on('click', '.keyboard-help-button', showKeyboardHelp); $element.on('click', '.keyboard-help-button', showKeyboardHelp);
$element.on('keydown', '.keyboard-help-button', function(evt) { $element.on('keydown', '.keyboard-help-button', function(evt) {
if (evt.which === RET) { runOnKey(evt, RET, showKeyboardHelp);
showKeyboardHelp(evt);
}
}); });
$element.on('click', '.reset-button', resetExercise); $element.on('click', '.reset-button', resetExercise);
$element.on('keydown', '.reset-button', function(evt) { $element.on('keydown', '.reset-button', function(evt) {
if (evt.which === RET) { runOnKey(evt, RET, resetExercise);
resetExercise(evt);
}
}); });
$element.on('click', '.submit-input', submitInput); $element.on('click', '.submit-input', submitInput);
...@@ -75,6 +69,12 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -75,6 +69,12 @@ function DragAndDropBlock(runtime, element, configuration) {
}); });
}; };
var runOnKey = function(evt, key, handler) {
if (evt.which === key) {
handler(evt);
}
};
var keyboardEventDispatcher = function(evt) { var keyboardEventDispatcher = function(evt) {
if (evt.which === TAB) { if (evt.which === TAB) {
trapFocus(evt); trapFocus(evt);
......
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