aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYarden Shoham <git@yardenshoham.com>2024-02-22 18:35:58 +0200
committerGitHub <noreply@github.com>2024-02-22 17:35:58 +0100
commitf390d5eb4f4db21eeacdf2e7a093f6bd4e87c96f (patch)
tree1c942d033af459b33f8ea52dfe4c6e16bb718338
parenta4fe1cdf38f9a063e44b197ef07e4260f731c919 (diff)
downloadgitea-f390d5eb4f4db21eeacdf2e7a093f6bd4e87c96f.tar.gz
gitea-f390d5eb4f4db21eeacdf2e7a093f6bd4e87c96f.zip
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 <git@yardenshoham.com>
-rw-r--r--web_src/js/features/comp/ImagePaste.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/web_src/js/features/comp/ImagePaste.js b/web_src/js/features/comp/ImagePaste.js
index 444ab89150..b727880bc8 100644
--- a/web_src/js/features/comp/ImagePaste.js
+++ b/web_src/js/features/comp/ImagePaste.js
@@ -1,4 +1,3 @@
-import $ from 'jquery';
import {htmlEscape} from 'escape-goat';
import {POST} from '../../modules/fetch.js';
import {imageInfo} from '../../utils/image.js';
@@ -93,11 +92,10 @@ class CodeMirrorEditor {
}
const uploadClipboardImage = async (editor, dropzone, e) => {
- const $dropzone = $(dropzone);
- const uploadUrl = $dropzone.attr('data-upload-url');
- const $files = $dropzone.find('.files');
+ const uploadUrl = dropzone.getAttribute('data-upload-url');
+ const filesContainer = dropzone.querySelector('.files');
- if (!uploadUrl || !$files.length) return;
+ if (!uploadUrl || !filesContainer) return;
const pastedImages = clipboardPastedImages(e);
if (!pastedImages || pastedImages.length === 0) {
@@ -126,8 +124,12 @@ const uploadClipboardImage = async (editor, dropzone, e) => {
}
editor.replacePlaceholder(placeholder, text);
- const $input = $(`<input name="files" type="hidden">`).attr('id', uuid).val(uuid);
- $files.append($input);
+ const input = document.createElement('input');
+ input.setAttribute('name', 'files');
+ input.setAttribute('type', 'hidden');
+ input.setAttribute('id', uuid);
+ input.value = uuid;
+ filesContainer.append(input);
}
};
@@ -140,7 +142,7 @@ export function initEasyMDEImagePaste(easyMDE, dropzone) {
export function initTextareaImagePaste(textarea, dropzone) {
if (!dropzone) return;
- $(textarea).on('paste', async (e) => {
- return uploadClipboardImage(new TextareaEditor(textarea), dropzone, e.originalEvent);
+ textarea.addEventListener('paste', async (e) => {
+ return uploadClipboardImage(new TextareaEditor(textarea), dropzone, e);
});
}