Skip to content

Commit 02e6b9b

Browse files
authored
ENGCOM-6378: 13865 safari block cookies breaks javascript scripts #25324
2 parents 0c1cead + 70b8e37 commit 02e6b9b

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</referenceBlock>
2424
<referenceContainer name="after.body.start">
2525
<block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
26+
<block class="Magento\Framework\View\Element\Template" name="cookie-status-check" as="cookie-status" template="Magento_Theme::js/cookie_status.phtml" />
2627
</referenceContainer>
2728
</body>
2829
</page>

app/code/Magento/Theme/view/frontend/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var config = {
3030
'welcome': 'Magento_Theme/js/view/welcome',
3131
'breadcrumbs': 'Magento_Theme/js/view/breadcrumbs',
3232
'criticalCssLoader': 'Magento_Theme/js/view/critical-css-loader',
33-
'jquery/ui': 'jquery/compat'
33+
'jquery/ui': 'jquery/compat',
34+
'cookieStatus': 'Magento_Theme/js/cookie-status'
3435
}
3536
},
3637
deps: [
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
8+
<div id="cookie-status" style="display: none">
9+
<?= $block->escapeHtml(__('The store will not work correctly in the case when cookies are disabled.')); ?>
10+
</div>
11+
12+
<script type="text/x-magento-init">
13+
{
14+
"*": {
15+
"cookieStatus": {}
16+
}
17+
}
18+
</script>
19+
20+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
define([
2+
'jquery',
3+
'Magento_Ui/js/modal/modal',
4+
'mage/translate'
5+
], function ($, modal) {
6+
'use strict';
7+
8+
$.widget('mage.cookieStatus', {
9+
options: {
10+
type: 'popup',
11+
responsive: true,
12+
innerScroll: true,
13+
autoOpen: true,
14+
buttons: [{
15+
text: $.mage.__('Close'),
16+
class: 'cookie-status',
17+
18+
/**
19+
* Callback for click event
20+
*/
21+
click: function () {
22+
this.closeModal();
23+
}
24+
}]
25+
},
26+
27+
/**
28+
* Init object
29+
* @private
30+
*/
31+
_init: function () {
32+
33+
if (!navigator.cookieEnabled) {
34+
modal(this.options, $('#cookie-status'));
35+
}
36+
}
37+
});
38+
39+
return $.mage.cookieStatus;
40+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'cookieStatus'
9+
], function ($, Cookie) {
10+
'use strict';
11+
12+
describe('Magento_Theme/js/cookie-status', function () {
13+
var widget,
14+
htmlContainer = '<div id="cookie-status" style="display: none"></div>',
15+
navigator;
16+
17+
beforeEach(function () {
18+
widget = new Cookie();
19+
navigator = window.navigator;
20+
$('.modal-popup').remove();
21+
$('#cookie-status').remove();
22+
$(document.body).append(htmlContainer);
23+
});
24+
25+
afterEach(function () {
26+
window.navigator = navigator;
27+
});
28+
29+
it('defines cookieStatus widget', function () {
30+
expect($.fn.cookieStatus).toBeDefined();
31+
});
32+
33+
it('does not show a modal when cookies are supported', function () {
34+
window.navigator = {
35+
cookieEnabled: true
36+
};
37+
widget._init();
38+
expect($(document.body).html()).not.toContain('<aside role="dialog" class="modal-popup');
39+
});
40+
41+
it('shows the modal when cookies are not supported', function () {
42+
window.navigator = {
43+
cookieEnabled: false
44+
};
45+
widget._init();
46+
expect($(document.body).html()).toContain('<aside role="dialog" class="modal-popup');
47+
});
48+
49+
});
50+
});

0 commit comments

Comments
 (0)