| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c68333e commit d8a9bbe
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,7 +63,7 @@ module.exports = function (grunt) { | |||
| 63 | 63 | ||
| 64 | 64 | watch: { | |
| 65 | 65 | scripts: { | |
| 66 | - files: ['src/**/*.js'], | ||
| 66 | + files: ['src/**/*'], | ||
| 67 | 67 | tasks: ['develop'], | |
| 68 | 68 | options: { | |
| 69 | 69 | spawn: false | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,8 @@ | |||
| 1 | 1 | buynow=Buy with {wordmark} | |
| 2 | 2 | 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} | ||
| 6 | 6 | item_name=Item | |
| 7 | 7 | number=Number | |
| 8 | 8 | amount=Amount | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,12 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | var template = require('./util/template'), | |
| 5 | - constants = require('./constants'), | ||
| 6 | - css = require('./util/css'), | ||
| 7 | - hasCss = false; | ||
| 5 | + constants = require('./constants'); | ||
| 8 | 6 | ||
| 9 | 7 | ||
| 10 | - module.exports = function Button(label, data, config) { | ||
| 8 | + module.exports = function button(label, data, config) { | ||
| 11 | 9 | var model, locale, style; | |
| 12 | 10 | ||
| 13 | 11 | config = config || {}; | |
@@ -21,11 +19,6 @@ module.exports = function Button(label, data, config) { | |||
| 21 | 19 | wordmark: constants.WORDMARK[style], | |
| 22 | 20 | label: constants.STRINGS[locale][label] | |
| 23 | 21 | }; | |
| 24 | - | ||
| 25 | - if (!hasCss) { | ||
| 26 | - hasCss = true; | ||
| 27 | - css.inject(document.getElementsByTagName('head')[0], constants.STYLES); | ||
| 28 | - } | ||
| 29 | 22 | ||
| 30 | - return template(constants.TEMPLATE.button, model); | ||
| 23 | + return template(constants.TEMPLATES.button, model); | ||
| 31 | 24 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,8 @@ module.exports = { | |||
| 24 | 24 | button_id: 'hosted_button_id' | |
| 25 | 25 | }, | |
| 26 | 26 | ||
| 27 | + WIDGET_NAME: 'paypal-button-widget', | ||
| 28 | + | ||
| 27 | 29 | DEFAULT_HOST: 'www.paypal.com', | |
| 28 | 30 | ||
| 29 | 31 | DEFAULT_TYPE: 'button', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,22 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | ||
| 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'), | ||
| 6 | 9 | QR = require('./qr'), | |
| 7 | - DataStore = require('./util/datastore'), | ||
| 8 | - constants = require('./constants'); | ||
| 10 | + hasCss = false; | ||
| 9 | 11 | ||
| 10 | 12 | ||
| 11 | 13 | ||
| 12 | 14 | module.exports = function factory(business, raw, config) { | |
| 13 | - var data, el, key, label, type, env; | ||
| 15 | + var data, wrapper, html, key, label, type, env; | ||
| 14 | 16 | ||
| 15 | 17 | if (!business) { return false; } | |
| 16 | 18 | ||
| 19 | + | ||
| 17 | 20 | // Normalize incoming data if needed | |
| 18 | 21 | if (raw.items) { | |
| 19 | 22 | data = raw; | |
@@ -25,28 +28,28 @@ module.exports = function factory(business, raw, config) { | |||
| 25 | 28 | } | |
| 26 | 29 | } | |
| 27 | 30 | ||
| 31 | + | ||
| 28 | 32 | // Defaults | |
| 29 | 33 | config = config || {}; | |
| 30 | 34 | label = config.label || constants.DEFAULT_LABEL; | |
| 31 | 35 | type = config.type || constants.DEFAULT_TYPE; | |
| 32 | 36 | ||
| 33 | - // Cart buttons | ||
| 37 | + | ||
| 38 | + // Cart | ||
| 34 | 39 | if (type === 'cart') { | |
| 35 | 40 | data.add('cmd', '_cart'); | |
| 36 | 41 | data.add('add', true); | |
| 37 | - // Donation buttons | ||
| 42 | + // Donation | ||
| 38 | 43 | } else if (type === 'donate') { | |
| 39 | 44 | data.add('cmd', '_donations'); | |
| 40 | - // Subscribe buttons | ||
| 45 | + // Subscribe | ||
| 41 | 46 | } else if (type === 'subscribe') { | |
| 42 | 47 | data.add('cmd', '_xclick-subscriptions'); | |
| 43 | 48 | ||
| 44 | - // TODO: "amount" cannot be used in prettyParams since it's overloaded | ||
| 45 | - // Find a better way to do this | ||
| 46 | 49 | if (data.get('amount') && !data.get('a3')) { | |
| 47 | - data.add('a3', data.get('amount')); | ||
| 50 | + data.add('a3', data.pluck('amount')); | ||
| 48 | 51 | } | |
| 49 | - // Buy Now buttons | ||
| 52 | + // Buy Now | ||
| 50 | 53 | } else { | |
| 51 | 54 | if (data.get('hosted_button_id')) { | |
| 52 | 55 | data.add('cmd', '_s-xclick'); | |
@@ -59,21 +62,32 @@ module.exports = function factory(business, raw, config) { | |||
| 59 | 62 | data.add('business', business); | |
| 60 | 63 | data.add('bn', constants.BN_CODE.replace(/\{label\}/, label)); | |
| 61 | 64 | ||
| 65 | + | ||
| 62 | 66 | // Build the UI components | |
| 63 | 67 | if (type === 'qr') { | |
| 64 | - el = QR(data, config); | ||
| 68 | + html = QR(data, config); | ||
| 65 | 69 | } else if (type === 'button') { | |
| 66 | - el = Button(label, data, config); | ||
| 70 | + html = button(label, data, config); | ||
| 67 | 71 | } else { | |
| 68 | - el = Form(label, data, config); | ||
| 72 | + html = form(label, data, config); | ||
| 69 | 73 | } | |
| 70 | 74 | ||
| 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; | ||
| 73 | 87 | ||
| 74 | 88 | return { | |
| 75 | 89 | label: label, | |
| 76 | 90 | type: type, | |
| 77 | - el: document.createElement('div').innerHTML = el | ||
| 91 | + el: wrapper | ||
| 78 | 92 | }; | |
| 79 | 93 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,10 +3,10 @@ | |||
| 3 | 3 | ||
| 4 | 4 | var constants = require('./constants'), | |
| 5 | 5 | template = require('./util/template'), | |
| 6 | - Button = require('./button'); | ||
| 6 | + button = require('./button'); | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | - module.exports = function Form(type, data, config) { | ||
| 9 | + module.exports = function form(type, data, config) { | ||
| 10 | 10 | // var form = document.createElement('form'), | |
| 11 | 11 | // hidden = document.createElement('input'), | |
| 12 | 12 | // paraElem = document.createElement('p'), | |
@@ -130,13 +130,20 @@ module.exports = function Form(type, data, config) { | |||
| 130 | 130 | // } | |
| 131 | 131 | // } | |
| 132 | 132 | ||
| 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 = { | ||
| 134 | 141 | 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 | ||
| 137 | 144 | }; | |
| 138 | 145 | ||
| 139 | - return template(constants.TEMPLATE.form, model); | ||
| 146 | + return template(constants.TEMPLATES.form, model); | ||
| 140 | 147 | }; | |
| 141 | 148 | ||
| 142 | 149 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,16 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | - var constants = require('./constants'); | ||
| 4 | + var constants = require('./constants'), | ||
| 5 | + template = require('./util/template'); | ||
| 5 | 6 | ||
| 6 | 7 | ||
| 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 | + | ||
| 10 | 11 | // Defaults | |
| 11 | 12 | config = config || {}; | |
| 12 | - size = config.size || constants.QR_SIZE; | ||
| 13 | + config.size = config.size || constants.QR_SIZE; | ||
| 13 | 14 | config.host = config.host || constants.DEFAULT_HOST; | |
| 14 | 15 | ||
| 15 | 16 | // Construct URL | |
@@ -23,13 +24,13 @@ module.exports = function QrCode(data, config) { | |||
| 23 | 24 | ||
| 24 | 25 | url = encodeURIComponent(url); | |
| 25 | 26 | ||
| 26 | - // Build the image | ||
| 27 | - img = document.createElement('img'); | ||
| 28 | - img.src = constants.QR_URL | ||
| 27 | + // Render | ||
| 28 | + model.url = constants.QR_URL | ||
| 29 | 29 | .replace('{host}', config.host) | |
| 30 | 30 | .replace('{url}', url) | |
| 31 | 31 | .replace('{pattern}', constants.QR_PATTERN) | |
| 32 | - .replace('{size}', size); | ||
| 32 | + .replace('{size}', config.size); | ||
| 33 | + | ||
| 33 | 34 | ||
| 34 | - return img; | ||
| 35 | + return template(constants.TEMPLATES.qr, model); | ||
| 35 | 36 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,7 @@ | |||
| 1 | 1 | <button class="paypal-button <%= style %> <%= size %>" type="submit"> | |
| 2 | 2 | <span class="paypal-button-logo"> | |
| 3 | 3 | <img src="<%= logo %>" /> | |
| 4 | - </span> | ||
| 5 | - <span class="paypal-button-content"> | ||
| 4 | + </span><span class="paypal-button-content"> | ||
| 6 | 5 | <img src="<%= wordmark %>" alt="PayPal" /> | |
| 7 | 6 | </span> | |
| 8 | 7 | </button> | |
| Original file line number | Diff line number | Diff 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"> | ||
| 2 | 2 | <% for (var key in data) { %> | |
| 3 | - <input type="hidden" name="<%= key %>" value="<%= data[key] %>" /> | ||
| 3 | + <input type="hidden" name="<%= key %>" value="<%= data[key].value %>" /> | ||
| 4 | 4 | <% } %> | |
| 5 | 5 | ||
| 6 | - <%= button %> | ||
| 6 | + <%- button %> | ||
| 7 | 7 | </form> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments