tinyMCE has an insert image button, but how to handle its functionality pls give some code
I know it is an old question. However, I think this answer may help somebody who wants to upload multiple images by using tinyMCE 5.xx. Based on @Chris Lear's and @stephen.hanson's answer, I modify some code to support multiple images uploading. Here is my code. Hope it could help somebody.
tinymce.init({
toolbar: 'imageupload',
setup: function(editor) {
initImageUpload(editor);
}
});
function initImageUpload(editor) {
// create input and insert in the DOM
var inp = $(``);
$(editor.getElement()).parent().append(inp);
// add the image upload button to the editor toolbar
editor.addButton('imageupload', {
text:'IMAGE',
onAction: function(_) {
// when toolbar button is clicked, open file select modal
inp.trigger('click');
}
});
// when a file is selected, upload it to the server
inp.on('change',function(){
for(let i=0;i {
if (res.status = 200) {
editor.insertContent('');
// clear data to avoid uploading same data not working in the second time
inp.val('');
}
})
}