-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3005: adding a banner snippet in the header that appears on every pag…
…e of the site (#2144) * Add notification - semi working * format models * Format migration * banner works * format migration * format * Remove console output * fix * comments for close button sizing and placement
- Loading branch information
1 parent
cd457e4
commit 2c79e46
Showing
10 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 3.2.23 on 2024-03-27 14:37 | ||
|
||
from django.db import migrations, models | ||
import wagtail.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cms", "0034_add_search_image_to_course_and_program_page"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SiteBanner", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("message", wagtail.fields.RichTextField(max_length=255)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.banners { | ||
position: relative; | ||
z-index: 1; | ||
|
||
// HACK: Using this rule to get around styling issues with <p> elements in the | ||
// notification content (notification content in Wagtail is configured to be HTML, | ||
// and Wagtail wraps content in a <p> tag by default when you use the editor). | ||
&.site-wide { | ||
p { | ||
margin: 0; | ||
} | ||
} | ||
|
||
// Django-rendered implementation | ||
.banner { | ||
background: $primary; | ||
text-align: center; | ||
color: white; | ||
height: 60px; | ||
padding: 15px 20px 15px 20px; | ||
background: linear-gradient(180deg, #A31F34 0%, #700934 100%); | ||
|
||
font-family: Inter; | ||
font-size: 18px; | ||
font-weight: 500; | ||
|
||
p a { | ||
color: white; | ||
text-decoration: underline; | ||
background-color: transparent; | ||
} | ||
|
||
} | ||
|
||
.close-banner { | ||
text-decoration: none; | ||
color: white; | ||
float: right; | ||
height: 30px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
&:after { | ||
content: "cancel"; | ||
font-family: Material Icons; | ||
font-size: 30px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*eslint-env jquery*/ | ||
/*eslint semi: ["error", "always"]*/ | ||
|
||
function renderSiteBanner() { | ||
const bannerId = $(".banner").data("banner-id"); | ||
if (bannerId) { | ||
if (localStorage.getItem("dismissedbanner") !== bannerId.toString()) { | ||
$(".banners").removeClass("d-none"); | ||
} | ||
} | ||
} | ||
|
||
export default function banner() { | ||
renderSiteBanner(); | ||
|
||
$(".banners").on("click", ".close-banner", function(e) { | ||
e.preventDefault(); | ||
const $banner = $(this).closest(".banner"); | ||
localStorage.setItem("dismissedbanner", $banner.data("banner-id")); | ||
$banner.remove(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="banners site-wide d-none"> | ||
{% if banner %} | ||
<div class="banner" data-banner-id="{{ banner.id }}"> | ||
<a href="#" class="close-banner"></a> | ||
{{ banner|safe }} | ||
</div> | ||
{% endif %} | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Templatetags for rendering site banner""" | ||
|
||
from django import template | ||
from cms.models import SiteBanner | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.inclusion_tag("../templates/partials/banner.html", takes_context=True) | ||
def banner(context): | ||
"""Return request context and banner.""" | ||
|
||
return { | ||
"banner": SiteBanner.objects.order_by("-id").first(), | ||
"request": context["request"], | ||
} |