1
- import $ from 'jquery' ;
2
1
import { htmlEscape } from 'escape-goat' ;
3
2
import { POST } from '../../modules/fetch.js' ;
4
3
import { imageInfo } from '../../utils/image.js' ;
@@ -93,11 +92,10 @@ class CodeMirrorEditor {
93
92
}
94
93
95
94
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' ) ;
99
97
100
- if ( ! uploadUrl || ! $files . length ) return ;
98
+ if ( ! uploadUrl || ! filesContainer ) return ;
101
99
102
100
const pastedImages = clipboardPastedImages ( e ) ;
103
101
if ( ! pastedImages || pastedImages . length === 0 ) {
@@ -126,8 +124,12 @@ const uploadClipboardImage = async (editor, dropzone, e) => {
126
124
}
127
125
editor . replacePlaceholder ( placeholder , text ) ;
128
126
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 ) ;
131
133
}
132
134
} ;
133
135
@@ -140,7 +142,7 @@ export function initEasyMDEImagePaste(easyMDE, dropzone) {
140
142
141
143
export function initTextareaImagePaste ( textarea , dropzone ) {
142
144
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 ) ;
145
147
} ) ;
146
148
}
0 commit comments