l'éditeur de la description de roman arrive désormais à héberger les images correctement
This commit is contained in:
parent
4d27f4579a
commit
3afd26333f
@ -162,7 +162,49 @@ function generateSlug($title) {
|
||||
<script src="../assets/js/story-edit.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Configuration de l'éditeur de description - identique à l'éditeur de chapitres
|
||||
// Configuration de l'éditeur de description
|
||||
// Récupérer le storyId depuis l'input caché ou l'URL
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const currentStoryId = document.querySelector('input[name="id"]')?.value || urlParams.get('id');
|
||||
|
||||
// Configuration des handlers pour les images
|
||||
const imageUploadHandler = (editor) => {
|
||||
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', currentStoryId);
|
||||
|
||||
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 = editor.getSelection(true);
|
||||
editor.insertEmbed(range.index, 'image', result.url);
|
||||
editor.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');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const descriptionEditor = new Quill('#descriptionEditor', {
|
||||
theme: 'snow',
|
||||
modules: {
|
||||
@ -184,40 +226,7 @@ function generateSlug($title) {
|
||||
],
|
||||
handlers: {
|
||||
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 = descriptionEditor.getSelection(true);
|
||||
descriptionEditor.insertEmbed(range.index, 'image', result.url);
|
||||
descriptionEditor.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');
|
||||
}
|
||||
}
|
||||
};
|
||||
imageUploadHandler(descriptionEditor);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user