From f5c29edee438d728c8253d99ea957a873e2f38c6 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Wed, 6 Nov 2024 10:47:19 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07874=20-=20Inline=20image=20deleted=20by?= =?UTF-8?q?=20garbage=20collector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/inlineimage.class.inc.php | 74 --------------------------------- js/ckeditor.handler.js | 76 +++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 108 deletions(-) diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php index 5a7162e09..ce49078ea 100644 --- a/core/inlineimage.class.inc.php +++ b/core/inlineimage.class.inc.php @@ -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 - << '); - $('#'+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( '' ); - } - } - }); - }); -JS - ; - } - public static function EnableCKEditor5ImageUpload(DBObject $oObject, $sTempId){ - return << { 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){