Skip to content

Commit 42d9a6a

Browse files
authored
move handleGlobalEnterQuickSubmit into a separate file to avoid cycle-import (#20679)
1 parent ba0a0d3 commit 42d9a6a

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

Diff for: web_src/js/features/common-global.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createDropzone from './dropzone.js';
55
import {initCompColorPicker} from './comp/ColorPicker.js';
66
import {showGlobalErrorMessage} from '../bootstrap.js';
77
import {attachDropdownAria} from './aria.js';
8+
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
89

910
const {appUrl, csrfToken} = window.config;
1011

@@ -53,20 +54,6 @@ export function initGlobalEnterQuickSubmit() {
5354
});
5455
}
5556

56-
export function handleGlobalEnterQuickSubmit(target) {
57-
const $target = $(target);
58-
const $form = $(target).closest('form');
59-
if ($form.length) {
60-
// here use the event to trigger the submit event (instead of calling `submit()` method directly)
61-
// otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
62-
$form.trigger('submit');
63-
} else {
64-
// if no form, then the editor is for an AJAX request, dispatch an event to the target, let the target's event handler to do the AJAX request.
65-
// the 'ce-' prefix means this is a CustomEvent
66-
$target.trigger('ce-quick-submit');
67-
}
68-
}
69-
7057
export function initGlobalButtonClickOnEnter() {
7158
$(document).on('keypress', '.ui.button', (e) => {
7259
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar

Diff for: web_src/js/features/comp/EasyMDE.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import attachTribute from '../tribute.js';
3-
import {handleGlobalEnterQuickSubmit} from '../common-global.js';
3+
import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js';
44

55
/**
66
* @returns {EasyMDE}

Diff for: web_src/js/features/comp/QuickSubmit.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import $ from 'jquery';
2+
3+
export function handleGlobalEnterQuickSubmit(target) {
4+
const $target = $(target);
5+
const $form = $(target).closest('form');
6+
if ($form.length) {
7+
// here use the event to trigger the submit event (instead of calling `submit()` method directly)
8+
// otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog
9+
$form.trigger('submit');
10+
} else {
11+
// if no form, then the editor is for an AJAX request, dispatch an event to the target, let the target's event handler to do the AJAX request.
12+
// the 'ce-' prefix means this is a CustomEvent
13+
$target.trigger('ce-quick-submit');
14+
}
15+
}

0 commit comments

Comments
 (0)