Skip to content

Commit

Permalink
submit forms via strg/cmd + enter (#4209)
Browse files Browse the repository at this point in the history
  • Loading branch information
schuer committed Dec 19, 2020
1 parent feca98a commit cfdcaeb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions redaxo/src/core/assets/standard.js
Expand Up @@ -679,6 +679,8 @@ jQuery(document).ready(function($) {
((windowHeight - rect.bottom) < menuHeight) &&
(rect.top > menuHeight));
});

document.addEventListener('keydown', handleKeyEvents, true);
});

// keep session alive
Expand All @@ -692,3 +694,25 @@ if ('login' !== rex.page && rex.session_keep_alive) {
clearInterval(keepAliveInterval);
}, rex.session_keep_alive * 1000 /* stop request after x seconds - see config.yml */);
}

// handle key events
var handleKeyEvents = function (event) {

// submit forms via strg/cmd + enter
if (event.metaKey && event.keyCode === 13) {
var form = event.target.closest('form');
if (form) {
// click apply button if available (e.g. when editing content)
var applyButton = form.querySelector('.btn-apply');
if (applyButton) {
applyButton.click();
} else {
// click (first) submit button
var submitButton = form.querySelector('[type=\'submit\']');
if (submitButton) {
submitButton.click();
}
}
}
}
}

0 comments on commit cfdcaeb

Please sign in to comment.