Skip to content

Commit

Permalink
✨ Add inline option to detailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pajowu committed Dec 4, 2024
1 parent 886d97b commit 59a9cbc
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.16 on 2024-12-02 15:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("fds_blog", "0024_alter_category_donation_banner"),
]

operations = [
migrations.AddField(
model_name="detailsboxcmsplugin",
name="inline",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="article",
name="content_template",
field=models.CharField(
choices=[
("fds_blog/_article_detail.html", "Default template"),
("fds_blog/content/_article_no_image.html", "No image in article"),
("fds_blog/content/_article_video_header.html", "Video header"),
],
default="fds_blog/_article_detail.html",
help_text="Template used to display the article's content.",
max_length=250,
verbose_name="content template",
),
),
]
1 change: 1 addition & 0 deletions fragdenstaat_de/fds_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ def __str__(self):
class DetailsBoxCMSPlugin(CMSPlugin):
title = models.CharField(max_length=100, blank=True)
content = models.TextField(blank=True)
inline = models.BooleanField(default=False)


class InfotextboxCMSPlugin(CMSPlugin):
Expand Down
27 changes: 21 additions & 6 deletions fragdenstaat_de/fds_blog/templates/fds_blog/detailsbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
{% load markup %}
{% load static %}
{% load blog_tags %}
<details>
<summary>
<strong>{{ instance.title }}</strong>
</summary>
{{ instance.content|safe }}
</details>
{% spaceless %}
{% if instance.inline %}
{% if request.resolver_match.url_name == "cms_placeholder_edit_plugin" %}
<a class="inline_detailbox--title">{{ instance.title }}⊕</a>
{% else %}
<span class="inline_detailbox">
<a class="inline_detailbox--title">{{ instance.title }}</a>
<template>
<div class="inline_detailbox--content">{{ instance.content|safe }}</div>
</template>
</span>
{% endif %}
{% else %}
<details>
<summary>
<strong>{{ instance.title }}</strong>
</summary>
{{ instance.content|safe }}
</details>
{% endif %}
{% endspaceless %}
1 change: 1 addition & 0 deletions frontend/javascript/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ import './misc/secpol-violation'
import './misc/shuffle-items'
import './misc/userfill-forms'
import './misc/video-modals'
import './misc/inline-detailbox'
11 changes: 11 additions & 0 deletions frontend/javascript/misc/inline-detailbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const containers = document.querySelectorAll('.inline_detailbox')
containers.forEach((container) => {
const template = container.getElementsByTagName('template')[0];
container.addEventListener('click', () => {
if (container.toggleAttribute("expanded")) {
container.appendChild(template.content.cloneNode(true));
} else {
for (const elem of container.getElementsByClassName("inline_detailbox--content")) { container.removeChild(elem) }
}
})
})
20 changes: 19 additions & 1 deletion frontend/styles/blog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ $blog-standout-width: 72rem;
}

> details,
> div.infotextbox {
> div.infotextbox,
.inline_detailbox--content {
color: var(--#{$prefix}primary-text-emphasis);
background-color: var(--#{$prefix}primary-bg-subtle);

Expand All @@ -123,6 +124,10 @@ $blog-standout-width: 72rem;
padding-bottom: 1rem;
}
}

.inline_detailbox--content {
display: flex
}
}

.blog-article .text-container {
Expand Down Expand Up @@ -198,3 +203,16 @@ aside.article-banner {
}
}
}

.inline_detailbox > .inline_detailbox--title::after {
content: "";
}


.inline_detailbox[expanded] > .inline_detailbox--title::after {
content: "";
}

.inline_detailbox {
padding-bottom: 1em;
}

0 comments on commit 59a9cbc

Please sign in to comment.