Skip to content

Commit 29f5a40

Browse files
author
Jeff Harrell
committed
Fix for issue #1. This now works in IE 7/8/9
1 parent c681eac commit 29f5a40

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ <h3 id="buy-now">Buy Now</h3>
129129
<p>Buy Now buttons are for single item purchases.</p>
130130

131131
<pre><code>&lt;script src="paypal.js?merchant=6XF3MPZBZV6HU"
132-
data-type="buy"
132+
data-type="buynow"
133133
data-item_name="Buy me now!"
134134
data-amount="1.00"
135135
&gt;&lt;/script&gt;</code></pre>
136136

137137
<script src="paypal.js?merchant=6XF3MPZBZV6HU"
138-
data-button="buy"
138+
data-button="buynow"
139139
data-item_name="Buy me now!"
140140
data-amount="1.00"
141141
></script>

paypal.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /^data-(.+)/.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

Comments
 (0)