mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°7874 - Inline image deleted by garbage collector
This commit is contained in:
@@ -541,80 +541,6 @@ JS
|
||||
CombodoCKEditorHandler.EnableImageUpload('#' + $(this).attr('id'), '$sAbsoluteUrlAppRoot'+'pages/ajax.render.php?operation=cke_img_upload&temp_id=$sTempId&obj_class=$sObjClass&obj_key=$iObjKey');
|
||||
});
|
||||
JS;
|
||||
|
||||
return
|
||||
<<<JS
|
||||
// Hook the file upload of all CKEditor instances
|
||||
$('.htmlEditor').each(function() {
|
||||
var oEditor = $(this).ckeditorGet();
|
||||
oEditor.config.filebrowserBrowseUrl = '$sAbsoluteUrlAppRoot'+'pages/ajax.render.php?operation=cke_browse&temp_id=$sTempId&obj_class=$sObjClass&obj_key=$iObjKey';
|
||||
oEditor.on( 'fileUploadResponse', function( evt ) {
|
||||
var fileLoader = evt.data.fileLoader;
|
||||
var xhr = fileLoader.xhr;
|
||||
var data = evt.data;
|
||||
try {
|
||||
var response = JSON.parse( xhr.responseText );
|
||||
|
||||
// Error message does not need to mean that upload finished unsuccessfully.
|
||||
// It could mean that ex. file name was changes during upload due to naming collision.
|
||||
if ( response.error && response.error.message ) {
|
||||
data.message = response.error.message;
|
||||
}
|
||||
|
||||
// But !uploaded means error.
|
||||
if ( !response.uploaded ) {
|
||||
evt.cancel();
|
||||
} else {
|
||||
data.fileName = response.fileName;
|
||||
data.url = response.url;
|
||||
|
||||
// Do not call the default listener.
|
||||
evt.stop();
|
||||
}
|
||||
} catch ( err ) {
|
||||
// Response parsing error.
|
||||
data.message = fileLoader.lang.filetools.responseError;
|
||||
window.console && window.console.log( xhr.responseText );
|
||||
|
||||
evt.cancel();
|
||||
}
|
||||
} );
|
||||
|
||||
oEditor.on( 'fileUploadRequest', function( evt ) {
|
||||
evt.data.fileLoader.uploadUrl += '?operation=cke_img_upload&temp_id=$sTempId&obj_class=$sObjClass';
|
||||
}, null, null, 4 ); // Listener with priority 4 will be executed before priority 5.
|
||||
|
||||
oEditor.on( 'instanceReady', function() {
|
||||
if(!CKEDITOR.env.iOS && $('#'+oEditor.id+'_toolbox .ibo-vendors-ckeditor--toolbar-fullscreen-button').length == 0)
|
||||
{
|
||||
$('#'+oEditor.id+'_toolbox').append('<span class="ibo-vendors-ckeditor--toolbar-fullscreen-button editor-fullscreen-button" data-role="ibo-vendors-ckeditor--toolbar-fullscreen-button" title="$sToggleFullScreen"> </span>');
|
||||
$('#'+oEditor.id+'_toolbox .ibo-vendors-ckeditor--toolbar-fullscreen-button').on('click', function() {
|
||||
oEditor.execCommand('maximize');
|
||||
if ($(this).closest('.cke_maximized').length != 0)
|
||||
{
|
||||
$('#'+oEditor.id+'_toolbar_collapser').trigger('click');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (oEditor.widgets.registered.uploadimage)
|
||||
{
|
||||
oEditor.widgets.registered.uploadimage.onUploaded = function( upload ) {
|
||||
var oData = JSON.parse(upload.xhr.responseText);
|
||||
this.replaceWith( '<img src="' + upload.url + '" ' +
|
||||
'width="' + oData.width + '" ' +
|
||||
'height="' + oData.height + '">' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
JS
|
||||
;
|
||||
}
|
||||
public static function EnableCKEditor5ImageUpload(DBObject $oObject, $sTempId){
|
||||
return <<<JS
|
||||
// Hook the file upload of all CKEditor instances
|
||||
JS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
const CombodoCKEditorHandler = {
|
||||
instances: {},
|
||||
instances_promise: {},
|
||||
is_upload_configured: {},
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -46,6 +47,8 @@ const CombodoCKEditorHandler = {
|
||||
// prepare configuration
|
||||
CombodoCKEditorHandler.PrepareConfiguration(sElem, aConfiguration);
|
||||
|
||||
this.is_upload_configured[sElem] = false;
|
||||
// create instance
|
||||
return this.instances_promise[sElem] = new Promise((resolve, reject) => {
|
||||
ClassicEditor.create($(sElem)[0], aConfiguration)
|
||||
.then(editor => {
|
||||
@@ -96,45 +99,50 @@ const CombodoCKEditorHandler = {
|
||||
GetInstanceSynchronous: function(sElem) {
|
||||
return this.instances[sElem];
|
||||
},
|
||||
EnableImageUpload: async function(sElem, sUrl){
|
||||
EnableImageUpload: async function (sElem, sUrl) {
|
||||
if (this.is_upload_configured[sElem]) {
|
||||
return;
|
||||
}
|
||||
const editor = await this.GetInstance(sElem);
|
||||
class SimpleUploadAdapter {
|
||||
constructor(loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
upload() {
|
||||
return this.loader.file
|
||||
.then(file => new Promise((resolve, reject) => {
|
||||
// Replace 'your-upload-url' with your server-side upload endpoint
|
||||
const uploadUrl = sUrl;
|
||||
class SimpleUploadAdapter {
|
||||
constructor(loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('upload', file);
|
||||
upload() {
|
||||
return this.loader.file
|
||||
.then(file => new Promise((resolve, reject) => {
|
||||
// Replace 'your-upload-url' with your server-side upload endpoint
|
||||
const uploadUrl = sUrl;
|
||||
|
||||
CombodoHTTP.Fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(responseData => {
|
||||
if (responseData.uploaded) {
|
||||
resolve({ default: responseData.url });
|
||||
} else {
|
||||
reject(responseData.error.message || 'Upload failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject('Upload failed due to a network error.');
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('upload', file);
|
||||
|
||||
// Enable the custom upload adapter
|
||||
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
||||
return new SimpleUploadAdapter(loader);
|
||||
};
|
||||
CombodoHTTP.Fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(responseData => {
|
||||
if (responseData.uploaded) {
|
||||
resolve({default: responseData.url});
|
||||
} else {
|
||||
reject(responseData.error.message || 'Upload failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject('Upload failed due to a network error.');
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the custom upload adapter
|
||||
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
||||
return new SimpleUploadAdapter(loader);
|
||||
};
|
||||
this.is_upload_configured[sElem] = true;
|
||||
},
|
||||
InsertHtmlInsideInstance: function(sElem, sHtml){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user