@@ -10,18 +10,18 @@ PAYPAL.apps = PAYPAL.apps || {};
1010 'use strict' ;
1111
1212
13- var PAYPAL_URL = 'https://www.paypal.com/cgi-bin/webscr' ,
14- CART_BTN_URL = '//www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif' ,
15- BUY_BTN_URL = '//www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif' ,
16- MINICART_URL = 'http://www.minicartjs.com/build/minicart.js' ;
17-
18-
1913 // Don't execute the code multiple times!
2014 if ( PAYPAL . apps . DynamicButton ) {
2115 return ;
2216 }
2317
2418
19+ var PAYPAL_URL = 'https://www.paypal.com/cgi-bin/webscr' ,
20+ CART_BTN_URL = '//www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif' ,
21+ BUY_BTN_URL = '//www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif' ,
22+ MINICART_URL = 'http://www.minicartjs.com/build/minicart.js' ;
23+
24+
2525 PAYPAL . apps . DynamicButton = ( function ( ) {
2626 var app = { } ;
2727
@@ -48,11 +48,11 @@ PAYPAL.apps = PAYPAL.apps || {};
4848 hidden = document . createElement ( 'input' ) ,
4949 btn , hidden , input , key ;
5050
51+ btn . type = 'image' ;
52+ hidden . type = 'hidden' ;
5153 form . method = 'post' ;
5254 form . action = PAYPAL_URL ;
5355 form . appendChild ( btn ) ;
54- hidden . type = 'hidden' ;
55- btn . type = 'image' ;
5656
5757 // Cart buttons
5858 if ( type === 'cart' ) {
@@ -103,9 +103,10 @@ PAYPAL.apps = PAYPAL.apps || {};
103103
104104 for ( i = 0 , len = nodes . length ; i < len ; i ++ ) {
105105 node = nodes [ i ] ;
106- data = node . dataset ;
106+ data = getDataSet ( node ) ;
107+ button = data && data . button ;
107108
108- if ( ( button = data . button ) ) {
109+ if ( button ) {
109110 this . renderButton ( node , button , data ) ;
110111 }
111112 }
@@ -134,6 +135,34 @@ PAYPAL.apps = PAYPAL.apps || {};
134135 }
135136
136137
138+ /**
139+ * Utility function to polyfill dataset functionality for browsers
140+ *
141+ * @param el {HTMLElement} The element to check
142+ * @return {Object }
143+ */
144+ function getDataSet ( el ) {
145+ var dataset = el . dataset ,
146+ attrs , attr , matches , len , i ;
147+
148+ if ( ! dataset ) {
149+ dataset = { } ;
150+
151+ if ( ( attrs = el . attributes ) ) {
152+ for ( i = 0 , len = attrs . length ; i < len ; i ++ ) {
153+ attr = attrs [ i ] ;
154+
155+ if ( ( matches = / ^ d a t a - ( .+ ) / . exec ( attr . name ) ) ) {
156+ dataset [ matches [ 1 ] ] = attr . value ;
157+ }
158+ }
159+ }
160+ }
161+
162+ return dataset ;
163+ }
164+
165+
137166 PAYPAL . apps . DynamicButton . init ( ) ;
138167
139168} ( ) ) ;
0 commit comments