@@ -31,29 +31,31 @@ define([
31
31
32
32
this . element . decorate ( 'list' , this . options . isRecursive ) ;
33
33
34
- // Add event on "Go to Checkout" button click
35
- $ ( this . options . checkoutButton ) . on ( 'click' , $ . proxy ( function ( ) {
36
- location . href = this . options . checkoutUrl ;
34
+ $ ( this . options . button . checkout ) . on ( 'click' , $ . proxy ( function ( ) {
35
+ location . href = this . options . url . checkout ;
37
36
} , this ) ) ;
38
37
39
- // Add event on "Remove item" click
40
- $ ( this . options . removeButton ) . click ( function ( event ) {
38
+ $ ( this . options . selectorItemQty ) . keyup ( function ( event ) {
39
+ self . _showButton ( $ ( this ) ) ;
40
+ } ) ;
41
+
42
+ $ ( this . options . button . remove ) . click ( function ( event ) {
41
43
event . stopPropagation ( ) ;
42
44
if ( confirm ( self . options . confirmMessage ) ) {
43
45
self . _removeItem ( $ ( this ) ) ;
44
46
}
45
47
} ) ;
46
48
47
- // Add event on "Qty" field changed
48
- $ ( this . options . selectorItemQty ) . change ( function ( event ) {
49
+ $ ( this . options . selectorItemButton ) . click ( function ( event ) {
49
50
event . stopPropagation ( ) ;
50
- self . _showButton ( $ ( this ) ) ;
51
+ self . _updateQty ( $ ( this ) )
51
52
} ) ;
52
53
53
- // Add event on "Update Qty" button click
54
- $ ( this . options . selectorItemButton ) . click ( function ( event ) {
54
+ $ ( 'body' ) . on ( 'minicart.update' , function ( event , elem , response ) {
55
55
event . stopPropagation ( ) ;
56
- self . _updateQty ( $ ( this ) )
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 ) ;
57
59
} ) ;
58
60
59
61
this . _initCloseButton ( ) ;
@@ -68,12 +70,17 @@ define([
68
70
*/
69
71
_initCloseButton : function ( ) {
70
72
var self = this ;
71
- $ ( this . options . closeButton ) . click ( function ( event ) {
73
+ $ ( this . options . button . close ) . click ( function ( event ) {
72
74
event . stopPropagation ( ) ;
73
75
$ ( self . options . targetElement ) . dropdownDialog ( "close" ) ;
74
76
} ) ;
75
77
} ,
76
78
79
+ /**
80
+ * Add 'overflowed' class to minicart items wrapper element
81
+ *
82
+ * @private
83
+ */
77
84
_isOverflowed : function ( ) {
78
85
var list = $ ( this . options . selectorList ) ;
79
86
if ( this . scrollHeight > list . innerHeight ( ) ) {
@@ -88,6 +95,9 @@ define([
88
95
var itemQty = elem . data ( 'item-qty' ) ;
89
96
if ( this . _isValidQty ( itemQty , elem . val ( ) ) ) {
90
97
$ ( '#update-cart-item-' + itemId ) . show ( 'fade' , 300 ) ;
98
+ } else if ( elem . val ( ) == 0 ) {
99
+ elem . val ( itemQty ) ;
100
+ this . _hideButton ( elem ) ;
91
101
} else {
92
102
this . _hideButton ( elem ) ;
93
103
}
@@ -113,35 +123,44 @@ define([
113
123
114
124
_updateQty : function ( elem ) {
115
125
var itemId = elem . data ( 'cart-item' ) ;
116
- this . _ajax ( this . options . updateItemQtyUrl , {
126
+ this . _ajax ( this . options . url . update , {
117
127
item_id : itemId ,
118
128
item_qty : $ ( '#cart-item-' + itemId + '-qty' ) . val ( )
119
129
} , elem , this . _updateQtyAfter ) ;
120
-
121
130
} ,
122
131
132
+ /**
133
+ * Update content after update qty
134
+ *
135
+ * @param elem
136
+ * @param response
137
+ * @private
138
+ */
123
139
_updateQtyAfter : function ( elem , response ) {
124
140
if ( $ . type ( response . data ) === 'object' ) {
141
+ $ ( 'body' ) . trigger ( 'minicart.update' , [ elem , response ] ) ;
125
142
this . _refreshItemQty ( elem , response . data . summary_qty ) ;
126
- this . _refreshSummaryQty ( response . data . summary_qty , response . data . summary_text ) ;
127
- this . _refreshSubtotal ( response . data . subtotal ) ;
128
- this . _refreshShowcartCounter ( response . data . summary_qty , response . data . summary_text ) ;
129
143
}
130
144
this . _hideButton ( elem ) ;
131
145
} ,
132
146
133
147
_removeItem : function ( elem ) {
134
148
var itemId = elem . data ( 'cart-item' ) ;
135
- this . _ajax ( this . options . removeItemUrl , {
149
+ this . _ajax ( this . options . url . remove , {
136
150
item_id : itemId
137
151
} , elem , this . _removeItemAfter ) ;
138
152
} ,
139
153
154
+ /**
155
+ * Update content after item remove
156
+ *
157
+ * @param elem
158
+ * @param response
159
+ * @private
160
+ */
140
161
_removeItemAfter : function ( elem , response ) {
141
162
if ( $ . type ( response . data ) === 'object' ) {
142
- this . _refreshSummaryQty ( response . data . summary_qty , response . data . summary_text ) ;
143
- this . _refreshSubtotal ( response . data . subtotal ) ;
144
- this . _refreshShowcartCounter ( response . data . summary_qty , response . data . summary_text ) ;
163
+ $ ( 'body' ) . trigger ( 'minicart.update' , [ elem , response ] ) ;
145
164
}
146
165
if ( response . cleanup === true ) {
147
166
$ ( this . options . selectorContentWrapper ) . replaceWith ( $ . trim ( response . content ) ) ;
@@ -189,7 +208,14 @@ define([
189
208
} ) ;
190
209
} ,
191
210
192
- _refreshSummaryQty : function ( qty , text ) {
211
+ _refreshItemQty : function ( elem , qty ) {
212
+ if ( qty != undefined ) {
213
+ var itemId = elem . data ( 'cart-item' ) ;
214
+ $ ( '#cart-item-' + itemId + '-qty' ) . data ( 'item-qty' , qty ) ;
215
+ }
216
+ } ,
217
+
218
+ _refreshQty : function ( qty , text ) {
193
219
if ( qty != undefined && text != undefined ) {
194
220
var self = this ;
195
221
$ ( this . options . selectorSummaryQty ) . fadeOut ( 'slow' , function ( ) {
@@ -198,13 +224,6 @@ define([
198
224
}
199
225
} ,
200
226
201
- _refreshItemQty : function ( elem , qty ) {
202
- if ( qty != undefined ) {
203
- var itemId = elem . data ( 'cart-item' ) ;
204
- $ ( '#cart-item-' + itemId + '-qty' ) . data ( 'item-qty' , qty ) ;
205
- }
206
- } ,
207
-
208
227
_refreshSubtotal : function ( val ) {
209
228
if ( val != undefined ) {
210
229
var self = this ;
@@ -214,7 +233,7 @@ define([
214
233
}
215
234
} ,
216
235
217
- _refreshShowcartCounter : function ( qty , text ) {
236
+ _refreshShowcart : function ( qty , text ) {
218
237
if ( qty != undefined && text != undefined ) {
219
238
var self = this ;
220
239
$ ( this . options . selectorShowcartNumber ) . fadeOut ( 'slow' , function ( ) {
@@ -226,6 +245,11 @@ define([
226
245
}
227
246
} ,
228
247
248
+ /**
249
+ * Calculate height of minicart list
250
+ *
251
+ * @private
252
+ */
229
253
_calcHeight : function ( ) {
230
254
var self = this ,
231
255
height = 0 ,
0 commit comments