Skip to content

Commit d8a9bbe

Browse files
author
Jeff Harrell
committed
Fixes to get it working again
1 parent c68333e commit d8a9bbe

12 files changed

Lines changed: 138 additions & 103 deletions

File tree

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function (grunt) {
6363

6464
watch: {
6565
scripts: {
66-
files: ['src/**/*.js'],
66+
files: ['src/**/*'],
6767
tasks: ['develop'],
6868
options: {
6969
spawn: false

dist/all.js

Lines changed: 66 additions & 50 deletions
Large diffs are not rendered by default.

locales/US/en/button.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
buynow=Buy with {wordmark}
22
cart=Add to Cart
3-
donate=Donate
4-
subscribe=Subscribe
5-
paynow=Pay Now
3+
donate=Donate with {wordmark}
4+
subscribe=Subscribe with {wordmark}
5+
paynow=Pay now with {wordmark}
66
item_name=Item
77
number=Number
88
amount=Amount

src/button.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33

44
var template = require('./util/template'),
5-
constants = require('./constants'),
6-
css = require('./util/css'),
7-
hasCss = false;
5+
constants = require('./constants');
86

97

10-
module.exports = function Button(label, data, config) {
8+
module.exports = function button(label, data, config) {
119
var model, locale, style;
1210

1311
config = config || {};
@@ -21,11 +19,6 @@ module.exports = function Button(label, data, config) {
2119
wordmark: constants.WORDMARK[style],
2220
label: constants.STRINGS[locale][label]
2321
};
24-
25-
if (!hasCss) {
26-
hasCss = true;
27-
css.inject(document.getElementsByTagName('head')[0], constants.STYLES);
28-
}
2922

30-
return template(constants.TEMPLATE.button, model);
23+
return template(constants.TEMPLATES.button, model);
3124
};

src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module.exports = {
2424
button_id: 'hosted_button_id'
2525
},
2626

27+
WIDGET_NAME: 'paypal-button-widget',
28+
2729
DEFAULT_HOST: 'www.paypal.com',
2830

2931
DEFAULT_TYPE: 'button',

src/factory.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
'use strict';
22

33

4-
var Button = require('./button'),
5-
Form = require('./form'),
4+
var DataStore = require('./util/datastore'),
5+
constants = require('./constants'),
6+
button = require('./button'),
7+
css = require('./util/css'),
8+
form = require('./form'),
69
QR = require('./qr'),
7-
DataStore = require('./util/datastore'),
8-
constants = require('./constants');
10+
hasCss = false;
911

1012

1113

1214
module.exports = function factory(business, raw, config) {
13-
var data, el, key, label, type, env;
15+
var data, wrapper, html, key, label, type, env;
1416

1517
if (!business) { return false; }
1618

19+
1720
// Normalize incoming data if needed
1821
if (raw.items) {
1922
data = raw;
@@ -25,28 +28,28 @@ module.exports = function factory(business, raw, config) {
2528
}
2629
}
2730

31+
2832
// Defaults
2933
config = config || {};
3034
label = config.label || constants.DEFAULT_LABEL;
3135
type = config.type || constants.DEFAULT_TYPE;
3236

33-
// Cart buttons
37+
38+
// Cart
3439
if (type === 'cart') {
3540
data.add('cmd', '_cart');
3641
data.add('add', true);
37-
// Donation buttons
42+
// Donation
3843
} else if (type === 'donate') {
3944
data.add('cmd', '_donations');
40-
// Subscribe buttons
45+
// Subscribe
4146
} else if (type === 'subscribe') {
4247
data.add('cmd', '_xclick-subscriptions');
4348

44-
// TODO: "amount" cannot be used in prettyParams since it's overloaded
45-
// Find a better way to do this
4649
if (data.get('amount') && !data.get('a3')) {
47-
data.add('a3', data.get('amount'));
50+
data.add('a3', data.pluck('amount'));
4851
}
49-
// Buy Now buttons
52+
// Buy Now
5053
} else {
5154
if (data.get('hosted_button_id')) {
5255
data.add('cmd', '_s-xclick');
@@ -59,21 +62,32 @@ module.exports = function factory(business, raw, config) {
5962
data.add('business', business);
6063
data.add('bn', constants.BN_CODE.replace(/\{label\}/, label));
6164

65+
6266
// Build the UI components
6367
if (type === 'qr') {
64-
el = QR(data, config);
68+
html = QR(data, config);
6569
} else if (type === 'button') {
66-
el = Button(label, data, config);
70+
html = button(label, data, config);
6771
} else {
68-
el = Form(label, data, config);
72+
html = form(label, data, config);
6973
}
7074

71-
// Inject CSS
72-
// injectCSS();
75+
76+
// Inject the CSS onto the page
77+
if (!hasCss) {
78+
hasCss = true;
79+
css.inject(document.getElementsByTagName('head')[0], constants.STYLES);
80+
}
81+
82+
83+
// Wrap it up all nice and neat and return it
84+
wrapper = document.createElement('div');
85+
wrapper.className = constants.WIDGET_NAME;
86+
wrapper.innerHTML = html;
7387

7488
return {
7589
label: label,
7690
type: type,
77-
el: document.createElement('div').innerHTML = el
91+
el: wrapper
7892
};
7993
};

src/form.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
var constants = require('./constants'),
55
template = require('./util/template'),
6-
Button = require('./button');
6+
button = require('./button');
77

88

9-
module.exports = function Form(type, data, config) {
9+
module.exports = function form(type, data, config) {
1010
// var form = document.createElement('form'),
1111
// hidden = document.createElement('input'),
1212
// paraElem = document.createElement('p'),
@@ -130,13 +130,20 @@ module.exports = function Form(type, data, config) {
130130
// }
131131
// }
132132

133-
var model = {
133+
var model, btn, url;
134+
135+
btn = button(type, data, config);
136+
137+
url = constants.PAYPAL_URL;
138+
url = url.replace('{host}', config.host || constants.DEFAULT_HOST);
139+
140+
model = {
134141
data: data.items,
135-
button: new Button(type, data, config),
136-
url: constants.PAYPAL_URL.replace('{host}', config.host || constants.DEFAULT_HOST)
142+
button: btn,
143+
url: url
137144
};
138145

139-
return template(constants.TEMPLATE.form, model);
146+
return template(constants.TEMPLATES.form, model);
140147
};
141148

142149

src/qr.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

33

4-
var constants = require('./constants');
4+
var constants = require('./constants'),
5+
template = require('./util/template');
56

67

7-
module.exports = function QrCode(data, config) {
8-
var img, url, item, key, size;
9-
8+
module.exports = function Qr(data, config) {
9+
var model = {}, url, key;
10+
1011
// Defaults
1112
config = config || {};
12-
size = config.size || constants.QR_SIZE;
13+
config.size = config.size || constants.QR_SIZE;
1314
config.host = config.host || constants.DEFAULT_HOST;
1415

1516
// Construct URL
@@ -23,13 +24,13 @@ module.exports = function QrCode(data, config) {
2324

2425
url = encodeURIComponent(url);
2526

26-
// Build the image
27-
img = document.createElement('img');
28-
img.src = constants.QR_URL
27+
// Render
28+
model.url = constants.QR_URL
2929
.replace('{host}', config.host)
3030
.replace('{url}', url)
3131
.replace('{pattern}', constants.QR_PATTERN)
32-
.replace('{size}', size);
32+
.replace('{size}', config.size);
33+
3334

34-
return img;
35+
return template(constants.TEMPLATES.qr, model);
3536
};

src/theme/button.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<button class="paypal-button <%= style %> <%= size %>" type="submit">
22
<span class="paypal-button-logo">
33
<img src="<%= logo %>" />
4-
</span>
5-
<span class="paypal-button-content">
4+
</span><span class="paypal-button-content">
65
<img src="<%= wordmark %>" alt="PayPal" />
76
</span>
87
</button>

src/theme/form.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<form method="post" action="<%= url %>" class="paypal-button-widget" target="_top">
1+
<form method="post" action="<%= url %>" target="_top">
22
<% for (var key in data) { %>
3-
<input type="hidden" name="<%= key %>" value="<%= data[key] %>" />
3+
<input type="hidden" name="<%= key %>" value="<%= data[key].value %>" />
44
<% } %>
55

6-
<%= button %>
6+
<%- button %>
77
</form>

0 commit comments

Comments
 (0)