diff options
author | Zarino Zappia <mail@zarino.co.uk> | 2020-03-18 16:48:12 +0000 |
---|---|---|
committer | Zarino Zappia <mail@zarino.co.uk> | 2020-03-24 09:43:39 +0000 |
commit | 724dde2244262d9a51ba55203a9f63c6e6a345f8 (patch) | |
tree | a61f412c3b72933188b9a692bbed5b52a4e07fc1 | |
parent | aaca9c44a2f2e5726e07dfc49175868d54139583 (diff) |
[fixmystreet.com] Survey banner
Big purple survey banner, which is hidden by default, and shown on 40%
of pageloads, by JavaScript.
Works on both the static pages, and the map pages.
Clicking the CTA button, or the close icon, hides the banner and sets
a cookie so that the banner isn’t shown again on that device.
Banner is always hidden during the mobile reporting flow.
Fixes #2928.
-rw-r--r-- | templates/web/fixmystreet.com/before_wrapper.html | 26 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/_survey-banner.scss | 124 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/base.scss | 1 |
3 files changed, 151 insertions, 0 deletions
diff --git a/templates/web/fixmystreet.com/before_wrapper.html b/templates/web/fixmystreet.com/before_wrapper.html new file mode 100644 index 000000000..9fc07343b --- /dev/null +++ b/templates/web/fixmystreet.com/before_wrapper.html @@ -0,0 +1,26 @@ +<div class="survey-banner"> + <p> + <span class="survey-banner__text">Share your views and help us improve FixMyStreet for everyone</span> + <a class="survey-banner__cta" href="https://www.surveygizmo.com/s3/5506345/46e9932d0fbf" target="_blank">Take our short survey</a> + </p> + <button class="survey-banner__close">Close</button> +</div> +<script nonce="[% csp_nonce %]"> +(function(){ + var live_site = location.hostname === 'www.fixmystreet.com'; + var hasnt_opted_out = document.cookie.indexOf('__has_closed_march_2020_survey') === -1; + var randomly_chosen = Math.random() > 0.6; + if ( live_site && hasnt_opted_out && randomly_chosen ) { + document.body.className = ((document.body.className) ? document.body.className + ' has-survey-banner' : 'has-survey-banner'); + document.querySelector('.survey-banner').style.display = 'block'; + } + function hide_survey(){ + document.querySelector('.survey-banner').style.display = 'none'; + document.body.className = document.body.className.replace('has-survey-banner', ''); + var t = new Date(); t.setFullYear(t.getFullYear() + 1); + document.cookie = '__has_closed_march_2020_survey=1; path=/; expires=' + t.toUTCString(); + } + document.querySelector('.survey-banner__close').onclick = hide_survey; + document.querySelector('.survey-banner__cta').onclick = hide_survey; +})(); +</script> diff --git a/web/cobrands/fixmystreet.com/_survey-banner.scss b/web/cobrands/fixmystreet.com/_survey-banner.scss new file mode 100644 index 000000000..a3db76ba4 --- /dev/null +++ b/web/cobrands/fixmystreet.com/_survey-banner.scss @@ -0,0 +1,124 @@ +.survey-banner { + display: none; // will get shown by javascript + background: #A94CA6; + color: #fff; + position: relative; + z-index: 1; // stack in front of the page top border + text-align: center; + padding: 0 2.5em; // make space for the close button + + .map-reporting & { + display: none !important; + } + + p { + margin: 0; + padding: 12px 0; // 12px vertical padding, plus 4px margin on childen = 16px = 1em + line-height: 1.3; + } +} + +.survey-banner__text, +.survey-banner__cta { + display: inline-block; + margin: 4px 8px; +} + +.survey-banner__text { + font-size: 0.9em; +} + +.survey-banner__cta { + font-size: 0.8em; + font-weight: bold; + background: #fff; + color: #000; + padding: 0.4em 1em; + border-radius: 3em; + text-decoration: none; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4); + + &:visited { + color: #000; + } + + &:focus { + outline: none; + box-shadow: 0 0 0 4px $primary; + } + + &:hover, + &:active { + background: mix(#A94CA6, #fff, 10%); + color: #000; + text-decoration: none; + } +} + +.survey-banner__close { + display: block; + position: absolute; + top: 0.5em; + right: 0.5em; + + width: 2em; + height: 0; + padding-top: 2em; + overflow: hidden; + + color: #fff; + background: transparent; + border: none; + + &:before { + display: block; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + content: "\00d7"; + font-size: 2em; + } + + @media screen and (min-width: 48em) { + top: 50%; + right: 0.75em; + transform: translate(0, -50%); + } +} + + +@media screen and (min-width: 48em) { + .mappage.has-survey-banner { + $mappage-header-height: 4em !default; + $banner-height: 3.5em; + + .survey-banner { + p { + display: flex; + justify-content: center; + align-items: center; + height: $banner-height; + padding-top: 0; + padding-bottom: 0; + } + } + + #site-header { + top: 0 + $banner-height; + } + + #map_box, + #map_sidebar { + top: $mappage-header-height + $banner-height; + } + + .nav-wrapper { + @if ($header-top-border) { + top: $header-top-border-width + $banner-height; + } @else { + top: 0 + $banner-height; + } + } + } +} diff --git a/web/cobrands/fixmystreet.com/base.scss b/web/cobrands/fixmystreet.com/base.scss index f261e677d..e17a7e4cf 100644 --- a/web/cobrands/fixmystreet.com/base.scss +++ b/web/cobrands/fixmystreet.com/base.scss @@ -176,6 +176,7 @@ svg|g.site-logo__svg { border-bottom: none; } +@import "survey-banner"; $mysoc-footer-background-color: #222; $mysoc-footer-text-color: #acacac; |