From beb73b58f3be2c7fb651bc8f613d2a8c0311912e Mon Sep 17 00:00:00 2001
From: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com>
Date: Mon, 21 Jun 2021 09:01:35 -0500
Subject: [PATCH] FEATURE: Add fireworks + gradient animation to campaign
success banner (#77)
---
.../components/campaign-banner.js.es6 | 22 +-
.../templates/components/campaign-banner.hbs | 32 ++-
assets/stylesheets/common/campaign.scss | 265 +++++++++++++++++-
config/locales/client.en.yml | 2 +
4 files changed, 298 insertions(+), 23 deletions(-)
diff --git a/assets/javascripts/discourse/components/campaign-banner.js.es6 b/assets/javascripts/discourse/components/campaign-banner.js.es6
index 536f83e..61c0ab1 100644
--- a/assets/javascripts/discourse/components/campaign-banner.js.es6
+++ b/assets/javascripts/discourse/components/campaign-banner.js.es6
@@ -4,6 +4,7 @@ import { equal } from "@ember/object/computed";
import { setting } from "discourse/lib/computed";
import Component from "@ember/component";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
+import { later } from "@ember/runloop";
import { inject as service } from "@ember/service";
export default Component.extend({
@@ -31,6 +32,7 @@ export default Component.extend({
showContributors: setting(
"discourse_subscriptions_campaign_show_contributors"
),
+ classNameBindings: ["isGoalMet:goal-met"],
init() {
this._super(...arguments);
@@ -69,6 +71,25 @@ export default Component.extend({
} else {
document.body.classList.remove("subscription-campaign-sidebar");
}
+
+ // makes sure to only play animation once, & not repeat on reload
+ if (this.isGoalMet) {
+ const successAnimationKey = this.keyValueStore.get(
+ "campaign_success_animation"
+ );
+
+ if (!successAnimationKey) {
+ later(() => {
+ this.keyValueStore.set({
+ key: "campaign_success_animation",
+ value: Date.now(),
+ });
+ document.body.classList.add("success-animation-off");
+ }, 7000);
+ } else {
+ document.body.classList.add("success-animation-off");
+ }
+ }
},
@discourseComputed(
@@ -130,7 +151,6 @@ export default Component.extend({
const currentVolume = this.subscriberGoal
? this.subscribers
: this.amountRaised;
-
return currentVolume >= this.goalTarget;
},
diff --git a/assets/javascripts/discourse/templates/components/campaign-banner.hbs b/assets/javascripts/discourse/templates/components/campaign-banner.hbs
index 99de413..d2b3ce4 100644
--- a/assets/javascripts/discourse/templates/components/campaign-banner.hbs
+++ b/assets/javascripts/discourse/templates/components/campaign-banner.hbs
@@ -12,21 +12,31 @@
var(--campaign-background-image);
background-size: cover;
background-repeat: no-repeat;' ''}}">
-
+ {{#if isGoalMet}}
+
+
{{#if isGoalMet}}
-
{{i18n 'discourse_subscriptions.campaign.goal'}}!
+
+
{{#if subscriberGoal}}
{{i18n 'discourse_subscriptions.campaign.goal_comparison' current=subscribers goal=goalTarget}}
diff --git a/assets/stylesheets/common/campaign.scss b/assets/stylesheets/common/campaign.scss
index 59877ae..287b334 100644
--- a/assets/stylesheets/common/campaign.scss
+++ b/assets/stylesheets/common/campaign.scss
@@ -97,6 +97,10 @@ body.archetype-regular {
border: 1px solid var(--primary-low);
position: relative;
align-items: stretch;
+ @media screen and (max-width: 400px) {
+ width: 98%;
+ flex-direction: column;
+ }
.btn.close {
position: absolute;
top: 1em;
@@ -122,11 +126,11 @@ body.archetype-regular {
align-items: center;
}
@media screen and (max-width: 400px) {
- width: 100%;
- display: grid;
- grid-template-columns: 60% auto;
- grid-template-areas: "left right" "left right";
+ width: calc(100% - 4em);
+ display: flex;
+ flex-direction: column;
align-items: center;
+ padding-bottom: 1em;
}
&-header {
font-size: $font-up-6;
@@ -145,6 +149,9 @@ body.archetype-regular {
@media screen and (max-width: 750px) {
font-size: $font-down-1;
}
+ @media screen and (max-width: 400px) {
+ text-align: center;
+ }
}
&-button {
grid-area: right;
@@ -170,16 +177,21 @@ body.archetype-regular {
width: 60%;
padding: 1.5em 2em 1.5em;
@media screen and (max-width: 400px) {
- display: none;
+ width: calc(100% - 4em);
}
&-success {
- font-size: $font-up-1;
- text-align: center;
- background-color: var(--tertiary);
- color: var(--secondary);
- padding: 0.25em;
+ height: 32px;
+ background: linear-gradient(
+ -45deg,
+ var(--tertiary-hover),
+ var(--tertiary-medium),
+ var(--tertiary-hover),
+ var(--tertiary-medium)
+ );
border-radius: 2em;
margin: 0;
+ background-size: 400% 100%;
+ animation: gradient 15s ease infinite;
}
&-description {
margin: 0.5em 0 0;
@@ -236,7 +248,7 @@ body.archetype-regular {
html:not(.mobile-view) .subscriptions-campaign-topic-footer .campaign-banner {
margin-top: 2em;
height: min-content;
- width: calc(100% + 5em);
+ width: calc(100% + 14em);
.btn.close {
top: 1em;
right: 1em;
@@ -264,3 +276,234 @@ html:not(.mobile-view) .subscriptions-campaign-topic-footer .campaign-banner {
}
}
}
+
+// CSS Animations for campaign Success
+@keyframes gradient {
+ 0% {
+ background-position: 0% 50%;
+ }
+ 50% {
+ background-position: 100% 50%;
+ }
+ 100% {
+ background-position: 0% 50%;
+ }
+}
+
+/* Fireworks
+ Copyright (c) 2020 by Eddie Lin (https://codepen.io/yshlin/pen/ylDEk)
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+$particles: 50;
+$width: 500;
+$height: 250;
+
+$sidebar-particles: 25;
+$sidebar-width: 300;
+$sidebar-height: 100;
+
+// Create the explosion...
+$box-shadow: ();
+$box-shadow2: ();
+
+$sidebar-box-shadow: ();
+$sidebar-box-shadow2: ();
+
+@for $i from 0 through $particles {
+ $box-shadow: $box-shadow,
+ random($width)-$width /
+ 2 +
+ px
+ random($height)-$height /
+ 1.2 +
+ px
+ hsl(random(360), 100, 50);
+ $box-shadow2: $box-shadow2, 0 0 #fff;
+}
+
+@for $i from 0 through $sidebar-particles {
+ $sidebar-box-shadow: $sidebar-box-shadow,
+ random($sidebar-width)-$sidebar-width /
+ 2 +
+ px
+ random($sidebar-height)-$sidebar-height /
+ 1.2 +
+ px
+ hsl(random(360), 100, 50);
+ $sidebar-box-shadow2: $sidebar-box-shadow2, 0 0 #fff;
+}
+
+@mixin keyframes($animationName) {
+ @-webkit-keyframes #{$animationName} {
+ @content;
+ }
+
+ @-moz-keyframes #{$animationName} {
+ @content;
+ }
+
+ @-o-keyframes #{$animationName} {
+ @content;
+ }
+
+ @-ms-keyframes #{$animationName} {
+ @content;
+ }
+
+ @keyframes #{$animationName} {
+ @content;
+ }
+}
+
+@mixin animation-delay($settings) {
+ -moz-animation-delay: $settings;
+ -webkit-animation-delay: $settings;
+ -o-animation-delay: $settings;
+ -ms-animation-delay: $settings;
+ animation-delay: $settings;
+}
+
+@mixin animation-duration($settings) {
+ -moz-animation-duration: $settings;
+ -webkit-animation-duration: $settings;
+ -o-animation-duration: $settings;
+ -ms-animation-duration: $settings;
+ animation-duration: $settings;
+}
+
+@mixin animation($settings) {
+ -moz-animation: $settings;
+ -webkit-animation: $settings;
+ -o-animation: $settings;
+ -ms-animation: $settings;
+ animation: $settings;
+}
+
+@mixin transform($settings) {
+ transform: $settings;
+ -moz-transform: $settings;
+ -webkit-transform: $settings;
+ -o-transform: $settings;
+ -ms-transform: $settings;
+}
+
+body:not(.archetype-regular):not(.success-animation-off) {
+ .fireworks > .before,
+ .fireworks > .after {
+ position: absolute;
+ width: 5px;
+ height: 5px;
+ border-radius: 50%;
+ box-shadow: $box-shadow2;
+ @include animation(
+ (
+ 1s bang ease-out 1s 5 backwards,
+ 1s gravity ease-in 1s 5 backwards,
+ 5s position ease-in-out 1s 1 backwards
+ )
+ );
+ }
+}
+
+body.subscription-campaign-sidebar:not(.archetype-regular):not(.success-animation-off) {
+ .fireworks > .before,
+ .fireworks > .after {
+ position: absolute;
+ width: 5px;
+ height: 5px;
+ border-radius: 50%;
+ box-shadow: $sidebar-box-shadow2;
+ animation: name duration timing-function delay iteration-count direction
+ fill-mode;
+ @include animation(
+ (
+ 1s sidebarbang ease-out 1s 5 backwards,
+ 1s gravity ease-in 1s 5 backwards,
+ 5s sidebarposition ease-in-out 1s 1 backwards
+ )
+ );
+ }
+}
+
+.fireworks > .after {
+ @include animation-delay((1.25s, 1.25s, 1.25s));
+ @include animation-duration((1.25s, 1.25s, 1.25s));
+}
+
+@include keyframes(bang) {
+ to {
+ box-shadow: $box-shadow;
+ }
+}
+
+@include keyframes(sidebarbang) {
+ to {
+ box-shadow: $sidebar-box-shadow;
+ }
+}
+
+@include keyframes(gravity) {
+ to {
+ @include transform(translateY(200px));
+ opacity: 0;
+ }
+}
+
+@include keyframes(position) {
+ 0%,
+ 19.9% {
+ margin-top: -2%;
+ margin-left: -43%;
+ }
+ 20%,
+ 39.9% {
+ margin-top: 2%;
+ margin-left: -18%;
+ }
+ 40%,
+ 59.9% {
+ margin-top: 0%;
+ margin-left: 0%;
+ }
+ 60%,
+ 79.9% {
+ margin-top: 4%;
+ margin-left: 18%;
+ }
+ 80%,
+ 99.9% {
+ margin-top: 6%;
+ margin-left: 56%;
+ }
+}
+
+@include keyframes(sidebarposition) {
+ 0%,
+ 19.9% {
+ margin-top: -25%;
+ margin-left: 0%;
+ }
+ 20%,
+ 39.9% {
+ margin-top: -25%;
+ margin-left: 25%;
+ }
+ 40%,
+ 59.9% {
+ margin-top: -25%;
+ margin-left: 50%;
+ }
+ 60%,
+ 79.9% {
+ margin-top: -25%;
+ margin-left: 75%;
+ }
+ 80%,
+ 99.9% {
+ margin-top: -25%;
+ margin-left: 100%;
+ }
+}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index df509ba..e16c786 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -34,6 +34,8 @@ en:
campaign:
title: Support Us
body: We need your help to keep this community up and running!
+ success_title: Success!
+ success_body: Thank you for your help in keeping this community up and running!
subscribers: Subscribers
goal_comparison: "%{current} of %{goal}"
raised: Raised