-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
notices.js
42 lines (37 loc) · 1.2 KB
/
notices.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* @api
*/
define([
'jquery',
'jquery-ui-modules/widget',
'mage/cookies'
], function ($) {
'use strict';
$.widget('mage.cookieNotices', {
/** @inheritdoc */
_create: function () {
if ($.mage.cookies.get(this.options.cookieName)) {
this.element.hide();
} else {
this.element.show();
}
$(this.options.cookieAllowButtonSelector).on('click', $.proxy(function () {
var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);
$.mage.cookies.set(this.options.cookieName, JSON.stringify(this.options.cookieValue), {
expires: cookieExpires
});
if ($.mage.cookies.get(this.options.cookieName)) {
this.element.hide();
$(document).trigger('user:allowed:save:cookie');
} else {
window.location.href = this.options.noCookiesUrl;
}
}, this));
}
});
return $.mage.cookieNotices;
});