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'); + } + } + }; } } },