Skip to content

Commit f390d5e

Browse files
authored
Remove jQuery from the image pasting functionality (#29324)
- Switched to plain JavaScript - Tested the image pasting functionality and it works as before # Demo using JavaScript without jQuery ![demo](https://github.com/go-gitea/gitea/assets/20454870/018993ff-7b09-4d5f-88e0-f276368bacd6) Signed-off-by: Yarden Shoham <[email protected]>
1 parent a4fe1cd commit f390d5e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

web_src/js/features/comp/ImagePaste.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import $ from 'jquery';
21
import {htmlEscape} from 'escape-goat';
32
import {POST} from '../../modules/fetch.js';
43
import {imageInfo} from '../../utils/image.js';
@@ -93,11 +92,10 @@ class CodeMirrorEditor {
9392
}
9493

9594
const uploadClipboardImage = async (editor, dropzone, e) => {
96-
const $dropzone = $(dropzone);
97-
const uploadUrl = $dropzone.attr('data-upload-url');
98-
const $files = $dropzone.find('.files');
95+
const uploadUrl = dropzone.getAttribute('data-upload-url');
96+
const filesContainer = dropzone.querySelector('.files');
9997

100-
if (!uploadUrl || !$files.length) return;
98+
if (!uploadUrl || !filesContainer) return;
10199

102100
const pastedImages = clipboardPastedImages(e);
103101
if (!pastedImages || pastedImages.length === 0) {
@@ -126,8 +124,12 @@ const uploadClipboardImage = async (editor, dropzone, e) => {
126124
}
127125
editor.replacePlaceholder(placeholder, text);
128126

129-
const $input = $(`<input name="files" type="hidden">`).attr('id', uuid).val(uuid);
130-
$files.append($input);
127+
const input = document.createElement('input');
128+
input.setAttribute('name', 'files');
129+
input.setAttribute('type', 'hidden');
130+
input.setAttribute('id', uuid);
131+
input.value = uuid;
132+
filesContainer.append(input);
131133
}
132134
};
133135

@@ -140,7 +142,7 @@ export function initEasyMDEImagePaste(easyMDE, dropzone) {
140142

141143
export function initTextareaImagePaste(textarea, dropzone) {
142144
if (!dropzone) return;
143-
$(textarea).on('paste', async (e) => {
144-
return uploadClipboardImage(new TextareaEditor(textarea), dropzone, e.originalEvent);
145+
textarea.addEventListener('paste', async (e) => {
146+
return uploadClipboardImage(new TextareaEditor(textarea), dropzone, e);
145147
});
146148
}

0 commit comments

Comments
 (0)