@@ -18,45 +18,40 @@ define([
18
18
scrollHeight : 0 ,
19
19
20
20
_create : function ( ) {
21
+ this . _initContent ( ) ;
22
+ } ,
23
+
24
+ _initContent : function ( ) {
21
25
var self = this ;
22
26
23
27
this . element . decorate ( 'list' , this . options . isRecursive ) ;
24
28
29
+ $ ( this . options . button . close ) . click ( function ( event ) {
30
+ event . stopPropagation ( ) ;
31
+ $ ( self . options . targetElement ) . dropdownDialog ( "close" ) ;
32
+ } ) ;
33
+
25
34
$ ( this . options . button . checkout ) . on ( 'click' , $ . proxy ( function ( ) {
26
35
location . href = this . options . url . checkout ;
27
36
} , this ) ) ;
28
37
29
- $ ( this . options . item . qty ) . keyup ( function ( event ) {
30
- self . _showButton ( $ ( this ) ) ;
31
- } ) ;
32
- $ ( this . options . item . button ) . click ( function ( event ) {
33
- event . stopPropagation ( ) ;
34
- self . _updateQty ( $ ( this ) )
35
- } ) ;
36
-
37
38
$ ( this . options . button . remove ) . click ( function ( event ) {
38
39
event . stopPropagation ( ) ;
39
40
if ( confirm ( self . options . confirmMessage ) ) {
40
41
self . _removeItem ( $ ( this ) ) ;
41
42
}
42
43
} ) ;
43
44
44
- this . _initCloseButton ( ) ;
45
- this . _calcHeight ( ) ;
46
- this . _isOverflowed ( ) ;
47
- } ,
48
-
49
- /**
50
- * Add event on "Close" button click
51
- *
52
- * @private
53
- */
54
- _initCloseButton : function ( ) {
55
- var self = this ;
56
- $ ( this . options . button . close ) . click ( function ( event ) {
45
+ $ ( this . options . item . qty ) . keyup ( function ( ) {
46
+ self . _showItemButton ( $ ( this ) ) ;
47
+ } ) ;
48
+ $ ( this . options . item . button ) . click ( function ( event ) {
57
49
event . stopPropagation ( ) ;
58
- $ ( self . options . targetElement ) . dropdownDialog ( "close" ) ;
50
+ self . _updateItemQty ( $ ( this ) )
59
51
} ) ;
52
+
53
+ this . _calcHeight ( ) ;
54
+ this . _isOverflowed ( ) ;
60
55
} ,
61
56
62
57
/**
@@ -73,16 +68,16 @@ define([
73
68
}
74
69
} ,
75
70
76
- _showButton : function ( elem ) {
71
+ _showItemButton : function ( elem ) {
77
72
var itemId = elem . data ( 'cart-item' ) ;
78
73
var itemQty = elem . data ( 'item-qty' ) ;
79
74
if ( this . _isValidQty ( itemQty , elem . val ( ) ) ) {
80
75
$ ( '#update-cart-item-' + itemId ) . show ( 'fade' , 300 ) ;
81
76
} else if ( elem . val ( ) == 0 ) {
82
77
elem . val ( itemQty ) ;
83
- this . _hideButton ( elem ) ;
78
+ this . _hideItemButton ( elem ) ;
84
79
} else {
85
- this . _hideButton ( elem ) ;
80
+ this . _hideItemButton ( elem ) ;
86
81
}
87
82
} ,
88
83
@@ -99,17 +94,17 @@ define([
99
94
&& ( changed - 0 > 0 ) ;
100
95
} ,
101
96
102
- _hideButton : function ( elem ) {
97
+ _hideItemButton : function ( elem ) {
103
98
var itemId = elem . data ( 'cart-item' ) ;
104
99
$ ( '#update-cart-item-' + itemId ) . hide ( 'fade' , 300 ) ;
105
100
} ,
106
101
107
- _updateQty : function ( elem ) {
102
+ _updateItemQty : function ( elem ) {
108
103
var itemId = elem . data ( 'cart-item' ) ;
109
104
this . _ajax ( this . options . url . update , {
110
105
item_id : itemId ,
111
106
item_qty : $ ( '#cart-item-' + itemId + '-qty' ) . val ( )
112
- } , elem , this . _updateQtyAfter ) ;
107
+ } , elem , this . _updateItemQtyAfter ) ;
113
108
} ,
114
109
115
110
/**
@@ -119,14 +114,14 @@ define([
119
114
* @param response
120
115
* @private
121
116
*/
122
- _updateQtyAfter : function ( elem , response ) {
117
+ _updateItemQtyAfter : function ( elem , response ) {
123
118
if ( $ . type ( response . data ) === 'object' ) {
124
119
this . _refreshQty ( response . data . summary_qty , response . data . summary_text ) ;
125
120
this . _refreshSubtotal ( response . data . subtotal ) ;
126
121
this . _refreshShowcart ( response . data . summary_qty , response . data . summary_text ) ;
127
122
this . _refreshItemQty ( elem , response . data . summary_qty ) ;
128
123
}
129
- this . _hideButton ( elem ) ;
124
+ this . _hideItemButton ( elem ) ;
130
125
} ,
131
126
132
127
_removeItem : function ( elem ) {
@@ -145,19 +140,13 @@ define([
145
140
*/
146
141
_removeItemAfter : function ( elem , response ) {
147
142
if ( $ . type ( response . data ) === 'object' ) {
148
- this . _refreshQty ( response . data . summary_qty , response . data . summary_text ) ;
149
- this . _refreshSubtotal ( response . data . subtotal ) ;
150
143
this . _refreshShowcart ( response . data . summary_qty , response . data . summary_text ) ;
151
144
}
145
+ $ ( this . options . minicart . content ) . html ( $ . trim ( response . content ) ) ;
152
146
if ( response . cleanup === true ) {
153
- $ ( this . options . minicart . content ) . replaceWith ( $ . trim ( response . content ) ) ;
154
147
$ ( this . options . showcart . parent ) . addClass ( 'empty' ) ;
155
- this . _initCloseButton ( ) ;
156
- } else {
157
- elem . closest ( 'li' ) . remove ( ) ;
158
- this . _calcHeight ( ) ;
159
- this . _isOverflowed ( ) ;
160
148
}
149
+ this . _initContent ( ) ;
161
150
} ,
162
151
163
152
/**
0 commit comments