| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - if (typeof PAYPAL === 'undefined' || !PAYPAL) { | ||
| 1 | + if (typeof PAYPAL === "undefined" || !PAYPAL) { | ||
| 2 | 2 | var PAYPAL = {}; | |
| 3 | 3 | } | |
| 4 | 4 | ||
@@ -7,24 +7,25 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 7 | 7 | ||
| 8 | 8 | (function () { | |
| 9 | 9 | ||
| 10 | - 'use strict'; | ||
| 10 | + "use strict"; | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | var app = {}, | |
| 14 | - paypalURL = 'https://www.paypal.com/cgi-bin/webscr', | ||
| 15 | - qrCodeURL = 'https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}', | ||
| 16 | - scriptURL = 'paypal-button.min.js', | ||
| 17 | - bnCode = 'JavaScriptButton_{type}', | ||
| 14 | + paypalURL = "https://www.paypal.com/cgi-bin/webscr", | ||
| 15 | + qrCodeURL = "https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}", | ||
| 16 | + scriptURL = "paypal-button.min.js", | ||
| 17 | + bnCode = "JavaScriptButton_{type}", | ||
| 18 | 18 | prettyParams = { | |
| 19 | - id: 'hosted_button_id', | ||
| 20 | - name: 'item_name', | ||
| 21 | - number: 'item_number', | ||
| 22 | - lang: 'lc' | ||
| 19 | + id: "hosted_button_id", | ||
| 20 | + name: "item_name", | ||
| 21 | + number: "item_number", | ||
| 22 | + lang: "lc" | ||
| 23 | 23 | }, | |
| 24 | 24 | buttonImgs = { | |
| 25 | - buynow: '//www.paypalobjects.com/{locale}/i/btn/btn_buynow_{size}.gif', | ||
| 26 | - cart: '//www.paypalobjects.com/{locale}/i/btn/btn_cart_{size}.gif', | ||
| 27 | - donate: '//www.paypalobjects.com/{locale}/i/btn/btn_donate_{size}.gif' | ||
| 25 | + buynow: "//www.paypalobjects.com/{locale}/i/btn/btn_buynow_{size}.gif", | ||
| 26 | + cart: "//www.paypalobjects.com/{locale}/i/btn/btn_cart_{size}.gif", | ||
| 27 | + donate: "//www.paypalobjects.com/{locale}/i/btn/btn_donate_{size}.gif", | ||
| 28 | + subscribe: "//www.paypalobjects.com/{locale}/i/btn/btn_subscribe_{size}.gif" | ||
| 28 | 29 | }; | |
| 29 | 30 | ||
| 30 | 31 | if (!PAYPAL.apps.ButtonFactory) { | |
@@ -34,10 +35,10 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 34 | 35 | */ | |
| 35 | 36 | app.config = { | |
| 36 | 37 | labels: { | |
| 37 | - item_name: 'Item', | ||
| 38 | - item_number: 'Number', | ||
| 39 | - amount: 'Amount', | ||
| 40 | - quantity: 'Quantity' | ||
| 38 | + item_name: "Item", | ||
| 39 | + item_number: "Number", | ||
| 40 | + amount: "Amount", | ||
| 41 | + quantity: "Quantity" | ||
| 41 | 42 | } | |
| 42 | 43 | }; | |
| 43 | 44 | ||
@@ -49,7 +50,8 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 49 | 50 | cart: 0, | |
| 50 | 51 | hosted: 0, | |
| 51 | 52 | donate: 0, | |
| 52 | - qr: 0 | ||
| 53 | + qr: 0, | ||
| 54 | + subscribe: 0 | ||
| 53 | 55 | }; | |
| 54 | 56 | ||
| 55 | 57 | /** | |
@@ -72,32 +74,35 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 72 | 74 | } | |
| 73 | 75 | ||
| 74 | 76 | // Defaults | |
| 75 | - type = type || 'buynow'; | ||
| 77 | + type = type || "buynow"; | ||
| 76 | 78 | ||
| 77 | 79 | // Hosted buttons | |
| 78 | 80 | if (data.items.hosted_button_id) { | |
| 79 | - type = 'hosted'; | ||
| 80 | - data.add('cmd', '_s-xclick'); | ||
| 81 | + type = "hosted"; | ||
| 82 | + data.add("cmd", "_s-xclick"); | ||
| 81 | 83 | // Cart buttons | |
| 82 | - } else if (type === 'cart') { | ||
| 83 | - data.add('cmd', '_cart'); | ||
| 84 | - data.add('add', true); | ||
| 84 | + } else if (type === "cart") { | ||
| 85 | + data.add("cmd", "_cart"); | ||
| 86 | + data.add("add", true); | ||
| 85 | 87 | // Donation buttons | |
| 86 | - } else if (type === 'donate') { | ||
| 87 | - data.add('cmd', '_donations'); | ||
| 88 | + } else if (type === "donate") { | ||
| 89 | + data.add("cmd", "_donations"); | ||
| 90 | + // Subscribe buttons | ||
| 91 | + } else if (type === "subscribe") { | ||
| 92 | + data.add("cmd", "_xclick-subscriptions"); | ||
| 88 | 93 | // Buy Now buttons | |
| 89 | 94 | } else { | |
| 90 | - data.add('cmd', '_xclick'); | ||
| 95 | + data.add("cmd", "_xclick"); | ||
| 91 | 96 | } | |
| 92 | 97 | ||
| 93 | 98 | // Add common data | |
| 94 | - data.add('business', business); | ||
| 95 | - data.add('bn', bnCode.replace(/\{type\}/, type)); | ||
| 99 | + data.add("business", business); | ||
| 100 | + data.add("bn", bnCode.replace(/\{type\}/, type)); | ||
| 96 | 101 | ||
| 97 | 102 | // Build the UI components | |
| 98 | - if (type === 'qr') { | ||
| 103 | + if (type === "qr") { | ||
| 99 | 104 | button = buildQR(data, data.items.size); | |
| 100 | - data.remove('size'); | ||
| 105 | + data.remove("size"); | ||
| 101 | 106 | } else { | |
| 102 | 107 | button = buildForm(data, type); | |
| 103 | 108 | } | |
@@ -126,36 +131,36 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 126 | 131 | * @return {HTMLElement} | |
| 127 | 132 | */ | |
| 128 | 133 | function buildForm(data, type) { | |
| 129 | - var form = document.createElement('form'), | ||
| 130 | - btn = document.createElement('input'), | ||
| 131 | - hidden = document.createElement('input'), | ||
| 134 | + var form = document.createElement("form"), | ||
| 135 | + btn = document.createElement("input"), | ||
| 136 | + hidden = document.createElement("input"), | ||
| 132 | 137 | items = data.items, | |
| 133 | 138 | item, child, label, input, key, size, locale; | |
| 134 | 139 | ||
| 135 | - btn.type = 'image'; | ||
| 136 | - hidden.type = 'hidden'; | ||
| 137 | - form.method = 'post'; | ||
| 140 | + btn.type = "image"; | ||
| 141 | + hidden.type = "hidden"; | ||
| 142 | + form.method = "post"; | ||
| 138 | 143 | form.action = paypalURL; | |
| 139 | - form.className = 'paypal-button'; | ||
| 140 | - form.target = '_top'; | ||
| 144 | + form.className = "paypal-button"; | ||
| 145 | + form.target = "_top"; | ||
| 141 | 146 | ||
| 142 | 147 | for (key in items) { | |
| 143 | 148 | item = items[key]; | |
| 144 | 149 | ||
| 145 | 150 | if (item.isEditable) { | |
| 146 | - input = document.createElement('input'); | ||
| 147 | - input.type = 'text'; | ||
| 148 | - input.className = 'paypal-input'; | ||
| 151 | + input = document.createElement("input"); | ||
| 152 | + input.type = "text"; | ||
| 153 | + input.className = "paypal-input"; | ||
| 149 | 154 | input.name = item.key; | |
| 150 | 155 | input.value = item.value; | |
| 151 | 156 | ||
| 152 | - label = document.createElement('label'); | ||
| 153 | - label.className = 'paypal-label'; | ||
| 154 | - label.appendChild(document.createTextNode(app.config.labels[item.key] + ' ' || '')); | ||
| 157 | + label = document.createElement("label"); | ||
| 158 | + label.className = "paypal-label"; | ||
| 159 | + label.appendChild(document.createTextNode(app.config.labels[item.key] + " " || "")); | ||
| 155 | 160 | label.appendChild(input); | |
| 156 | 161 | ||
| 157 | - child = document.createElement('p'); | ||
| 158 | - child.className = 'paypal-group'; | ||
| 162 | + child = document.createElement("p"); | ||
| 163 | + child.className = "paypal-group"; | ||
| 159 | 164 | child.appendChild(label); | |
| 160 | 165 | } else { | |
| 161 | 166 | input = child = hidden.cloneNode(true); | |
@@ -173,7 +178,7 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 173 | 178 | btn.src = getButtonImg(type, size, locale); | |
| 174 | 179 | ||
| 175 | 180 | // If the Mini Cart is present then register the form | |
| 176 | - if (PAYPAL.apps.MiniCart && data.items.cmd.value === '_cart') { | ||
| 181 | + if (PAYPAL.apps.MiniCart && data.items.cmd.value === "_cart") { | ||
| 177 | 182 | var MiniCart = PAYPAL.apps.MiniCart; | |
| 178 | 183 | ||
| 179 | 184 | if (!MiniCart.UI.itemList) { | |
@@ -196,8 +201,8 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 196 | 201 | * @return {HTMLElement} | |
| 197 | 202 | */ | |
| 198 | 203 | function buildQR(data, size, locale) { | |
| 199 | - var img = document.createElement('img'), | ||
| 200 | - url = paypalURL + '?', | ||
| 204 | + var img = document.createElement("img"), | ||
| 205 | + url = paypalURL + "?", | ||
| 201 | 206 | pattern = 13, | |
| 202 | 207 | items = data.items, | |
| 203 | 208 | item, key; | |
@@ -207,11 +212,11 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 207 | 212 | ||
| 208 | 213 | for (key in items) { | |
| 209 | 214 | item = items[key]; | |
| 210 | - url += item.key + '=' + encodeURIComponent(item.value) + '&'; | ||
| 215 | + url += item.key + "=" + encodeURIComponent(item.value) + "&"; | ||
| 211 | 216 | } | |
| 212 | 217 | ||
| 213 | 218 | url = encodeURIComponent(url); | |
| 214 | - img.src = qrCodeURL.replace('{url}', url).replace('{pattern}', pattern).replace('{size}', size); | ||
| 219 | + img.src = qrCodeURL.replace("{url}", url).replace("{pattern}", pattern).replace("{size}", size); | ||
| 215 | 220 | ||
| 216 | 221 | return img; | |
| 217 | 222 | } | |
@@ -229,8 +234,8 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 229 | 234 | var img = buttonImgs[type] || buttonImgs.buynow; | |
| 230 | 235 | ||
| 231 | 236 | // Image defaults | |
| 232 | - locale = locale || 'en_US'; | ||
| 233 | - size = (size === 'small') ? 'SM' : 'LG'; | ||
| 237 | + locale = locale || "en_US"; | ||
| 238 | + size = (size === "small") ? "SM" : "LG"; | ||
| 234 | 239 | ||
| 235 | 240 | return img.replace(/\{locale\}/, locale).replace(/\{size\}/, size); | |
| 236 | 241 | } | |
@@ -249,7 +254,7 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 249 | 254 | for (i = 0, len = attrs.length; i < len; i++) { | |
| 250 | 255 | attr = attrs[i]; | |
| 251 | 256 | ||
| 252 | - if ((matches = /^data-([a-z]+)(-editable)?/i.exec(attr.name))) { | ||
| 257 | + if ((matches = /^data-([a-z0-9]+)(-editable)?/i.exec(attr.name))) { | ||
| 253 | 258 | dataset[matches[1]] = { | |
| 254 | 259 | value: attr.value, | |
| 255 | 260 | isEditable: !!matches[2] | |
@@ -283,9 +288,9 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 283 | 288 | ||
| 284 | 289 | ||
| 285 | 290 | // Init the buttons | |
| 286 | - if (typeof document !== 'undefined') { | ||
| 291 | + if (typeof document !== "undefined") { | ||
| 287 | 292 | var ButtonFactory = PAYPAL.apps.ButtonFactory, | |
| 288 | - nodes = document.getElementsByTagName('script'), | ||
| 293 | + nodes = document.getElementsByTagName("script"), | ||
| 289 | 294 | node, data, type, business, i, len; | |
| 290 | 295 | ||
| 291 | 296 | for (i = 0, len = nodes.length; i < len; i++) { | |
@@ -295,7 +300,7 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 295 | 300 | ||
| 296 | 301 | data = node && getDataSet(node); | |
| 297 | 302 | type = data && data.button && data.button.value; | |
| 298 | - business = node.src.split('?merchant=')[1]; | ||
| 303 | + business = node.src.split("?merchant=")[1]; | ||
| 299 | 304 | ||
| 300 | 305 | if (business) { | |
| 301 | 306 | ButtonFactory.create(business, data, type, node.parentNode); | |
@@ -311,6 +316,6 @@ PAYPAL.apps = PAYPAL.apps || {}; | |||
| 311 | 316 | ||
| 312 | 317 | ||
| 313 | 318 | // Export for CommonJS environments | |
| 314 | - if (typeof module === 'object' && typeof module.exports === 'object') { | ||
| 319 | + if (typeof module === "object" && typeof module.exports === "object") { | ||
| 315 | 320 | module.exports = PAYPAL; | |
| 316 | 321 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,29 @@ <h2>Donate (Large)</h2> | |||
| 108 | 108 | ></script> | |
| 109 | 109 | </div> | |
| 110 | 110 | ||
| 111 | + <div id="subscribe-sm"> | ||
| 112 | + <h2>Subscribe (Small)</h2> | ||
| 113 | + <script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU" | ||
| 114 | + data-button="subscribe" | ||
| 115 | + data-name="Subscribe!" | ||
| 116 | + data-amount="1.00" | ||
| 117 | + data-size="small" | ||
| 118 | + data-a3="1.00" | ||
| 119 | + data-p3="1" | ||
| 120 | + data-t3="M" | ||
| 121 | + ></script> | ||
| 122 | + </div> | ||
| 123 | + | ||
| 124 | + <div id="subscribe-lg"> | ||
| 125 | + <h2>Subscribe (Large)</h2> | ||
| 126 | + <script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU" | ||
| 127 | + data-button="subscribe" | ||
| 128 | + data-name="Subscribe!" | ||
| 129 | + data-amount="1.00" | ||
| 130 | + data-size="large" | ||
| 131 | + ></script> | ||
| 132 | + </div> | ||
| 133 | + | ||
| 111 | 134 | <div id="hosted-sm"> | |
| 112 | 135 | <h2>Hosted (Small)</h2> | |
| 113 | 136 | <script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU" | |
@@ -136,4 +159,4 @@ <h2>QR Code</h2> | |||
| 136 | 159 | </div> | |
| 137 | 160 | ||
| 138 | 161 | </body> | |
| 139 | - </html> | ||
| 162 | + </html> | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments