Skip to content

Commit 67bb649

Browse files
committed
Handle animation on thumbs-up when clicked
1 parent f461229 commit 67bb649

6 files changed

Lines changed: 67 additions & 8 deletions

File tree

web/themes/custom/hoeringsportal/assets/css/module/_animated-svg.scss

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ a:has(svg) {
99

1010
display: flex;
1111
gap: var(--sp2);
12+
text-decoration: none;
1213

1314
svg {
1415
/* Comment */
@@ -38,7 +39,7 @@ a:has(svg) {
3839

3940
path:first-of-type {
4041
transform-origin: center left;
41-
transition: stroke 200ms var(--ease-spring-glide);
42+
transition: fill 200ms var(--ease-spring-glide);
4243
}
4344
}
4445
}
@@ -68,15 +69,34 @@ a:has(svg) {
6869
/* Thumbs-up hover */
6970
g.thumbs-up {
7071
path:last-child {
71-
transition: fill 200ms 300ms var(--ease-spring-lazy);
72+
transition: fill 200ms 200ms var(--ease-spring-lazy);
7273
fill: var(--bs-primary);
7374
}
74-
7575
path:first-of-type {
76-
animation:
77-
pop 400ms var(--ease-spring-lazy),
78-
rotate 200ms var(--ease-spring-lazy);
76+
transform: rotate(-3deg);
77+
transition: transform 200ms var(--ease-spring-lazy);
7978
}
8079
}
8180
}
8281
}
82+
83+
/* Click on <a> with thumbs-up svg */
84+
.liked a:has(svg) {
85+
g.thumbs-up {
86+
path:first-of-type {
87+
animation: rotatePop 500ms var(--ease-spring-lazy);
88+
}
89+
path:last-child {
90+
fill: var(--bs-primary);
91+
}
92+
}
93+
}
94+
95+
/* Thumbs-up already set*/
96+
.action-unflag a:has(svg) {
97+
g.thumbs-up {
98+
path:last-child {
99+
fill: var(--bs-primary);
100+
}
101+
}
102+
}

web/themes/custom/hoeringsportal/assets/css/module/_animation.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
}
2929
}
3030

31+
@keyframes rotatePop {
32+
50% {
33+
transform: rotate(10deg) translateX(-1px);
34+
}
35+
75% {
36+
transform: scale(1.2) rotate(-10deg) translateX(-2px);
37+
}
38+
100% {
39+
transform: scale(1);
40+
}
41+
}
42+
3143
@keyframes stretchX {
3244
50% {
3345
transform: scaleX(1.1);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
document.addEventListener(
2+
"click",
3+
function (e) {
4+
// Find the closest <a> tag that's inside .flag-wrapper
5+
const link = e.target.closest(".flag-wrapper");
6+
7+
if (link) {
8+
// Find the child div with the flag classes
9+
const flagDiv = link.querySelector(".flag");
10+
11+
// Only add animation if action-unflag does NOT exist
12+
if (flagDiv && !flagDiv.classList.contains("action-unflag")) {
13+
e.preventDefault();
14+
link.classList.add("liked");
15+
16+
// Cleanup class after animation
17+
window.setTimeout(() => {
18+
link.classList.remove("liked");
19+
}, 400);
20+
} else {
21+
e.preventDefault();
22+
}
23+
}
24+
},
25+
true,
26+
);

web/themes/custom/hoeringsportal/assets/js/hoeringsportal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require("./filter-collapse.js");
1919
require("./icons.js");
2020
require("./modify-dialogue-form.js");
2121
require("./modify-dialogue-proposal-comments.js");
22+
require("./animated-svg.js");
2223

2324
// Enable popovers.
2425
$(function () {

web/themes/custom/hoeringsportal/templates/comment/comment.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</div>
7979
<div class="d-flex mb-2">
8080
<div class="flag-wrapper me-3">{{ content.flag_support_comment }}</div>
81-
<div class="comment-reply"><a class="use-ajax" data-dialog-options="{&quot;width&quot;:400}" data-dialog-type="modal" href="{{ path('comment.reply', {entity_type: 'node', entity: comment.entity_id.value[0].target_id, field_name: 'field_comments', pid: comment.cid.value}) }}">{{ include('themes/custom/hoeringsportal/templates/animated-svg/icon-deltag-reply.svg.html.twig') }}{{ 'Reply'|t({}, {context: 'Comment reply '}) }}</a></div>
81+
<div class="comment-reply"><a class="use-ajax text-secondary" data-dialog-options="{&quot;width&quot;:400}" data-dialog-type="modal" href="{{ path('comment.reply', {entity_type: 'node', entity: comment.entity_id.value[0].target_id, field_name: 'field_comments', pid: comment.cid.value}) }}">{{ include('themes/custom/hoeringsportal/templates/animated-svg/icon-deltag-reply.svg.html.twig') }}{{ 'Reply'|t({}, {context: 'Comment reply '}) }}</a></div>
8282
</div>
8383
{% endif %}
8484
</div>

web/themes/custom/hoeringsportal/templates/content/node--dialogue-proposal--full.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<span class="flag-wrapper">{{ content.flag_support_proposal }}</span>
2525
</div>
2626
<div>
27-
<a href="#comments" class="text-decoration-none text-secondary">{{ include('themes/custom/hoeringsportal/templates/animated-svg/icon-deltag-comment.svg.html.twig') }}<span>{{ node.field_comments.comment_count }}</span><span>{{ 'Comments'|t }}</span></a>
27+
<a href="#comments" class="text-secondary">{{ include('themes/custom/hoeringsportal/templates/animated-svg/icon-deltag-comment.svg.html.twig') }}<span>{{ node.field_comments.comment_count }}</span><span>{{ 'Comments'|t }}</span></a>
2828
</div>
2929
</div>
3030
</div>

0 commit comments

Comments
 (0)