Skip to content

Commit

Permalink
BIG-21501 - EU Cookie warning
Browse files Browse the repository at this point in the history
* Add event listener that will handle when the cookie is accepted from the client side application if the cookie event was prevented.
* refactored function to ES6 style function definition.
  • Loading branch information
Mick Ryan committed Dec 18, 2015
1 parent fb1c282 commit eeaa4a0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/api/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default class extends Base
*/
privacyNotificationCheck() {
const alreadyAcceptedCookies = document.cookie.indexOf('ACCEPT_COOKIE_USAGE') !== -1;
let cookieStr;

if (alreadyAcceptedCookies) {
return;
}
Expand All @@ -31,7 +33,7 @@ export default class extends Base
const date = new Date();
const event = {
defaultPrevented: false,
preventDefault: function() {
preventDefault() {
this.defaultPrevented = true;
},
};
Expand All @@ -41,12 +43,16 @@ export default class extends Base
}

date.setDate(date.getDate() + 365);

document.cookie = `ACCEPT_COOKIE_USAGE=1;expires=${date.toGMTString()}; path=/`;

cookieStr = `ACCEPT_COOKIE_USAGE=1;expires=${date.toGMTString()}; path=/`;
Hooks.emit('cookie-privacy-notification', event, response.data.PrivacyCookieNotification);

if (!event.defaultPrevented) {
// Set up handler to listen if the cookie was accepted.
if (event.defaultPrevented) {
Hooks.on('cookie-privacy-accepted', () => {
document.cookie = cookieStr;
});
} else {
document.cookie = cookieStr;
alert(response.data.PrivacyCookieNotification);
}
}
Expand Down

0 comments on commit eeaa4a0

Please sign in to comment.