mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
detect span.counter and allow to put styles on the number
This commit is contained in:
parent
730199cca4
commit
ec29758547
@ -25,6 +25,7 @@ import { chill } from './js/chill.js';
|
|||||||
global.chill = chill;
|
global.chill = chill;
|
||||||
|
|
||||||
require('./js/date.js');
|
require('./js/date.js');
|
||||||
|
require('./js/counter.js');
|
||||||
|
|
||||||
/// Load fonts
|
/// Load fonts
|
||||||
require('./fonts/OpenSans/OpenSans.scss')
|
require('./fonts/OpenSans/OpenSans.scss')
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* This script search for span.counter elements like
|
||||||
|
* <span class="counter">Il y a 4 notifications</span>
|
||||||
|
* and return
|
||||||
|
* <span class="counter">Il y a <span>4</span> notifications</span>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const isNum = (v) => !isNaN(v);
|
||||||
|
|
||||||
|
const parseCounter = () => {
|
||||||
|
document.querySelectorAll('span.counter')
|
||||||
|
.forEach(el => {
|
||||||
|
let r = [];
|
||||||
|
el.innerText
|
||||||
|
.trim()
|
||||||
|
.split(' ')
|
||||||
|
.forEach(w => {
|
||||||
|
if (isNum(w)) {
|
||||||
|
r.push(`<span>${w}</span>`);
|
||||||
|
} else {
|
||||||
|
r.push(w);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
;
|
||||||
|
el.innerHTML = r.join(' ');
|
||||||
|
})
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', function (e) {
|
||||||
|
parseCounter();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { parseCounter };
|
@ -82,7 +82,7 @@ div#notification-fold {
|
|||||||
|
|
||||||
// Counter
|
// Counter
|
||||||
div.notification-counter {
|
div.notification-counter {
|
||||||
span {
|
span.counter {
|
||||||
&:not(:first-child) {
|
&:not(:first-child) {
|
||||||
&::before {
|
&::before {
|
||||||
content: '/ ';
|
content: '/ ';
|
||||||
@ -90,3 +90,11 @@ div.notification-counter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
span.counter {
|
||||||
|
& > span {
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: $chill-ll-gray;
|
||||||
|
padding: 0 0.4rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
}
|
@ -73,8 +73,8 @@
|
|||||||
<div class="item-col item-meta">
|
<div class="item-col item-meta">
|
||||||
|
|
||||||
{# TODO twig extension to count comments #}
|
{# TODO twig extension to count comments #}
|
||||||
<div class="comment-counter visually-hidden">
|
<div class="comment-counter">
|
||||||
<span>4 commentaires</span>
|
<span class="counter">4 commentaires</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<div class="notification-counter">
|
<div class="notification-counter">
|
||||||
{% if counter.total > 0 %}
|
{% if counter.total > 0 %}
|
||||||
<span>
|
<span class="counter">
|
||||||
{{ 'notification.counter total notifications'|trans({'total': counter.total }) }}
|
{{ 'notification.counter total notifications'|trans({'total': counter.total }) }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if counter.unread > 0 %}
|
{% if counter.unread > 0 %}
|
||||||
<span>
|
<span class="counter">
|
||||||
{{ 'notification.counter unread notifications'|trans({'unread': counter.unread }) }}
|
{{ 'notification.counter unread notifications'|trans({'unread': counter.unread }) }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user