Skip to content

Commit

Permalink
proper notifications init
Browse files Browse the repository at this point in the history
  • Loading branch information
hotdoy committed Jan 12, 2020
1 parent 9732934 commit 227e3dd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
13 changes: 11 additions & 2 deletions css/notify.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@
padding: 0.2rem 2rem;
min-height: 4rem;
border-radius: 8px;
background-color: var(--bg-color-alt);
color: var(--fg-color-alt);
background-color: var(--bg-color);
color: var(--fg-color);
box-shadow: var(--shadow-2);
transition: all 0.5s;
z-index: 5000;
}

div[data-notify]{
display: none;
}

.notify *{
margin: 0;
}

.notify a{
color: inherit;
text-decoration: underline;
}

.notify__done{
position: absolute;
top: 5px;
Expand Down
16 changes: 16 additions & 0 deletions js/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ function notify(message, bg_color, fg_color, id){
$('body').append(notice);
}
}


$( document ).ready(function() {
let notifications = document.querySelectorAll('[data-notify]');
notifications.forEach(n => {
let message = n.innerHTML;
let bgcolor = n.getAttribute('data-bgcolor');
let fgcolor = n.getAttribute('data-fgcolor');
let id = n.getAttribute('data-id');

if (!!message) {
notify(message,bgcolor,fgcolor, id);
}

});
});
19 changes: 17 additions & 2 deletions templates/partials/notifications.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
{% for n in p.header.notifications if n.visible == true %}
{% set content = n.content|markdown %}
{% set id = n.remember ? n.id %}
{% set remember = n.remember %}
{% set bg_color = n.bg_color %}
{% set fg_color = n.fg_color %}

{% if n.target %}
{% for t in n.target if t == page.rawroute %}
<script>notify("{{ content }}", "{{ bg_color }}", "{{ fg_color }}", "{{ id }}");</script>
<div
data-notify
data-bgcolor="{{ bg_color }}"
data-fgcolor="{{ fg_color }}"
{% if id and remember %}data-id="{{ id }}"{% endif %}>
{{ content }}
</div>
{% endfor %}

{% else %}
<script>notify("{{ content }}", "{{ bg_color }}", "{{ fg_color }}", "{{ id }}");</script>
<div
data-notify
data-bgcolor="{{ bg_color }}"
data-fgcolor="{{ fg_color }}"
{% if id and remember %}data-id="{{ id }}"{% endif %}>
{{ content }}
</div>
{% endif %}
{% endfor %}
{% endfor %}

0 comments on commit 227e3dd

Please sign in to comment.