FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Doc updates · zequeira/JavaScriptButtons@13c34a4 · GitHub

Repository navigation

Commit 13c34a4

Browse files
Jeff Harrell
committed
Doc updates
1 parent cf3ff7f commit 13c34a4

4 files changed

Lines changed: 9 additions & 303 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,6 @@ All of PayPal's [HTML button variables](https://developer.paypal.com/webapps/dev
114114
Creating editable fields is easy! Just add `-editable` to the name of your variable, e.g. `data-quantity-editable`, and an input field will magically appear for your users.
115115

116116

117-
### Custom fields
118-
You can also add custom text fields and dropdowns to your form.
119-
120-
121-
For a text field:
122-
```javascript
123-
data-option0name="Coupon Number"
124-
```
125-
126-
For a dropdown:
127-
```javascript
128-
data-option0name="Size"
129-
data-option0select0="Small"
130-
data-option0select1="Medium"
131-
data-option0select2="Large"
132-
data-option0price0="8.00"
133-
data-option0price1="10.00"
134-
data-option0price2="12.00"
135-
```
136-
137117
### Callback notification
138118
On completion of a transaction you can get a payment notification ([IPN](https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/)) on a callback URL you specify using the `data-callback` attribute. An [IPN simulator](https://developer.paypal.com/webapps/developer/applications/ipn_simulator) is available on the sandbox.
139119

@@ -142,22 +122,22 @@ On completion of a transaction you can get a payment notification ([IPN](https:/
142122

143123
### Localization
144124
* Changing the default language of a button can be done by setting the variable `data-lc` with the correct locale code, e.g. es_ES.
145-
* Changing the default input labels of editable buttons can be done by overriding the default configuration, e.g. PAYPAL.apps.ButtonFactory.config.labels.
125+
* Changing the default input labels of editable buttons can be done by overriding the default configuration, e.g. `paypal.button.config.labels`.
146126

147127

148128
### JavaScript API
149129
There's even a fancy JavaScript API if you'd like to pragmatically create your buttons.
150130

151-
**PAYPAL.apps.ButtonFactory.config**
152-
This can be overridden to change the default behavior of the buttons.
153-
154-
**PAYPAL.apps.ButtonFactory.create(business, data, type, parentNode)**
131+
**paypal.button.create(business, data, config, parentNode)**
155132
Creates and returns an HTML element that contains the button code.
156133
> **business** - A string containing either the business ID or the business email
157134
> **data** - A JavaScript object containing the button variables
158-
> **type** - The button type, e.g. "buynow", "cart", "qr"
135+
> **config** - A configuration object for the button. Possible settings are `button`, `type`, `style`, `size`, and `host`
159136
> **parentNode** - An HTML element to add the newly created button to (Optional)
160137
138+
**paypal.button.process(node)**
139+
Parses `node` and automatically runs `paypal.button.create` on any `<script>` element it finds matching the right criteria. This is called automatically on `document.body`.
140+
161141

162142
## Browser support
163143
The JavaScript buttons have been tested and work in all modern browsers including:

‎dist/all.js‎

Lines changed: 2 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,143 +1830,6 @@ module.exports = function form(type, data, config) {
18301830
return template(constants.TEMPLATES.form, model);
18311831
};
18321832

1833-
1834-
// var form = document.createElement('form'),
1835-
// hidden = document.createElement('input'),
1836-
// paraElem = document.createElement('p'),
1837-
// labelElem = document.createElement('label'),
1838-
// inputTextElem = document.createElement('input'),
1839-
// selectElem = document.createElement('select'),
1840-
// optionElem = document.createElement('option'),
1841-
// items = data.items,
1842-
// optionFieldArr = [],
1843-
// item, child, label, input, key, selector, optionField, fieldDetails = {}, fieldDetail, fieldValue, field, labelText, btn;
1844-
1845-
// // Defaults
1846-
// config = config || {};
1847-
// config.host = config.host || constants.DEFAULT_HOST;
1848-
1849-
// form.method = 'post';
1850-
// form.action = constants.PAYPAL_URL.replace('{host}', config.host);
1851-
// form.className = 'paypal-button-widget';
1852-
// form.target = '_top';
1853-
1854-
// inputTextElem.type = 'text';
1855-
// inputTextElem.className = 'paypal-input';
1856-
// paraElem.className = 'paypal-group';
1857-
// labelElem.className = 'paypal-label';
1858-
// selectElem.className = 'paypal-select';
1859-
1860-
// hidden.type = 'hidden';
1861-
1862-
// for (key in items) {
1863-
// item = items[key];
1864-
1865-
1866-
// if (item.hasOptions) {
1867-
// optionFieldArr.push(item);
1868-
// } else if (item.isEditable) {
1869-
// input = inputTextElem.cloneNode(true);
1870-
// input.name = item.key;
1871-
// input.value = item.value;
1872-
1873-
// label = labelElem.cloneNode(true);
1874-
// // FIXME: This needs to resolve to user strings
1875-
// labelText = item.key;
1876-
// label.htmlFor = item.key;
1877-
// label.appendChild(document.createTextNode(labelText));
1878-
// label.appendChild(input);
1879-
1880-
// child = paraElem.cloneNode(true);
1881-
// child.appendChild(label);
1882-
// form.appendChild(child);
1883-
// } else {
1884-
// input = child = hidden.cloneNode(true);
1885-
// input.name = item.key;
1886-
// input.value = item.value;
1887-
// form.appendChild(child);
1888-
// }
1889-
// }
1890-
1891-
// optionFieldArr = sortOptionFields(optionFieldArr);
1892-
1893-
// for (key in optionFieldArr) {
1894-
// item = optionFieldArr[key];
1895-
1896-
// if (optionFieldArr[key].hasOptions) {
1897-
// fieldDetails = item.value;
1898-
// if (fieldDetails.options.length > 1) {
1899-
// input = hidden.cloneNode(true);
1900-
// //on - Option Name
1901-
// input.name = 'on' + item.displayOrder;
1902-
// input.value = fieldDetails.label;
1903-
1904-
// selector = selectElem.cloneNode(true);
1905-
// //os - Option Select
1906-
// selector.name = 'os' + item.displayOrder;
1907-
1908-
// for (fieldDetail in fieldDetails.options) {
1909-
// fieldValue = fieldDetails.options[fieldDetail];
1910-
1911-
// if (typeof fieldValue === 'string') {
1912-
// optionField = optionElem.cloneNode(true);
1913-
// optionField.value = fieldValue;
1914-
// optionField.appendChild(document.createTextNode(fieldValue));
1915-
// selector.appendChild(optionField);
1916-
// } else {
1917-
// for (field in fieldValue) {
1918-
// optionField = optionElem.cloneNode(true);
1919-
// optionField.value = field;
1920-
// optionField.appendChild(document.createTextNode(fieldValue[field]));
1921-
// selector.appendChild(optionField);
1922-
// }
1923-
// }
1924-
// }
1925-
1926-
// label = labelElem.cloneNode(true);
1927-
// labelText = fieldDetails.label || item.key;
1928-
// label.htmlFor = item.key;
1929-
// label.appendChild(document.createTextNode(labelText));
1930-
// label.appendChild(selector);
1931-
// label.appendChild(input);
1932-
// } else {
1933-
// label = labelElem.cloneNode(true);
1934-
// labelText = fieldDetails.label || item.key;
1935-
// label.htmlFor = item.key;
1936-
// label.appendChild(document.createTextNode(labelText));
1937-
1938-
// input = hidden.cloneNode(true);
1939-
// input.name = 'on' + item.displayOrder;
1940-
// input.value = fieldDetails.label;
1941-
// label.appendChild(input);
1942-
1943-
// input = inputTextElem.cloneNode(true);
1944-
// input.name = 'os' + item.displayOrder;
1945-
// input.value = fieldDetails.options[0] || '';
1946-
// input.setAttribute('data-label', fieldDetails.label);
1947-
1948-
// label.appendChild(input);
1949-
// }
1950-
// child = paraElem.cloneNode(true);
1951-
// child.appendChild(label);
1952-
1953-
// form.appendChild(child);
1954-
// }
1955-
// }
1956-
1957-
1958-
// /**
1959-
// * Sort Optional Fields by display order
1960-
// */
1961-
// function sortOptionFields(optionFieldArr) {
1962-
// optionFieldArr.sort(function (a, b) {
1963-
// return a.displayOrder - b.displayOrder;
1964-
// });
1965-
1966-
// return optionFieldArr;
1967-
// }
1968-
1969-
19701833

19711834

19721835
},{"./button":9,"./constants":10,"./util/template":17}],13:[function(require,module,exports){
@@ -2002,7 +1865,7 @@ app.create = function (business, data, config, parent) {
20021865

20031866

20041867
app.process = function (el) {
2005-
var nodes = document.getElementsByTagName('script'),
1868+
var nodes = el.getElementsByTagName('script'),
20061869
node, data, business, i, len;
20071870

20081871
for (i = 0, len = nodes.length; i < len; i++) {
@@ -2306,5 +2169,5 @@ if (!String.prototype.trim) {
23062169
return this.replace(/^\s+|\s+$/g, '');
23072170
};
23082171
}
2309-
},{"ejs":6}]},{},[9,10,11,12,13,14,16,15,17])
2172+
},{"ejs":6}]},{},[9,10,11,12,13,14,15,16,17])
23102173
;

