From dbca0698bf1cd6eb710ac5608c8ca4f8116f7702 Mon Sep 17 00:00:00 2001 From: "E. S." Date: Sat, 16 Mar 2024 00:46:36 +0000 Subject: [PATCH] admin: post editing: automatically set textarea height --- htdocs/js/admin/11-write-form.js | 13 ++++++++++++- skin/admin.phps | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/htdocs/js/admin/11-write-form.js b/htdocs/js/admin/11-write-form.js index ed742b3..dc7fede 100644 --- a/htdocs/js/admin/11-write-form.js +++ b/htdocs/js/admin/11-write-form.js @@ -6,6 +6,7 @@ function AdminWriteEditForm(opts) { this.form = document.forms[this.isPage() ? 'pageForm' : 'postForm']; this.previewTimeout = null; this.previewRequest = null; + this.firstPreviewShowDone = false; this.tocByLang = {}; if (!this.isEditing() && this.isPost()) { @@ -91,7 +92,17 @@ extend(AdminWriteEditForm.prototype, { if (err) return console.error(err); ge('preview_html').innerHTML = response.html; - }); + if (!this.firstPreviewShowDone && this.isEditing() && this.isPost()) { + window.requestAnimationFrame(function() { + var taHeight = this.form.text.getBoundingClientRect().height; + var blogPostHeight = ge('blog_post').getBoundingClientRect().height - 70; + if (blogPostHeight > taHeight) { + setStyle(this.form.text, {height: blogPostHeight + 'px'}); + } + }.bind(this)) + this.firstPreviewShowDone = true; + } + }.bind(this)); }, showError: function(code, message) { diff --git a/skin/admin.phps b/skin/admin.phps index 6d50e54..24b8295 100644 --- a/skin/admin.phps +++ b/skin/admin.phps @@ -424,8 +424,7 @@ HTML; function markdownPreview($ctx, $unsafe_html, $title) { return << -
+
{$ctx->if_true($title, '

'.$title.'

')}
{$unsafe_html}