Make Hero Banner closable (#6333) [deploy]

* feat: set up an event handler that will allow close the banner and set a cookie when you've closed it

* feat: return early if the cookie says it shouldn't be shown

* refactor: make the names more general so that they can be applied to other campaigns
This commit is contained in:
Ridhwana 2020-02-27 19:06:37 +02:00 committed by GitHub
parent da133bcbb5
commit 55909afdc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -45,8 +45,8 @@ function callInitalizers(){
initializeCreditsPage();
initializeUserProfilePage();
initializePodcastPlayback();
initializeDrawerSliders();
initializeHeroBannerClose();
function freezeScrolling(event){
event.preventDefault();

View file

@ -0,0 +1,13 @@
'use strict';
function initializeHeroBannerClose() {
let banner = document.getElementById("js-hero-banner");
let closeIcon = document.getElementById("js-hero-banner__x");
if (banner && closeIcon) {
closeIcon.onclick = (e) => {
document.cookie = "heroBanner=false";
banner.style.display = "none";
}
}
}

View file

@ -56,7 +56,7 @@ class StoriesController < ApplicationController
private
def assign_hero_html
return if SiteConfig.campaign_hero_html_variant_name.blank?
return if SiteConfig.campaign_hero_html_variant_name.blank? || cookies[:heroBanner] == "false"
@hero_html = HtmlVariant.relevant.select(:html).
find_by(group: "campaign", name: SiteConfig.campaign_hero_html_variant_name)&.html