From 65f8f03fc0734ab50914628ca227e7f24afdd481 Mon Sep 17 00:00:00 2001 From: Esenjin Date: Sat, 15 Feb 2025 19:24:18 +0100 Subject: [PATCH] =?UTF-8?q?les=20images=20s'h=C3=A9bergent=20correctement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/story-edit.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/assets/js/story-edit.js b/assets/js/story-edit.js index d831cb9..5e44b69 100644 --- a/assets/js/story-edit.js +++ b/assets/js/story-edit.js @@ -49,11 +49,41 @@ document.addEventListener('DOMContentLoaded', function() { ['clean'] ], handlers: { - 'divider': function() { - const range = quill.getSelection(true); - quill.insertText(range.index, '\n', Quill.sources.USER); - quill.insertEmbed(range.index + 1, 'divider', true, Quill.sources.USER); - quill.setSelection(range.index + 2, Quill.sources.SILENT); + image: function() { + const input = document.createElement('input'); + input.setAttribute('type', 'file'); + input.setAttribute('accept', 'image/*'); + input.click(); + + input.onchange = async () => { + const file = input.files[0]; + if (file) { + const formData = new FormData(); + formData.append('image', file); + formData.append('storyId', storyId); + + try { + const response = await fetch('api/upload-image.php', { + method: 'POST', + body: formData + }); + + if (!response.ok) throw new Error('Upload failed'); + + const result = await response.json(); + if (result.success) { + const range = quill.getSelection(true); + quill.insertEmbed(range.index, 'image', result.url); + quill.setSelection(range.index + 1); + } else { + showNotification(result.error || 'Erreur lors de l\'upload', 'error'); + } + } catch (error) { + console.error('Error:', error); + showNotification('Erreur lors de l\'upload de l\'image', 'error'); + } + } + }; } } },