fix editor for short_story and chapters

This commit is contained in:
2026-05-01 21:53:43 +03:00
parent ce6fffaa57
commit b69a110b97
4 changed files with 88 additions and 142 deletions
+6 -13
View File
@@ -5,7 +5,7 @@ include 'views/layouts/header.php';
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="col-lg-10">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Создание новой книги</h1>
<a href="<?= SITE_URL ?>/books" class="btn btn-outline-secondary">
@@ -109,10 +109,10 @@ include 'views/layouts/header.php';
<h5 class="card-title mb-0">Содержание рассказа</h5>
</div>
<div class="card-body">
<div id="story-editor" style="height: 400px;" data-content="<?= htmlspecialchars($_POST['content'] ?? '', ENT_QUOTES) ?>">
<div id="quill-editor" style="height: 400px;" data-content="<?= htmlspecialchars($_POST['content'] ?? '', ENT_QUOTES) ?>">
<?= $_POST['content'] ?? '' ?>
</div>
<input type="hidden" name="content" id="story-content" <?= !empty($_POST['content']) ? 'value="' . htmlspecialchars($_POST['content'], ENT_QUOTES) . '"' : '' ?>>
<input type="hidden" name="content" id="content" <?= !empty($_POST['content']) ? 'value="' . htmlspecialchars($_POST['content'], ENT_QUOTES) . '"' : '' ?>>
</div>
</div>
@@ -141,18 +141,11 @@ function toggleStoryEditor() {
storyCard.style.display = isShortStory ? 'block' : 'none';
if (isShortStory && !window.writerEditor) {
initQuillEditor(true);
} else if (!isShortStory && window.writerEditor) {
window.writerEditor.quill.destroy();
window.writerEditor = new WriterEditor('#book-form', 'quill-editor', 'content');
} else if (!isShortStory && window.writerEditor && window.writerEditor.quill) {
try { window.writerEditor.quill.destroy(); } catch(e) {}
window.writerEditor = null;
}
if (isShortStory && window.writerEditor && window.writerEditor.quill) {
setTimeout(() => {
window.writerEditor.quill.root.style.height = '400px';
window.writerEditor.quill.container.style.height = '400px';
}, 100);
}
}
}
+20 -1
View File
@@ -76,6 +76,24 @@ include 'views/layouts/header.php';
rows="4"><?= e($book['description'] ?? '') ?></textarea>
</div>
<div class="mb-3">
<label for="cover_image" class="form-label">Обложка книги</label>
<?php if (!empty($book['cover_image'])): ?>
<div class="mb-2">
<img src="<?= COVERS_URL . e($book['cover_image']) ?>"
alt="Обложка"
class="img-thumbnail"
style="max-height: 150px;">
<div class="form-text">Текущая обложка</div>
</div>
<?php endif; ?>
<input type="file" class="form-control" id="cover_image" name="cover_image"
accept="image/jpeg,image/png,image/gif,image/webp">
<div class="form-text">
Разрешены форматы: JPG, PNG, GIF, WebP. Максимальный размер: 5MB. Оставьте пустым, чтобы оставить текущую обложку.
</div>
</div>
<div class="mb-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="published" name="published" value="1"
@@ -109,7 +127,7 @@ include 'views/layouts/header.php';
</h5>
</div>
<div class="card-body">
<div id="story-editor" style="height: 500px;" data-content="<?= htmlspecialchars($book['content'] ?? '', ENT_QUOTES) ?>"></div>
<div id="quill-editor" style="height: 500px;" data-content="<?= htmlspecialchars($book['content'] ?? '', ENT_QUOTES) ?>"></div>
<textarea name="content" id="content" style="display: none;"><?= htmlspecialchars($book['content'] ?? '', ENT_QUOTES) ?></textarea>
</div>
</div>
@@ -181,6 +199,7 @@ include 'views/layouts/header.php';
</form>
<script src="<?= SITE_URL ?>/assets/js/editor.js"></script>
<script src="<?= SITE_URL ?>/assets/js/autosave.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {