js: add "ctrl+enter to submit form" shortcut.
Press Ctrl+Enter inside any text box to submit the form.
This commit is contained in:
@@ -5,6 +5,8 @@ let Shortcuts = {};
|
||||
Shortcuts.initialize = function() {
|
||||
Utility.keydown("s", "scroll_down", Shortcuts.nav_scroll_down);
|
||||
Utility.keydown("w", "scroll_up", Shortcuts.nav_scroll_up);
|
||||
Utility.keydown("ctrl+return", "submit_form", Shortcuts.submit_form, 'input[type="text"], textarea');
|
||||
|
||||
Shortcuts.initialize_data_shortcuts();
|
||||
}
|
||||
|
||||
@@ -42,6 +44,11 @@ Shortcuts.initialize_data_shortcuts = function() {
|
||||
});
|
||||
};
|
||||
|
||||
Shortcuts.submit_form = function(event) {
|
||||
$(event.target).parents("form").find('input[type="submit"]').click();
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
Shortcuts.nav_scroll_down = function() {
|
||||
window.scrollBy(0, $(window).height() * 0.15);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import Post from './posts.js.erb'
|
||||
import Shortcuts from './shortcuts.js';
|
||||
import Utility from './utility.js';
|
||||
import Dropzone from 'dropzone';
|
||||
import SparkMD5 from 'spark-md5';
|
||||
|
||||
@@ -11,7 +13,7 @@ Upload.IQDB_HIGH_SIMILARITY = 65;
|
||||
|
||||
Upload.initialize_all = function() {
|
||||
if ($("#c-uploads,#c-posts").length) {
|
||||
this.initialize_enter_on_tags();
|
||||
Utility.keydown("return", "submit", Shortcuts.submit_form, "#upload_tag_string, #post_tag_string");
|
||||
$("#upload_source").on("change.danbooru", Upload.fetch_data_manual);
|
||||
$(document).on("click.danbooru", "#fetch-data-manual", Upload.fetch_data_manual);
|
||||
}
|
||||
@@ -66,16 +68,6 @@ Upload.validate_upload = function (e) {
|
||||
}
|
||||
}
|
||||
|
||||
Upload.initialize_enter_on_tags = function() {
|
||||
var $textarea = $("#upload_tag_string, #post_tag_string");
|
||||
var $submit = $textarea.parents("form").find('input[type="submit"]');
|
||||
|
||||
$textarea.on("keydown.danbooru.submit", null, "return", function(e) {
|
||||
$submit.click();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Upload.initialize_similar = function() {
|
||||
$("#similar-button").on("click.danbooru", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -67,9 +67,9 @@ Utility.dialog = function(title, html) {
|
||||
});
|
||||
}
|
||||
|
||||
Utility.keydown = function(keys, namespace, handler) {
|
||||
Utility.keydown = function(keys, namespace, handler, selector = document) {
|
||||
if (CurrentUser.data("enable-post-navigation")) {
|
||||
$(document).on("keydown.danbooru." + namespace, null, keys, handler);
|
||||
$(selector).on("keydown.danbooru." + namespace, null, keys, handler);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user