Permalink
Browse files

commentTools: add ctrl-enter listeners in go() (#3877)

Since you can submit with ctrl-enter from forms that don't get editor tools (like the title and url fields), these listeners should be added separately from the editor listeners.
  • Loading branch information...
1 parent 6814b73 commit c8e03d7fbbf225cad5dc4288c48588f4f1f0fb6a @erikdesjardins erikdesjardins committed on GitHub Jan 11, 2017
Showing with 39 additions and 35 deletions.
  1. +39 −35 lib/modules/commentTools.js
@@ -246,8 +246,47 @@ const macroKeyTable: Array<[KeyArray, number]> = [];
module.go = () => {
$(document.body).on('focus', commentTextareaSelector, attachEditorToUsertext);
+
+ initializeCtrlEnterToSubmit();
};
+function initializeCtrlEnterToSubmit() {
+ if (module.options.ctrlEnterSubmitsComments.value) {
+ onCtrlEnter(
+ '.usertext-edit textarea, #BigEditor textarea, #wiki_page_content',
+ e => {
+ const currentForm = $(e.target).closest('form');
+ const saveButton = currentForm.find('.save')[0] || currentForm.find('#wiki_save_button')[0] || $('.BEFoot button')[0];
+ if (saveButton) click(saveButton);
+ }
+ );
+ }
+
+ if (module.options.ctrlEnterSavesLiveThreads.value) {
+ onCtrlEnter(
+ '.usertext-edit textarea',
+ () => {
+ const saveButton = $('#new-update-form .save-button button')[0];
+ if (saveButton) click(saveButton);
+ }
+ );
+ }
+
+ if (module.options.ctrlEnterSubmitsPosts.value) {
+ onCtrlEnter(
+ '#title-field textarea, #text-field textarea, #url, #sr-autocomplete, input.captcha',
+ () => {
+ const $captcha = $('input.captcha:not(.cap-text)');
+ if ($captcha.length && $captcha.val() === '') {
+ $captcha.focus();
+ } else {
+ click($('.spacer .btn')[0]);
+ }
+ }
+ );
+ }
+}
+
const initializeEditorTools = _.once(() => {
const $body = $('body');
@@ -318,41 +357,6 @@ const initializeEditorTools = _.once(() => {
});
}
- if (module.options.ctrlEnterSubmitsComments.value) {
- onCtrlEnter(
- '.usertext-edit textarea, #BigEditor textarea, #wiki_page_content',
- e => {
- const currentForm = $(e.target).closest('form');
- const saveButton = currentForm.find('.save')[0] || currentForm.find('#wiki_save_button')[0] || $('.BEFoot button')[0];
- if (saveButton) click(saveButton);
- }
- );
- }
-
- if (module.options.ctrlEnterSavesLiveThreads.value) {
- onCtrlEnter(
- '.usertext-edit textarea',
- () => {
- const saveButton = $('#new-update-form .save-button button')[0];
- if (saveButton) click(saveButton);
- }
- );
- }
-
- if (module.options.ctrlEnterSubmitsPosts.value) {
- onCtrlEnter(
- '#title-field textarea, #text-field textarea, #url, #sr-autocomplete, input.captcha',
- () => {
- const $captcha = $('input.captcha:not(.cap-text)');
- if ($captcha.length && $captcha.val() === '') {
- $captcha.focus();
- } else {
- click($('.spacer .btn')[0]);
- }
- }
- );
- }
-
if (module.options.subredditAutocomplete.value || module.options.userAutocomplete.value) {
addAutoCompletePop();
}

0 comments on commit c8e03d7

Please sign in to comment.