Skip to content

Commit

Permalink
Use GOVUK cookie helper functions in init
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanita Barrett committed Feb 5, 2020
1 parent 15d4206 commit 1005202
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/global-bar-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ window.GOVUK = window.GOVUK || {}
// Bump this if you are releasing a major change to the banner
// This will reset the view count so all users will see the banner, even if previously seen
var BANNER_VERSION = 3;
var GLOBAL_BAR_SEEN_COOKIE = "global_bar_seen"

var globalBarInit = {
getBannerVersion: function() {
return BANNER_VERSION
},

getLatestCookie: function() {
var currentCookie = document.cookie.match("(?:^|[ ;])(?:global_bar_seen=)(.+?)(?:(?=;|$))")
var currentCookie = window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)

if (currentCookie == null) {
return currentCookie
Expand All @@ -35,13 +36,13 @@ var globalBarInit = {
},

setBannerCookie: function() {
var cookieCategory = window.GOVUK.getCookieCategory("global_bar_seen")
var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BAR_SEEN_COOKIE)
var cookieConsent = GOVUK.getConsentCookie()

if (cookieConsent && cookieConsent[cookieCategory]) {
var value = JSON.stringify({count: 0, version: globalBarInit.getBannerVersion()})

window.GOVUK.setCookie("global_bar_seen", value, {days: 84});
window.GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, value, {days: 84});
}
},

Expand Down

0 comments on commit 1005202

Please sign in to comment.