@@ -13,16 +13,7 @@ define([
13
13
$ . widget ( 'mage.sidebar' , {
14
14
options : {
15
15
isRecursive : true ,
16
- maxItemsVisible : 3 ,
17
- selectorItemQty : ':input.cart-item-qty' ,
18
- selectorItemButton : ':button.update-cart-item' ,
19
- selectorSummaryQty : '.block-content > div.items-total' ,
20
- selectorSubtotal : '.block-content > div.subtotal > div.amount span.price' ,
21
- selectorShowcartNumber : 'a.showcart > span.counter > span.counter-number' ,
22
- selectorShowcartLabel : 'a.showcart > span.counter > span.counter-label' ,
23
- selectorShowcart : 'a.showcart > span.counter' ,
24
- selectorList : '#mini-cart' ,
25
- selectorContentWrapper : '#minicart-content-wrapper'
16
+ maxItemsVisible : 3
26
17
} ,
27
18
scrollHeight : 0 ,
28
19
@@ -35,9 +26,13 @@ define([
35
26
location . href = this . options . url . checkout ;
36
27
} , this ) ) ;
37
28
38
- $ ( this . options . selectorItemQty ) . keyup ( function ( event ) {
29
+ $ ( this . options . item . qty ) . keyup ( function ( event ) {
39
30
self . _showButton ( $ ( this ) ) ;
40
31
} ) ;
32
+ $ ( this . options . item . button ) . click ( function ( event ) {
33
+ event . stopPropagation ( ) ;
34
+ self . _updateQty ( $ ( this ) )
35
+ } ) ;
41
36
42
37
$ ( this . options . button . remove ) . click ( function ( event ) {
43
38
event . stopPropagation ( ) ;
@@ -46,18 +41,6 @@ define([
46
41
}
47
42
} ) ;
48
43
49
- $ ( this . options . selectorItemButton ) . click ( function ( event ) {
50
- event . stopPropagation ( ) ;
51
- self . _updateQty ( $ ( this ) )
52
- } ) ;
53
-
54
- $ ( 'body' ) . on ( 'minicart.update' , function ( event , elem , response ) {
55
- event . stopPropagation ( ) ;
56
- self . _refreshQty ( response . data . summary_qty , response . data . summary_text ) ;
57
- self . _refreshSubtotal ( response . data . subtotal ) ;
58
- self . _refreshShowcart ( response . data . summary_qty , response . data . summary_text ) ;
59
- } ) ;
60
-
61
44
this . _initCloseButton ( ) ;
62
45
this . _calcHeight ( ) ;
63
46
this . _isOverflowed ( ) ;
@@ -82,7 +65,7 @@ define([
82
65
* @private
83
66
*/
84
67
_isOverflowed : function ( ) {
85
- var list = $ ( this . options . selectorList ) ;
68
+ var list = $ ( this . options . minicart . list ) ;
86
69
if ( this . scrollHeight > list . innerHeight ( ) ) {
87
70
list . parent ( ) . addClass ( 'overflowed' ) ;
88
71
} else {
@@ -138,7 +121,9 @@ define([
138
121
*/
139
122
_updateQtyAfter : function ( elem , response ) {
140
123
if ( $ . type ( response . data ) === 'object' ) {
141
- $ ( 'body' ) . trigger ( 'minicart.update' , [ elem , response ] ) ;
124
+ this . _refreshQty ( response . data . summary_qty , response . data . summary_text ) ;
125
+ this . _refreshSubtotal ( response . data . subtotal ) ;
126
+ this . _refreshShowcart ( response . data . summary_qty , response . data . summary_text ) ;
142
127
this . _refreshItemQty ( elem , response . data . summary_qty ) ;
143
128
}
144
129
this . _hideButton ( elem ) ;
@@ -160,11 +145,13 @@ define([
160
145
*/
161
146
_removeItemAfter : function ( elem , response ) {
162
147
if ( $ . type ( response . data ) === 'object' ) {
163
- $ ( 'body' ) . trigger ( 'minicart.update' , [ elem , response ] ) ;
148
+ this . _refreshQty ( response . data . summary_qty , response . data . summary_text ) ;
149
+ this . _refreshSubtotal ( response . data . subtotal ) ;
150
+ this . _refreshShowcart ( response . data . summary_qty , response . data . summary_text ) ;
164
151
}
165
152
if ( response . cleanup === true ) {
166
- $ ( this . options . selectorContentWrapper ) . replaceWith ( $ . trim ( response . content ) ) ;
167
- $ ( this . options . selectorShowcart ) . addClass ( 'empty' ) ;
153
+ $ ( this . options . minicart . content ) . replaceWith ( $ . trim ( response . content ) ) ;
154
+ $ ( this . options . showcart . parent ) . addClass ( 'empty' ) ;
168
155
this . _initCloseButton ( ) ;
169
156
} else {
170
157
elem . closest ( 'li' ) . remove ( ) ;
@@ -218,29 +205,29 @@ define([
218
205
_refreshQty : function ( qty , text ) {
219
206
if ( qty != undefined && text != undefined ) {
220
207
var self = this ;
221
- $ ( this . options . selectorSummaryQty ) . fadeOut ( 'slow' , function ( ) {
222
- $ ( self . options . selectorSummaryQty ) . text ( qty + text ) ;
208
+ $ ( this . options . minicart . qty ) . fadeOut ( 'slow' , function ( ) {
209
+ $ ( self . options . minicart . qty ) . html ( '<span class="count">' + qty + '</span>' + text ) ;
223
210
} ) . fadeIn ( ) ;
224
211
}
225
212
} ,
226
213
227
214
_refreshSubtotal : function ( val ) {
228
215
if ( val != undefined ) {
229
216
var self = this ;
230
- $ ( this . options . selectorSubtotal ) . fadeOut ( 'slow' , function ( ) {
231
- $ ( self . options . selectorSubtotal ) . replaceWith ( val ) ;
217
+ $ ( this . options . minicart . subtotal ) . fadeOut ( 'slow' , function ( ) {
218
+ $ ( self . options . minicart . subtotal ) . replaceWith ( val ) ;
232
219
} ) . fadeIn ( ) ;
233
220
}
234
221
} ,
235
222
236
223
_refreshShowcart : function ( qty , text ) {
237
224
if ( qty != undefined && text != undefined ) {
238
225
var self = this ;
239
- $ ( this . options . selectorShowcartNumber ) . fadeOut ( 'slow' , function ( ) {
240
- $ ( self . options . selectorShowcartNumber ) . text ( qty ) ;
226
+ $ ( this . options . showcart . qty ) . fadeOut ( 'slow' , function ( ) {
227
+ $ ( self . options . showcart . qty ) . text ( qty ) ;
241
228
} ) . fadeIn ( ) ;
242
- $ ( this . options . selectorShowcartLabel ) . fadeOut ( 'slow' , function ( ) {
243
- $ ( self . options . selectorShowcartLabel ) . text ( text ) ;
229
+ $ ( this . options . showcart . label ) . fadeOut ( 'slow' , function ( ) {
230
+ $ ( self . options . showcart . label ) . text ( text ) ;
244
231
} ) . fadeIn ( ) ;
245
232
}
246
233
} ,
@@ -254,7 +241,7 @@ define([
254
241
var self = this ,
255
242
height = 0 ,
256
243
counter = this . options . maxItemsVisible ,
257
- target = $ ( this . options . selectorList )
244
+ target = $ ( this . options . minicart . list )
258
245
. clone ( )
259
246
. attr ( 'style' , 'position: absolute !important; top: -10000 !important;' )
260
247
. appendTo ( 'body' ) ;
@@ -269,7 +256,7 @@ define([
269
256
270
257
target . remove ( ) ;
271
258
272
- $ ( this . options . selectorList ) . css ( 'height' , height ) ;
259
+ $ ( this . options . minicart . list ) . css ( 'height' , height ) ;
273
260
}
274
261
} ) ;
275
262
0 commit comments