Jul 22 - Update - add Rich-text editor, draft/publish, drag-to-reorder
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% block title %}{{ 'Edit topic' if topic else 'New topic' }}{% endblock %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link href="{{ url_for('static', filename='vendor/quill.snow.css') }}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
|
||||
{% macro val(field, default='') -%}
|
||||
{%- if form is not none -%}{{ form.get(field, default) }}
|
||||
{%- elif topic is not none -%}{{ topic[field] if topic[field] is not none else default }}
|
||||
@@ -50,9 +54,39 @@
|
||||
<input type="text" name="slug" value="{{ val('slug') }}" placeholder="auto">
|
||||
</label>
|
||||
|
||||
<label class="field">
|
||||
<span>Body <small class="muted">(HTML — use <p>, <strong>, <ul><li>)</small></span>
|
||||
<textarea name="body_html" rows="7">{{ val('body_html') }}</textarea>
|
||||
<div class="field">
|
||||
<span>Body</span>
|
||||
<div id="editor-toolbar" class="ql-tools">
|
||||
<span class="ql-formats">
|
||||
<button class="ql-bold"></button>
|
||||
<button class="ql-italic"></button>
|
||||
<button class="ql-underline"></button>
|
||||
<button class="ql-strike"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-header" value="2"></button>
|
||||
<button class="ql-header" value="3"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-list" value="ordered"></button>
|
||||
<button class="ql-list" value="bullet"></button>
|
||||
<button class="ql-blockquote"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-link"></button>
|
||||
<button class="ql-clean"></button>
|
||||
</span>
|
||||
</div>
|
||||
<div id="editor"></div>
|
||||
<!-- Real field. Quill enhances it; if Quill fails to load, this stays a
|
||||
usable raw-HTML textarea so a save never wipes the body. -->
|
||||
<textarea name="body_html" id="body_src" rows="7">{{ val('body_html') }}</textarea>
|
||||
</div>
|
||||
|
||||
{% set pub = (form.get('is_published') == '1') if form is not none else (topic.is_published if topic else True) %}
|
||||
<label class="field field--check">
|
||||
<input type="checkbox" name="is_published" value="1" {{ 'checked' if pub }}>
|
||||
<span>Published <small class="muted">(uncheck to keep as a draft — hidden from the public site)</small></span>
|
||||
</label>
|
||||
|
||||
<fieldset class="fieldset">
|
||||
@@ -99,3 +133,24 @@
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ url_for('static', filename='vendor/quill.min.js') }}"></script>
|
||||
<script>
|
||||
(function () {
|
||||
if (typeof Quill === 'undefined') return; // textarea stays usable
|
||||
var ta = document.getElementById('body_src');
|
||||
var toolbar = document.getElementById('editor-toolbar');
|
||||
var editorEl = document.getElementById('editor');
|
||||
var quill = new Quill(editorEl, { theme: 'snow', modules: { toolbar: toolbar } });
|
||||
if (ta.value.trim()) quill.clipboard.dangerouslyPasteHTML(ta.value);
|
||||
|
||||
// Switch the UI from textarea to Quill only once it's ready.
|
||||
document.body.classList.add('quill-on');
|
||||
|
||||
ta.form.addEventListener('submit', function () {
|
||||
ta.value = quill.getText().trim().length ? quill.root.innerHTML : '';
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user