Use DOM Level 2 events.

HFJ-1999
pull/22/head
Thomas Marstrander 2016-06-07 15:09:59 +02:00
parent 8bd9e9c2db
commit 10e1a7ba65
1 changed files with 11 additions and 11 deletions

View File

@ -71,12 +71,12 @@ H5P.ConfirmationDialog = (function (EventDispatcher) {
popup.classList.add('h5p-confirmation-dialog-popup', 'hidden'); popup.classList.add('h5p-confirmation-dialog-popup', 'hidden');
popup.setAttribute('role', 'dialog'); popup.setAttribute('role', 'dialog');
popupBackground.appendChild(popup); popupBackground.appendChild(popup);
popup.onkeydown = function (e) { popup.addEventListener('keydown', function (e) {
if (e.which === 27) {// Esc key if (e.which === 27) {// Esc key
// Exit dialog // Exit dialog
dialogCanceled(e); dialogCanceled(e);
} }
}; });
// Popup header // Popup header
var header = document.createElement('div'); var header = document.createElement('div');
@ -123,36 +123,36 @@ H5P.ConfirmationDialog = (function (EventDispatcher) {
exitButton.title = options.cancelText; exitButton.title = options.cancelText;
// Cancel handler // Cancel handler
cancelButton.onclick = dialogCanceled; cancelButton.addEventListener('click', dialogCanceled);
cancelButton.onkeydown = function (e) { cancelButton.addEventListener('keydown', function (e) {
if (e.which === 32) { // Space if (e.which === 32) { // Space
dialogCanceled(e); dialogCanceled(e);
} }
else if (e.which === 9 && e.shiftKey) { // Shift-tab else if (e.which === 9 && e.shiftKey) { // Shift-tab
flowTo(exitButton, e); flowTo(exitButton, e);
} }
}; });
buttons.appendChild(cancelButton); buttons.appendChild(cancelButton);
// Confirm handler // Confirm handler
confirmButton.onclick = dialogConfirmed; confirmButton.addEventListener('click', dialogConfirmed);
confirmButton.onkeydown = function (e) { confirmButton.addEventListener('keydown', function (e) {
if (e.which === 32) { // Space if (e.which === 32) { // Space
dialogConfirmed(e); dialogConfirmed(e);
} }
}; });
buttons.appendChild(confirmButton); buttons.appendChild(confirmButton);
// Exit handler // Exit handler
exitButton.onclick = dialogCanceled; exitButton.addEventListener('click', dialogCanceled);
exitButton.onkeydown = function (e) { exitButton.addEventListener('keydown', function (e) {
if (e.which === 32) { // Space if (e.which === 32) { // Space
dialogCanceled(e); dialogCanceled(e);
} }
else if (e.which === 9 && !e.shiftKey) { // Tab else if (e.which === 9 && !e.shiftKey) { // Tab
flowTo(cancelButton, e); flowTo(cancelButton, e);
} }
}; });
popup.appendChild(exitButton); popup.appendChild(exitButton);
// Wrapper element // Wrapper element