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) {
$(document).on('keydown mousedown touchstart', closePopup);
$(document).on('keypress', function(evt) {
if (evt.which === QUESTION_MARK) {
showKeyboardHelp(evt);
}
runOnKey(evt, QUESTION_MARK, showKeyboardHelp);
});
$element.on('click', '.keyboard-help-button', showKeyboardHelp);
$element.on('keydown', '.keyboard-help-button', function(evt) {
if (evt.which === RET) {
showKeyboardHelp(evt);
}
runOnKey(evt, RET, showKeyboardHelp);
});
$element.on('click', '.reset-button', resetExercise);
$element.on('keydown', '.reset-button', function(evt) {
if (evt.which === RET) {
resetExercise(evt);
}
runOnKey(evt, RET, resetExercise);
});
$element.on('click', '.submit-input', submitInput);
......@@ -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) {
if (evt.which === TAB) {
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