Skip to content

Commit

Permalink
Merge pull request #347 from localgovdrupal/fix/1.x-271-cookie
Browse files Browse the repository at this point in the history
Remove js-cookie dependancy
  • Loading branch information
andybroomfield authored Jul 11, 2024
2 parents 6f95d61 + 32bf9d4 commit f6579f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 14 additions & 5 deletions js/alert_banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
* This is so if the alert changes, the banner is reshown.
*/

(function($, cookies) {
(function($) {

'use strict';

function setAlertBannerHideCookie(cookie_tokens, token) {
cookie_tokens.push(token);
var new_cookie = cookie_tokens.join('+')
cookies.set('hide-alert-banner-token', new_cookie, { path: '/', expires: 30, SameSite: 'Lax' });
var new_cookie = cookie_tokens.join('+');
// Set expiry 30 days.
var expiry = Date.now() + (30 * 24 * 60 * 60 * 1000);
document.cookie = 'hide-alert-banner-token=' + new_cookie + '; expires=' + Date(expiry).toString() + '; SameSite=Lax;'
}

$(document).ready(function() {

var cookie = cookies.get('hide-alert-banner-token');
var all_cookies = document.cookie.split(';');
var cookie = '';
for (var i = 0; i < all_cookies.length; i++) {
var indv_cookie = all_cookies[i].split('=');
if (indv_cookie[0] == 'hide-alert-banner-token') {
cookie = indv_cookie[1];
}
}
var cookie_tokens = typeof cookie !== 'undefined' ? cookie.split('+') : [];

$('.js-localgov-alert-banner').each(function() {
Expand All @@ -37,4 +46,4 @@

});

}) (jQuery, window.Cookies);
}) (jQuery);
1 change: 0 additions & 1 deletion localgov_alert_banner.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ alert_banner:
js/alert_banner.js: {}
dependencies:
- core/jquery
- core/js-cookie

0 comments on commit f6579f0

Please sign in to comment.