‎src/form.js‎

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -25,141 +25,4 @@ module.exports = function form(type, data, config) {
2525
return template(constants.TEMPLATES.form, model);
2626
};
2727

28-
29-
// var form = document.createElement('form'),
30-
// hidden = document.createElement('input'),
31-
// paraElem = document.createElement('p'),
32-
// labelElem = document.createElement('label'),
33-
// inputTextElem = document.createElement('input'),
34-
// selectElem = document.createElement('select'),
35-
// optionElem = document.createElement('option'),
36-
// items = data.items,
37-
// optionFieldArr = [],
38-
// item, child, label, input, key, selector, optionField, fieldDetails = {}, fieldDetail, fieldValue, field, labelText, btn;
39-
40-
// // Defaults
41-
// config = config || {};
42-
// config.host = config.host || constants.DEFAULT_HOST;
43-
44-
// form.method = 'post';
45-
// form.action = constants.PAYPAL_URL.replace('{host}', config.host);
46-
// form.className = 'paypal-button-widget';
47-
// form.target = '_top';
48-
49-
// inputTextElem.type = 'text';
50-
// inputTextElem.className = 'paypal-input';
51-
// paraElem.className = 'paypal-group';
52-
// labelElem.className = 'paypal-label';
53-
// selectElem.className = 'paypal-select';
54-
55-
// hidden.type = 'hidden';
56-
57-
// for (key in items) {
58-
// item = items[key];
59-
60-
61-
// if (item.hasOptions) {
62-
// optionFieldArr.push(item);
63-
// } else if (item.isEditable) {
64-
// input = inputTextElem.cloneNode(true);
65-
// input.name = item.key;
66-
// input.value = item.value;
67-
68-
// label = labelElem.cloneNode(true);
69-
// // FIXME: This needs to resolve to user strings
70-
// labelText = item.key;
71-
// label.htmlFor = item.key;
72-
// label.appendChild(document.createTextNode(labelText));
73-
// label.appendChild(input);
74-
75-
// child = paraElem.cloneNode(true);
76-
// child.appendChild(label);
77-
// form.appendChild(child);
78-
// } else {
79-
// input = child = hidden.cloneNode(true);
80-
// input.name = item.key;
81-
// input.value = item.value;
82-
// form.appendChild(child);
83-
// }
84-
// }
85-
86-
// optionFieldArr = sortOptionFields(optionFieldArr);
87-
88-
// for (key in optionFieldArr) {
89-
// item = optionFieldArr[key];
90-
91-
// if (optionFieldArr[key].hasOptions) {
92-
// fieldDetails = item.value;
93-
// if (fieldDetails.options.length > 1) {
94-
// input = hidden.cloneNode(true);
95-
// //on - Option Name
96-
// input.name = 'on' + item.displayOrder;
97-
// input.value = fieldDetails.label;
98-
99-
// selector = selectElem.cloneNode(true);
100-
// //os - Option Select
101-
// selector.name = 'os' + item.displayOrder;
102-
103-
// for (fieldDetail in fieldDetails.options) {
104-
// fieldValue = fieldDetails.options[fieldDetail];
105-
106-
// if (typeof fieldValue === 'string') {
107-
// optionField = optionElem.cloneNode(true);
108-
// optionField.value = fieldValue;
109-
// optionField.appendChild(document.createTextNode(fieldValue));
110-
// selector.appendChild(optionField);
111-
// } else {
112-
// for (field in fieldValue) {
113-
// optionField = optionElem.cloneNode(true);
114-
// optionField.value = field;
115-
// optionField.appendChild(document.createTextNode(fieldValue[field]));
116-
// selector.appendChild(optionField);
117-
// }
118-
// }
119-
// }
120-
121-
// label = labelElem.cloneNode(true);
122-
// labelText = fieldDetails.label || item.key;
123-
// label.htmlFor = item.key;
124-
// label.appendChild(document.createTextNode(labelText));
125-
// label.appendChild(selector);
126-
// label.appendChild(input);
127-
// } else {
128-
// label = labelElem.cloneNode(true);
129-
// labelText = fieldDetails.label || item.key;
130-
// label.htmlFor = item.key;
131-
// label.appendChild(document.createTextNode(labelText));
132-
133-
// input = hidden.cloneNode(true);
134-
// input.name = 'on' + item.displayOrder;
135-
// input.value = fieldDetails.label;
136-
// label.appendChild(input);
137-
138-
// input = inputTextElem.cloneNode(true);
139-
// input.name = 'os' + item.displayOrder;
140-
// input.value = fieldDetails.options[0] || '';
141-
// input.setAttribute('data-label', fieldDetails.label);
142-
143-
// label.appendChild(input);
144-
// }
145-
// child = paraElem.cloneNode(true);
146-
// child.appendChild(label);
147-
148-
// form.appendChild(child);
149-
// }
150-
// }
151-
152-
153-
// /**
154-
// * Sort Optional Fields by display order
155-
// */
156-
// function sortOptionFields(optionFieldArr) {
157-
// optionFieldArr.sort(function (a, b) {
158-
// return a.displayOrder - b.displayOrder;
159-
// });
160-
161-
// return optionFieldArr;
162-
// }
163-
164-
16528

‎src/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ app.create = function (business, data, config, parent) {
3030

3131

3232
app.process = function (el) {
33-
var nodes = document.getElementsByTagName('script'),
33+
var nodes = el.getElementsByTagName('script'),
3434
node, data, business, i, len;
3535

3636
for (i = 0, len = nodes.length; i < len; i++) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL