File tree Expand file tree Collapse file tree 5 files changed +113
-1
lines changed
app/code/Magento/Theme/view/frontend
dev/tests/js/jasmine/tests/app/code/Magento/Theme/view/frontend/web/js Expand file tree Collapse file tree 5 files changed +113
-1
lines changed Original file line number Diff line number Diff line change 23
23
</referenceBlock >
24
24
<referenceContainer name =" after.body.start" >
25
25
<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" />
26
27
</referenceContainer >
27
28
</body >
28
29
</page >
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ var config = {
30
30
'welcome' : 'Magento_Theme/js/view/welcome' ,
31
31
'breadcrumbs' : 'Magento_Theme/js/view/breadcrumbs' ,
32
32
'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'
34
35
}
35
36
} ,
36
37
deps : [
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments