mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Move code for deleting old cookies into banner JS
Removes the following cookies: - seen_cookie_message (flags if banner was already shown) - _gid (Google Analytics cookie) - _ga (Google Analytics cookie) These were set by default before so potentially still around for some users. The code for this now exists as a static method on the cookieMessage module and is called when the JS loads for the first time.
This commit is contained in:
@@ -4,6 +4,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|||||||
(function (Modules) {
|
(function (Modules) {
|
||||||
function CookieBanner () { }
|
function CookieBanner () { }
|
||||||
|
|
||||||
|
CookieBanner.clearOldCookies = function () {
|
||||||
|
// clear any cookies set by the previous version
|
||||||
|
var oldCookies = ['seen_cookie_message', '_ga', '_gid'];
|
||||||
|
|
||||||
|
for (var i = 0; i < oldCookies.length; i++) {
|
||||||
|
if (window.GOVUK.cookie(oldCookies[i])) {
|
||||||
|
var cookieString = oldCookies[i] + '=;expires=' + new Date() + ';domain=' + window.location.hostname.replace(/^www\./, '.') + ';path=/';
|
||||||
|
document.cookie = cookieString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
CookieBanner.prototype.start = function ($module) {
|
CookieBanner.prototype.start = function ($module) {
|
||||||
this.$module = $module[0];
|
this.$module = $module[0];
|
||||||
this.$module.hideCookieMessage = this.hideCookieMessage.bind(this);
|
this.$module.hideCookieMessage = this.hideCookieMessage.bind(this);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
window.GOVUK.Frontend.initAll();
|
window.GOVUK.Frontend.initAll();
|
||||||
|
|
||||||
$(() => GOVUK.addCookieMessage());
|
window.GOVUK.Modules.CookieBanner.clearOldCookies();
|
||||||
|
|
||||||
if (window.GOVUK.hasConsentFor('analytics')) {
|
if (window.GOVUK.hasConsentFor('analytics')) {
|
||||||
window.GOVUK.initAnalytics();
|
window.GOVUK.initAnalytics();
|
||||||
|
|||||||
@@ -242,12 +242,4 @@
|
|||||||
<!--[if gt IE 8]><!-->
|
<!--[if gt IE 8]><!-->
|
||||||
<script type="text/javascript" src="{{ asset_url('javascripts/all.js') }}"></script>
|
<script type="text/javascript" src="{{ asset_url('javascripts/all.js') }}"></script>
|
||||||
<!--<![endif]-->
|
<!--<![endif]-->
|
||||||
<script>
|
|
||||||
if (window.GOVUK.cookie('_ga') !== null) {
|
|
||||||
document.cookie = '_ga' + '=;expires=' + new Date() + ';domain=' + window.location.hostname.replace(/^www\./, '.') + ';path=/';
|
|
||||||
}
|
|
||||||
if (window.GOVUK.cookie('_gid') !== null) {
|
|
||||||
document.cookie = '_gid' + '=;expires=' + new Date() + ';domain=' + window.location.hostname.replace(/^www\./, '.') + ';path=/';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user