Uses details to show/hide content warning field

This commit is contained in:
Mouse Reeve 2022-03-10 09:03:24 -08:00
parent e2476d1ad3
commit a922b8fd04
3 changed files with 32 additions and 38 deletions

View file

@ -1,22 +1,33 @@
{% load i18n %}
<div
class="field{% if not reply_parent.content_warning and not draft.content_warning %} is-hidden{% endif %}"
id="spoilers_{{ uuid }}{{ local_uuid }}"
>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Content warning:" %}
</label>
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
<div class="field is-relative">
<details
{% if reply_parent.content_warning or draft.content_warning %}open{% endif %}
>
<summary class="is-flex">
<span class="icon icon-warning is-size-5 mr-1" aria-hidden="true"></span>
<span>
{% trans "Include spoiler alert" %}
</span>
<span class="details-close icon icon-plus" aria-hidden="true"></span>
</summary>
<label
class="label"
for="id_content_warning_{{ uuid }}{{ local_uuid }}"
>
{% trans "Content warning:" %}
</label>
<div class="control">
<input
type="text"
name="content_warning"
maxlength="255"
class="input"
id="id_content_warning_{{ uuid }}{{ local_uuid }}"
placeholder="{% trans 'Spoilers ahead!' %}"
value="{% firstof draft.content_warning reply_parent.content_warning '' %}"
{% if not draft %}data-cache-draft="id_content_warning_{{ book.id }}_{{ type }}"{% endif %}
>
</div>
</details>
</div>

View file

@ -1,17 +0,0 @@
{% load i18n %}
<div class="control">
<input
type="checkbox"
class="is-hidden"
name="sensitive"
id="id_show_spoilers_{{ uuid }}{{ local_uuid }}"
{% if draft.content_warning or status.content_warning %}checked{% endif %}
aria-hidden="true"
{% if not draft %}data-cache-draft="id_sensitive_{{ book.id }}_{{ type }}{{ reply_parent.id }}"{% endif %}
>
{% trans "Include spoiler alert" as button_text %}
{% firstof draft.content_warning status.content_warning as pressed %}
{% firstof local_uuid '' as local_uuid %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid|add:local_uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=pressed %}
</div>

View file

@ -37,8 +37,6 @@ reply_parent: the Status object this post will be in reply to, if applicable
{% endif %}
{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{# fields that go between the content warnings and the content field (ie, quote) #}
{% block pre_content_additions %}{% endblock %}
@ -55,6 +53,8 @@ reply_parent: the Status object this post will be in reply to, if applicable
{# additional fields that go after the content block (ie, progress) #}
{% block post_content_additions %}{% endblock %}
{% include "snippets/create_status/content_warning_field.html" %}
{% block options_block %}
{# cw, post privacy, and submit button #}
{% include "snippets/create_status/post_options_block.html" %}