-
- var id = "image-" + Math.random().toString(16).slice(2);
- var loadingImage = window.baseUrl('/loading.gif');
- editor.execCommand('mceInsertContent', false, '<img src="'+ loadingImage +'" id="' + id + '">');
-
- var remoteFilename = "image-" + Date.now() + "." + ext;
- formData.append('file', file, remoteFilename);
- formData.append('_token', document.querySelector('meta[name="token"]').getAttribute('content'));
-
- xhr.open('POST', window.baseUrl('/images/gallery/upload'));
- xhr.onload = function () {
- if (xhr.status === 200 || xhr.status === 201) {
- var result = JSON.parse(xhr.responseText);
- editor.dom.setAttrib(id, 'src', result.thumbs.display);
- } else {
- console.log('An error occurred uploading the image');
- console.log(xhr.responseText);
- editor.dom.remove(id);
- }
- };
- xhr.send(formData);