diff --git a/app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml b/app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml index ab4dabfa6d1a0..a4a10ef3f6ee9 100644 --- a/app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml +++ b/app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml @@ -23,6 +23,7 @@ + diff --git a/app/code/Magento/Theme/view/frontend/requirejs-config.js b/app/code/Magento/Theme/view/frontend/requirejs-config.js index c41a0602ef3e8..b5ffd358c893b 100644 --- a/app/code/Magento/Theme/view/frontend/requirejs-config.js +++ b/app/code/Magento/Theme/view/frontend/requirejs-config.js @@ -30,7 +30,8 @@ var config = { 'welcome': 'Magento_Theme/js/view/welcome', 'breadcrumbs': 'Magento_Theme/js/view/breadcrumbs', 'criticalCssLoader': 'Magento_Theme/js/view/critical-css-loader', - 'jquery/ui': 'jquery/compat' + 'jquery/ui': 'jquery/compat', + 'cookieStatus': 'Magento_Theme/js/cookie-status' } }, deps: [ diff --git a/app/code/Magento/Theme/view/frontend/templates/js/cookie_status.phtml b/app/code/Magento/Theme/view/frontend/templates/js/cookie_status.phtml new file mode 100644 index 0000000000000..2da71c90b5657 --- /dev/null +++ b/app/code/Magento/Theme/view/frontend/templates/js/cookie_status.phtml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/app/code/Magento/Theme/view/frontend/web/js/cookie-status.js b/app/code/Magento/Theme/view/frontend/web/js/cookie-status.js new file mode 100644 index 0000000000000..3726996a862c6 --- /dev/null +++ b/app/code/Magento/Theme/view/frontend/web/js/cookie-status.js @@ -0,0 +1,40 @@ +define([ + 'jquery', + 'Magento_Ui/js/modal/modal', + 'mage/translate' +], function ($, modal) { + 'use strict'; + + $.widget('mage.cookieStatus', { + options: { + type: 'popup', + responsive: true, + innerScroll: true, + autoOpen: true, + buttons: [{ + text: $.mage.__('Close'), + class: 'cookie-status', + + /** + * Callback for click event + */ + click: function () { + this.closeModal(); + } + }] + }, + + /** + * Init object + * @private + */ + _init: function () { + + if (!navigator.cookieEnabled) { + modal(this.options, $('#cookie-status')); + } + } + }); + + return $.mage.cookieStatus; +}); diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Theme/view/frontend/web/js/cookie-status.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Theme/view/frontend/web/js/cookie-status.test.js new file mode 100644 index 0000000000000..67ba24fe3bcfb --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Theme/view/frontend/web/js/cookie-status.test.js @@ -0,0 +1,50 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'cookieStatus' +], function ($, Cookie) { + 'use strict'; + + describe('Magento_Theme/js/cookie-status', function () { + var widget, + htmlContainer = '', + navigator; + + beforeEach(function () { + widget = new Cookie(); + navigator = window.navigator; + $('.modal-popup').remove(); + $('#cookie-status').remove(); + $(document.body).append(htmlContainer); + }); + + afterEach(function () { + window.navigator = navigator; + }); + + it('defines cookieStatus widget', function () { + expect($.fn.cookieStatus).toBeDefined(); + }); + + it('does not show a modal when cookies are supported', function () { + window.navigator = { + cookieEnabled: true + }; + widget._init(); + expect($(document.body).html()).not.toContain('