@@ -12,57 +12,63 @@ define([
12
12
] , function ( Component , customerData , $ , ko , _ ) {
13
13
'use strict' ;
14
14
15
- var sidebarInitialized = false ;
16
- var addToCartCalls = 0 ;
15
+ var sidebarInitialized = false ,
16
+ addToCartCalls = 0 ,
17
+ miniCart ;
17
18
18
- var minicart = $ ( " [data-block='minicart']" ) ;
19
- minicart . on ( 'dropdowndialogopen' , function ( ) {
19
+ miniCart = $ ( ' [data-block=\ 'minicart\']' ) ;
20
+ miniCart . on ( 'dropdowndialogopen' , function ( ) {
20
21
initSidebar ( ) ;
21
22
} ) ;
22
23
24
+ /**
25
+ * @return {Boolean }
26
+ */
23
27
function initSidebar ( ) {
24
- if ( minicart . data ( 'mageSidebar' ) ) {
25
- minicart . sidebar ( 'update' ) ;
28
+ if ( miniCart . data ( 'mageSidebar' ) ) {
29
+ miniCart . sidebar ( 'update' ) ;
26
30
}
27
31
28
32
if ( ! $ ( '[data-role=product-item]' ) . length ) {
29
33
return false ;
30
34
}
31
- minicart . trigger ( 'contentUpdated' ) ;
35
+ miniCart . trigger ( 'contentUpdated' ) ;
36
+
32
37
if ( sidebarInitialized ) {
33
38
return false ;
34
39
}
35
40
sidebarInitialized = true ;
36
- minicart . sidebar ( {
37
- " targetElement" : " div.block.block-minicart" ,
38
- " url" : {
39
- " checkout" : window . checkout . checkoutUrl ,
40
- " update" : window . checkout . updateItemQtyUrl ,
41
- " remove" : window . checkout . removeItemUrl ,
42
- " loginUrl" : window . checkout . customerLoginUrl ,
43
- " isRedirectRequired" : window . checkout . isRedirectRequired
41
+ miniCart . sidebar ( {
42
+ ' targetElement' : ' div.block.block-minicart' ,
43
+ ' url' : {
44
+ ' checkout' : window . checkout . checkoutUrl ,
45
+ ' update' : window . checkout . updateItemQtyUrl ,
46
+ ' remove' : window . checkout . removeItemUrl ,
47
+ ' loginUrl' : window . checkout . customerLoginUrl ,
48
+ ' isRedirectRequired' : window . checkout . isRedirectRequired
44
49
} ,
45
- " button" : {
46
- " checkout" : " #top-cart-btn-checkout" ,
47
- " remove" : " #mini-cart a.action.delete" ,
48
- " close" : " #btn-minicart-close"
50
+ ' button' : {
51
+ ' checkout' : ' #top-cart-btn-checkout' ,
52
+ ' remove' : ' #mini-cart a.action.delete' ,
53
+ ' close' : ' #btn-minicart-close'
49
54
} ,
50
- " showcart" : {
51
- " parent" : " span.counter" ,
52
- " qty" : " span.counter-number" ,
53
- " label" : " span.counter-label"
55
+ ' showcart' : {
56
+ ' parent' : ' span.counter' ,
57
+ ' qty' : ' span.counter-number' ,
58
+ ' label' : ' span.counter-label'
54
59
} ,
55
- "minicart" : {
56
- "list" : "#mini-cart" ,
57
- "content" : "#minicart-content-wrapper" ,
58
- "qty" : "div.items-total" ,
59
- "subtotal" : "div.subtotal span.price"
60
+ 'minicart' : {
61
+ 'list' : '#mini-cart' ,
62
+ 'content' : '#minicart-content-wrapper' ,
63
+ 'qty' : 'div.items-total' ,
64
+ 'subtotal' : 'div.subtotal span.price' ,
65
+ 'maxItemsVisible' : window . checkout . minicartMaxItemsVisible
60
66
} ,
61
- " item" : {
62
- " qty" : " :input.cart-item-qty" ,
63
- " button" : " :button.update-cart-item"
67
+ ' item' : {
68
+ ' qty' : ' :input.cart-item-qty' ,
69
+ ' button' : ' :button.update-cart-item'
64
70
} ,
65
- " confirmMessage" : $ . mage . __ (
71
+ ' confirmMessage' : $ . mage . __ (
66
72
'Are you sure you would like to remove this item from the shopping cart?'
67
73
)
68
74
} ) ;
@@ -87,7 +93,7 @@ define([
87
93
this . update ( updatedCart ) ;
88
94
initSidebar ( ) ;
89
95
} , this ) ;
90
- $ ( '[data-block="minicart"]' ) . on ( 'contentLoading' , function ( event ) {
96
+ $ ( '[data-block="minicart"]' ) . on ( 'contentLoading' , function ( event ) {
91
97
addToCartCalls ++ ;
92
98
self . isLoading ( true ) ;
93
99
} ) ;
@@ -96,14 +102,24 @@ define([
96
102
} ,
97
103
isLoading : ko . observable ( false ) ,
98
104
initSidebar : initSidebar ,
99
- closeSidebar : function ( ) {
105
+
106
+ /**
107
+ * @return {Boolean }
108
+ */
109
+ closeSidebar : function ( ) {
100
110
var minicart = $ ( '[data-block="minicart"]' ) ;
101
- minicart . on ( 'click' , '[data-action="close"]' , function ( event ) {
111
+ minicart . on ( 'click' , '[data-action="close"]' , function ( event ) {
102
112
event . stopPropagation ( ) ;
103
- minicart . find ( '[data-role="dropdownDialog"]' ) . dropdownDialog ( " close" ) ;
113
+ minicart . find ( '[data-role="dropdownDialog"]' ) . dropdownDialog ( ' close' ) ;
104
114
} ) ;
115
+
105
116
return true ;
106
117
} ,
118
+
119
+ /**
120
+ * @param {String } productType
121
+ * @return {*|String }
122
+ */
107
123
getItemRenderer : function ( productType ) {
108
124
return this . itemRenderer [ productType ] || 'defaultRenderer' ;
109
125
} ,
0 commit comments