Files
ForME/templates/edit.html

43 lines
1.7 KiB
HTML

{% extends 'base.html' %}
{% block content %}
<h1>Редактирование страницы #{{ page.id }}</h1>
<form method="post">
<div class="row">
<label for="title">Название страницы</label>
<input type="text" id="title" name="title" value="{{ page.title }}" />
</div>
<div class="row">
<label for="html">HTML-код</label>
<textarea id="html" name="html" required>{{ page.html }}</textarea>
</div>
<div class="row">
<button class="btn" type="submit">Сохранить</button>
<a class="btn secondary" href="{{ url_for('admin') }}" style="margin-left:8px;">Отмена</a>
</div>
</form>
<div class="row" style="margin-top: 1.25rem;">
<div class="muted" style="margin-bottom: .5rem;">Моментальный предпросмотр</div>
<iframe id="preview" style="width:100%; height:320px; border:1px solid rgba(255,255,255,.08); border-radius:12px; background:#fff;"></iframe>
</div>
<script>
(function(){
const htmlEl = document.getElementById('html');
const titleEl = document.getElementById('title');
const iframe = document.getElementById('preview');
function render(){
const doc = iframe.contentDocument || iframe.contentWindow.document;
const t = (titleEl && titleEl.value) ? `<title>${titleEl.value}</title>` : '';
doc.open();
doc.write(`<!doctype html><html lang=\"ru\"><head><meta charset=\"utf-8\">${t}</head><body>${htmlEl.value}</body></html>`);
doc.close();
}
htmlEl.addEventListener('input', render);
if (titleEl) titleEl.addEventListener('input', render);
render();
})();
</script>
{% endblock %}