@@ -81,21 +81,23 @@ define([
81
81
*/
82
82
initMsrpPopup : function ( ) {
83
83
var popupDOM = $ ( this . options . popUpAttr ) [ 0 ] ,
84
- $msrpPopup = $ ( $ ( popupDOM ) . html ( ) ) . clone ( ) ;
84
+ $msrpPopup = $ ( popupDOM . innerHTML . trim ( ) ) ;
85
85
86
86
$msrpPopup . find ( this . options . productIdInput ) . val ( this . options . productId ) ;
87
87
$ ( 'body' ) . append ( $msrpPopup ) ;
88
88
$msrpPopup . trigger ( 'contentUpdated' ) ;
89
89
90
- $msrpPopup . find ( 'button' ) . on ( 'click' , function ( ev ) {
91
- ev . preventDefault ( ) ;
92
- this . handleMsrpAddToCart ( ) ;
93
- } . bind ( this ) ) ;
90
+ $msrpPopup . find ( 'button' )
91
+ . on ( 'click' ,
92
+ this . handleMsrpAddToCart . bind ( this ) )
93
+ . filter ( this . options . popupCartButtonId )
94
+ . text ( $ ( this . options . addToCartButton ) . text ( ) ) ;
94
95
95
96
$msrpPopup . find ( this . options . paypalCheckoutButons ) . on ( 'click' ,
96
97
this . handleMsrpPaypalCheckout . bind ( this ) ) ;
97
98
98
- $ ( this . options . popupId ) . on ( 'click' , this . openPopup . bind ( this ) ) ;
99
+ $ ( this . options . popupId ) . on ( 'click' ,
100
+ this . openPopup . bind ( this ) ) ;
99
101
100
102
this . $popup = $msrpPopup ;
101
103
} ,
@@ -106,7 +108,9 @@ define([
106
108
*/
107
109
initInfoPopup : function ( ) {
108
110
var infoPopupDOM = $ ( '[data-role=msrp-info-template]' ) [ 0 ] ,
109
- $infoPopup = $ ( infoPopupDOM . innerText ) . appendTo ( 'body' ) ;
111
+ $infoPopup = $ ( infoPopupDOM . innerHTML . trim ( ) ) ;
112
+
113
+ $ ( 'body' ) . append ( $infoPopup ) ;
110
114
111
115
$ ( this . options . helpLinkId ) . on ( 'click' , function ( e ) {
112
116
this . popUpOptions . position . of = $ ( e . target ) ;
@@ -122,39 +126,37 @@ define([
122
126
* @private
123
127
*/
124
128
initTierPopup : function ( ) {
125
- var tierOptions = JSON . parse ( $ ( this . options . attr ) . attr ( 'data-tier-price' ) ) ,
126
- popupDOM = $ ( this . options . popUpAttr ) [ 0 ] ,
127
- $tierPopup = $ ( popupDOM . innerText ) . appendTo ( 'body' ) ;
129
+ var popupDOM = $ ( this . options . popUpAttr ) [ 0 ] ,
130
+ $tierPopup = $ ( popupDOM . innerHTML . trim ( ) ) ;
128
131
132
+ $ ( 'body' ) . append ( $tierPopup ) ;
129
133
$tierPopup . find ( this . options . productIdInput ) . val ( this . options . productId ) ;
130
134
this . popUpOptions . position . of = $ ( this . options . helpLinkId ) ;
131
135
132
- $tierPopup . find ( 'button' ) . on ( 'click' , function ( ev ) {
133
- ev . preventDefault ( ) ;
134
- this . handleTierAddToCart ( tierOptions ) ;
135
- } . bind ( this ) ) ;
136
+ $tierPopup . find ( 'button' ) . on ( 'click' ,
137
+ this . handleTierAddToCart . bind ( this ) )
138
+ . filter ( this . options . popupCartButtonId )
139
+ . text ( $ ( this . options . addToCartButton ) . text ( ) ) ;
136
140
137
- $tierPopup . find ( this . options . paypalCheckoutButons ) . on ( 'click' , function ( ) {
138
- this . handleTierPaypalCheckout ( tierOptions ) ;
139
- } . bind ( this ) ) ;
141
+ $tierPopup . find ( this . options . paypalCheckoutButons ) . on ( 'click' ,
142
+ this . handleTierPaypalCheckout . bind ( this ) ) ;
140
143
141
144
$ ( this . options . attr ) . on ( 'click' , function ( e ) {
142
- this . popUpOptions . position . of = $ ( e . target ) ;
143
- $tierPopup . find ( this . options . msrpLabelId ) . html ( tierOptions . msrp ) ;
144
- $tierPopup . find ( this . options . priceLabelId ) . html ( tierOptions . price ) ;
145
- $tierPopup . dropdownDialog ( this . popUpOptions ) . dropdownDialog ( 'open' ) ;
146
- this . _toggle ( $tierPopup ) ;
145
+ this . $popup = $tierPopup ;
146
+ this . tierOptions = $ ( e . target ) . data ( 'tier-price' ) ;
147
+ this . openPopup ( e ) ;
147
148
} . bind ( this ) ) ;
148
-
149
- this . $popup = $tierPopup ;
150
149
} ,
151
150
152
151
/**
153
152
* handle 'AddToCart' click on Msrp popup
153
+ * @param {Object } ev
154
154
*
155
155
* @private
156
156
*/
157
- handleMsrpAddToCart : function ( ) {
157
+ handleMsrpAddToCart : function ( ev ) {
158
+ ev . preventDefault ( ) ;
159
+
158
160
if ( this . options . addToCartButton ) {
159
161
$ ( this . options . addToCartButton ) . click ( ) ;
160
162
this . closePopup ( this . $popup ) ;
@@ -173,14 +175,16 @@ define([
173
175
/**
174
176
* handle 'AddToCart' click on Tier popup
175
177
*
176
- * @param {Object } tierOptions
178
+ * @param {Object } ev
177
179
* @private
178
180
*/
179
- handleTierAddToCart : function ( tierOptions ) {
181
+ handleTierAddToCart : function ( ev ) {
182
+ ev . preventDefault ( ) ;
183
+
180
184
if ( this . options . addToCartButton &&
181
- this . options . inputQty && ! isNaN ( tierOptions . qty )
185
+ this . options . inputQty && ! isNaN ( this . tierOptions . qty )
182
186
) {
183
- $ ( this . options . inputQty ) . val ( tierOptions . qty ) ;
187
+ $ ( this . options . inputQty ) . val ( this . tierOptions . qty ) ;
184
188
$ ( this . options . addToCartButton ) . click ( ) ;
185
189
this . closePopup ( this . $popup ) ;
186
190
}
@@ -189,13 +193,12 @@ define([
189
193
/**
190
194
* handle 'paypal checkout buttons' click on Tier popup
191
195
*
192
- * @param {Object } tierOptions
193
196
* @private
194
197
*/
195
- handleTierPaypalCheckout : function ( tierOptions ) {
196
- if ( this . options . inputQty && ! isNaN ( tierOptions . qty )
198
+ handleTierPaypalCheckout : function ( ) {
199
+ if ( this . options . inputQty && ! isNaN ( this . tierOptions . qty )
197
200
) {
198
- $ ( this . options . inputQty ) . val ( tierOptions . qty ) ;
201
+ $ ( this . options . inputQty ) . val ( this . tierOptions . qty ) ;
199
202
this . closePopup ( this . $popup ) ;
200
203
}
201
204
} ,
@@ -206,9 +209,11 @@ define([
206
209
* @param {Object } event
207
210
*/
208
211
openPopup : function ( event ) {
212
+ var options = this . tierOptions || this . options ;
213
+
209
214
this . popUpOptions . position . of = $ ( event . target ) ;
210
- this . $popup . find ( this . options . msrpLabelId ) . html ( this . options . msrpPrice ) ;
211
- this . $popup . find ( this . options . priceLabelId ) . html ( this . options . realPrice ) ;
215
+ this . $popup . find ( this . options . msrpLabelId ) . html ( options . msrpPrice ) ;
216
+ this . $popup . find ( this . options . priceLabelId ) . html ( options . realPrice ) ;
212
217
this . $popup . dropdownDialog ( this . popUpOptions ) . dropdownDialog ( 'open' ) ;
213
218
this . _toggle ( this . $popup ) ;
214
219
@@ -223,7 +228,7 @@ define([
223
228
* @private
224
229
*/
225
230
_toggle : function ( $elem ) {
226
- $ ( document ) . on ( 'mouseup' , function ( e ) {
231
+ $ ( document ) . on ( 'mouseup.msrp touchend.msrp ' , function ( e ) {
227
232
if ( ! $elem . is ( e . target ) && $elem . has ( e . target ) . length === 0 ) {
228
233
this . closePopup ( $elem ) ;
229
234
}
@@ -239,7 +244,7 @@ define([
239
244
*/
240
245
closePopup : function ( $elem ) {
241
246
$elem . dropdownDialog ( 'close' ) ;
242
- $ ( document ) . off ( 'mouseup' ) ;
247
+ $ ( document ) . off ( 'mouseup.msrp touchend.msrp ' ) ;
243
248
} ,
244
249
245
250
/**
0 commit comments