Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: donation banner tweaks #7703

Merged
merged 12 commits into from
Dec 5, 2022
Merged
64 changes: 57 additions & 7 deletions scss/_off.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1157,13 +1157,63 @@ span.ico-bold {
@include button( 10, $white);
}

#donate_image_banner_outside {
margin-bottom:1rem;
background: no-repeat url(/images/illustrations/donate-heart.svg)
}

#donate_image_banner_inside {
@media only screen and (max-width: 100rem) {margin-left:140px;}
#donate-banner {
position: relative;
display: flex;
padding: 2rem 0;
background-color: #6D85D9;
@media #{$small-only} {
flex-direction: column;
&__content {
flex-direction: column;
.banner-content {
order: 1;
flex-direction: column;
p {
text-align: center;
margin: 1rem;
}
}
.button { order: 2; }
}
}
p { color: $white; }
&__image {
display: block;
content: "";
background: no-repeat url(/images/illustrations/donate-heart.svg);
min-width: 150px;
height: 81px;
}
&__content {
display: inline-flex;
align-items: center;
gap: 2rem;
.banner-content {
display: flex;
flex-direction: column;
}
.banner__close {
width: 32px;
height: 32px;
.banner__close--icon {
position: absolute;
top: 0; right: 0;
margin: 1rem;
color: $white;
opacity: .5;
cursor: pointer;
}
}
& label > span { visibility: hidden; }
> .button {
display: inline-flex !important;
flex-direction: row;
align-items: center;
gap: 8px;
margin-bottom: 0;
}
}
}

.footer_social_icon {
Expand Down
111 changes: 63 additions & 48 deletions templates/web/common/includes/donate_banner.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,69 @@

[% IF banner %]

<div id="donate_banner" class="block black short" style="background-color:#6D85D9">

<div id="donate_image_banner_outside">
<div class="row hide-for-small">

<div id="donate_image_banner_inside">

<a href="[% link %]?utm_source=off&utm_medium=web&utm_campaign=donate-2022&utm_term=en-text-button" class="button round white-button" style="float:left;margin-right:2rem;">
<span class="material-icons material-symbols-button">volunteer_activism</span>
[% lang('donation_cta') %]
</a>

<p class="">[% f_lang('donation_body_employees', { number_of_employees => '7' }) %]<br>
[% f_lang('donation_why_year', { year => '2022' }) %] <strong>[% lang('thank_you') %] <span style="color:red">❤️</span></strong>
</p>
<input id="hide_image_banner" type="checkbox" style="margin-top:1.5rem;margin-bottom:0;">
<label for="hide_image_banner">
<span id="hide_image_banner_hide"class="text-white">[% lang('donation_banner_hide') %]</span>
</label>

</div>
</div>

<div class="row hide-for-medium-up">

<div id="donate_image_banner_inside" style="min-height:90px;padding-top:10px;">

<a href="[% link %]?utm_source=off&utm_medium=web&utm_campaign=donate-2022&utm_term=en-text-button" class="button round white-button" style="float:left;margin-right:2rem;">
<span class="material-icons material-symbols-button">volunteer_activism</span>
[% lang('donation_cta') %]
</a>
</div>

<div class="small-12 columns">
<p class="">[% f_lang('donation_body_employees', { number_of_employees => '7' }) %]<br>
[% f_lang('donation_why_year', { year => '2022' }) %] <strong>[% lang('thank_you') %] <span style="color:red">❤️</span></strong>
</p>
<input id="hide_image_banner" type="checkbox" style="margin-top:1.5rem;margin-bottom:0;">
<label for="hide_image_banner">
<span id="hide_image_banner_hide"class="text-white">[% lang('donation_banner_hide') %]</span>
</label>

</div>
</div>

</div>

</div>
<section id="donate-banner">
<span id="donate-banner__image"></span>
<div id="donate-banner__content">
<a href="[% link %]?utm_source=off&utm_medium=web&utm_campaign=donate-2022&utm_term=en-text-button"
class="button round white-button">
<span class="material-icons">volunteer_activism</span>
[% lang('donation_cta') %]
</a>
<div class="banner-content">
<p>[% f_lang('donation_body_employees', { number_of_employees => '7' }) %] [% f_lang('donation_why_year', { year => '2022' }) %]</p>
<p>[% lang('thank_you') %] <span>❤️</span></p>
</div>
<div class="banner__close">
<span id="hide-donate-banner" onclick="DonationButton();" class="material-icons banner__close--icon">close</span>
</div>
</div>
</section>

<script>
let d = new Date();
let expires = 'expires=' + d.toUTCString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we don't need this any-more ?

let bannerID = document.getElementById('donate-banner');
let bcval = "1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we don't need this any-more ?


function setBannerCookie(bcname, bcval, bcexdays) {
d.setTime(d.getTime() + (bcexdays*60*60*24*1000));
let expires = 'expires=' + d.toUTCString();
document.cookie = bcname + '=' + bcval + ';' + expires + ';path=/';
console.log(expires);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this :-)

Suggested change
console.log(expires);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot about those! Thank you, I will remove it soon, also unused vars and logs.

}


function deleteBannerCookie(bcname) {
d.setTime(d.getTime() + (60*60*24*1000));
let expires = 'expires=' + d.toUTCString();
document.cookie = bcname + '=;' + expires + ';path=/';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this, and not only call setBannerCookie ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's like a double-check for me - cleans the cookie value and set expire for current time, if you feel like it is not really important I can test the code without it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it's ok if we keep it, but maybe a comment to explain is good :-)


function getBannerCookie(bcname) {
let name = bcname + '=';
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') { c = c.substring(1); }
if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); }
}
return '';
}

function DonationButton() {
deleteBannerCookie('off-donation-banner');
setBannerCookie('off-donation-banner', 1, 14);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems to me 14 days is not enough, it's a bit pushy to users.

If I donate, I would expect this not to show up again for at least 180 days !

If possible, I would set it on whole openfoodfacts.xx subdomain (not only for eg. world) (that is you can set domain to the last two components of domain).

@teolemon what is your though ?

bannerID.style.display = 'none';
}

if (getBannerCookie('off-donation-banner') != '') {
bannerID.style.display = 'none';
} else {
bannerID.style.display = 'flex';
}
</script>

[% END %]

<!-- end templates/[% component.name %] -->