| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d2e5157 commit d1a14fb
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,33 +1,31 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | - var constants = require('./constants'), | ||
| 5 | - css = require('./util/css'); | ||
| 4 | + var template = require('./util/template'), | ||
| 5 | + constants = require('./constants'), | ||
| 6 | + css = require('./util/css'), | ||
| 7 | + hasCss = false; | ||
| 6 | 8 | ||
| 7 | 9 | ||
| 8 | 10 | module.exports = function Button(label, data, config) { | |
| 9 | - var locale = data.get('lc') || 'en_US', | ||
| 10 | - btn = document.createElement('button'), | ||
| 11 | - btnLogo = document.createElement('span'), | ||
| 12 | - btnContent = document.createElement('span'); | ||
| 11 | + var model, locale, style; | ||
| 13 | 12 | ||
| 14 | - // Defaults | ||
| 15 | 13 | config = config || {}; | |
| 16 | - config.style = config.style || constants.DEFAULT_STYLE; | ||
| 17 | - config.size = config.size || constants.DEFAULT_SIZE; | ||
| 18 | - | ||
| 19 | - btn.className += 'paypal-button ' + config.style + ' ' + config.size; | ||
| 20 | - | ||
| 21 | - btnLogo.className = 'paypal-button-logo'; | ||
| 22 | - btnLogo.innerHTML = '<img src="' + constants.LOGO + '" />'; | ||
| 23 | - | ||
| 24 | - btnContent.className = 'paypal-button-content'; | ||
| 25 | - btnContent.innerHTML = constants.STRINGS[locale][label].replace('{wordmark}', '<img src="' + constants.WORDMARK[config.style] + '" alt="PayPal" />'); | ||
| 26 | - | ||
| 27 | - btn.appendChild(btnLogo); | ||
| 28 | - btn.appendChild(btnContent); | ||
| 29 | - | ||
| 30 | - css.inject(document.getElementsByTagName('head')[0], constants.STYLES); | ||
| 31 | - | ||
| 32 | - return btn; | ||
| 14 | + locale = data.get('lc') || constants.DEFAULT_LOCALE; | ||
| 15 | + style = config.style || constants.DEFAULT_STYLE; | ||
| 16 | + | ||
| 17 | + model = { | ||
| 18 | + style: style, | ||
| 19 | + size: config.size || constants.DEFAULT_SIZE, | ||
| 20 | + logo: constants.LOGO, | ||
| 21 | + wordmark: constants.WORDMARK[style], | ||
| 22 | + label: constants.STRINGS[locale][label] | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + if (!hasCss) { | ||
| 26 | + hasCss = true; | ||
| 27 | + css.inject(document.getElementsByTagName('head')[0], constants.STYLES); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + return template(constants.TEMPLATE.button, model); | ||
| 33 | 31 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,8 +34,12 @@ module.exports = { | |||
| 34 | 34 | ||
| 35 | 35 | DEFAULT_STYLE: 'primary', | |
| 36 | 36 | ||
| 37 | + DEFAULT_LOCALE: 'en_US', | ||
| 38 | + | ||
| 37 | 39 | DEFAULT_ENV: 'www', | |
| 38 | 40 | ||
| 41 | + TEMPLATES: $TEMPLATES$, | ||
| 42 | + | ||
| 39 | 43 | STRINGS: $STRINGS$, | |
| 40 | 44 | ||
| 41 | 45 | STYLES: '$STYLES$', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,6 @@ module.exports = function factory(business, raw, config) { | |||
| 74 | 74 | return { | |
| 75 | 75 | label: label, | |
| 76 | 76 | type: type, | |
| 77 | - el: el | ||
| 77 | + el: document.createElement('div').innerHTML = el | ||
| 78 | 78 | }; | |
| 79 | 79 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,66 +2,67 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | var constants = require('./constants'), | |
| 5 | - Button = require('./button'); | ||
| 5 | + template = require('./util/template'), | ||
| 6 | + Button = require('./button'); | ||
| 6 | 7 | ||
| 7 | 8 | ||
| 8 | 9 | module.exports = function Form(type, data, config) { | |
| 9 | - var form = document.createElement('form'), | ||
| 10 | - hidden = document.createElement('input'), | ||
| 11 | - paraElem = document.createElement('p'), | ||
| 12 | - labelElem = document.createElement('label'), | ||
| 13 | - inputTextElem = document.createElement('input'), | ||
| 14 | - selectElem = document.createElement('select'), | ||
| 15 | - optionElem = document.createElement('option'), | ||
| 16 | - items = data.items, | ||
| 17 | - optionFieldArr = [], | ||
| 18 | - item, child, label, input, key, selector, optionField, fieldDetails = {}, fieldDetail, fieldValue, field, labelText, btn; | ||
| 19 | - | ||
| 20 | - // Defaults | ||
| 21 | - config = config || {}; | ||
| 22 | - config.host = config.host || constants.DEFAULT_HOST; | ||
| 23 | - | ||
| 24 | - form.method = 'post'; | ||
| 25 | - form.action = constants.PAYPAL_URL.replace('{host}', config.host); | ||
| 26 | - form.className = 'paypal-button-widget'; | ||
| 27 | - form.target = '_top'; | ||
| 28 | - | ||
| 29 | - inputTextElem.type = 'text'; | ||
| 30 | - inputTextElem.className = 'paypal-input'; | ||
| 31 | - paraElem.className = 'paypal-group'; | ||
| 32 | - labelElem.className = 'paypal-label'; | ||
| 33 | - selectElem.className = 'paypal-select'; | ||
| 34 | - | ||
| 35 | - hidden.type = 'hidden'; | ||
| 36 | - | ||
| 37 | - for (key in items) { | ||
| 38 | - item = items[key]; | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - if (item.hasOptions) { | ||
| 42 | - optionFieldArr.push(item); | ||
| 43 | - } else if (item.isEditable) { | ||
| 44 | - input = inputTextElem.cloneNode(true); | ||
| 45 | - input.name = item.key; | ||
| 46 | - input.value = item.value; | ||
| 47 | - | ||
| 48 | - label = labelElem.cloneNode(true); | ||
| 49 | - // FIXME: This needs to resolve to user strings | ||
| 50 | - labelText = item.key; | ||
| 51 | - label.htmlFor = item.key; | ||
| 52 | - label.appendChild(document.createTextNode(labelText)); | ||
| 53 | - label.appendChild(input); | ||
| 54 | - | ||
| 55 | - child = paraElem.cloneNode(true); | ||
| 56 | - child.appendChild(label); | ||
| 57 | - form.appendChild(child); | ||
| 58 | - } else { | ||
| 59 | - input = child = hidden.cloneNode(true); | ||
| 60 | - input.name = item.key; | ||
| 61 | - input.value = item.value; | ||
| 62 | - form.appendChild(child); | ||
| 63 | - } | ||
| 64 | - } | ||
| 10 | + // var form = document.createElement('form'), | ||
| 11 | + // hidden = document.createElement('input'), | ||
| 12 | + // paraElem = document.createElement('p'), | ||
| 13 | + // labelElem = document.createElement('label'), | ||
| 14 | + // inputTextElem = document.createElement('input'), | ||
| 15 | + // selectElem = document.createElement('select'), | ||
| 16 | + // optionElem = document.createElement('option'), | ||
| 17 | + // items = data.items, | ||
| 18 | + // optionFieldArr = [], | ||
| 19 | + // item, child, label, input, key, selector, optionField, fieldDetails = {}, fieldDetail, fieldValue, field, labelText, btn; | ||
| 20 | + | ||
| 21 | + // // Defaults | ||
| 22 | + // config = config || {}; | ||
| 23 | + // config.host = config.host || constants.DEFAULT_HOST; | ||
| 24 | + | ||
| 25 | + // form.method = 'post'; | ||
| 26 | + // form.action = constants.PAYPAL_URL.replace('{host}', config.host); | ||
| 27 | + // form.className = 'paypal-button-widget'; | ||
| 28 | + // form.target = '_top'; | ||
| 29 | + | ||
| 30 | + // inputTextElem.type = 'text'; | ||
| 31 | + // inputTextElem.className = 'paypal-input'; | ||
| 32 | + // paraElem.className = 'paypal-group'; | ||
| 33 | + // labelElem.className = 'paypal-label'; | ||
| 34 | + // selectElem.className = 'paypal-select'; | ||
| 35 | + | ||
| 36 | + // hidden.type = 'hidden'; | ||
| 37 | + | ||
| 38 | + // for (key in items) { | ||
| 39 | + // item = items[key]; | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + // if (item.hasOptions) { | ||
| 43 | + // optionFieldArr.push(item); | ||
| 44 | + // } else if (item.isEditable) { | ||
| 45 | + // input = inputTextElem.cloneNode(true); | ||
| 46 | + // input.name = item.key; | ||
| 47 | + // input.value = item.value; | ||
| 48 | + | ||
| 49 | + // label = labelElem.cloneNode(true); | ||
| 50 | + // // FIXME: This needs to resolve to user strings | ||
| 51 | + // labelText = item.key; | ||
| 52 | + // label.htmlFor = item.key; | ||
| 53 | + // label.appendChild(document.createTextNode(labelText)); | ||
| 54 | + // label.appendChild(input); | ||
| 55 | + | ||
| 56 | + // child = paraElem.cloneNode(true); | ||
| 57 | + // child.appendChild(label); | ||
| 58 | + // form.appendChild(child); | ||
| 59 | + // } else { | ||
| 60 | + // input = child = hidden.cloneNode(true); | ||
| 61 | + // input.name = item.key; | ||
| 62 | + // input.value = item.value; | ||
| 63 | + // form.appendChild(child); | ||
| 64 | + // } | ||
| 65 | + // } | ||
| 65 | 66 | ||
| 66 | 67 | // optionFieldArr = sortOptionFields(optionFieldArr); | |
| 67 | 68 | ||
@@ -128,34 +129,28 @@ module.exports = function Form(type, data, config) { | |||
| 128 | 129 | // form.appendChild(child); | |
| 129 | 130 | // } | |
| 130 | 131 | // } | |
| 131 | - | ||
| 132 | - btn = new Button(type, data, config); | ||
| 133 | - | ||
| 134 | - // Safari won't let you set read-only attributes on buttons. | ||
| 135 | - try { | ||
| 136 | - btn.type = 'submit'; | ||
| 137 | - } catch (e) { | ||
| 138 | - btn.setAttribute('type', 'submit'); | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - // Add the correct button | ||
| 142 | - form.appendChild(btn); | ||
| 143 | - | ||
| 144 | - return form; | ||
| 132 | + | ||
| 133 | + var model = { | ||
| 134 | + data: data.items, | ||
| 135 | + button: new Button(type, data, config), | ||
| 136 | + url: constants.PAYPAL_URL.replace('{host}', config.host || constants.DEFAULT_HOST) | ||
| 137 | + }; | ||
| 138 | + | ||
| 139 | + return template(constants.TEMPLATE.form, model); | ||
| 145 | 140 | }; | |
| 146 | 141 | ||
| 147 | 142 | ||
| 148 | 143 | ||
| 149 | - /** | ||
| 150 | - * Sort Optional Fields by display order | ||
| 151 | - */ | ||
| 152 | - function sortOptionFields(optionFieldArr) { | ||
| 153 | - optionFieldArr.sort(function (a, b) { | ||
| 154 | - return a.displayOrder - b.displayOrder; | ||
| 155 | - }); | ||
| 144 | + // /** | ||
| 145 | + // * Sort Optional Fields by display order | ||
| 146 | + // */ | ||
| 147 | + // function sortOptionFields(optionFieldArr) { | ||
| 148 | + // optionFieldArr.sort(function (a, b) { | ||
| 149 | + // return a.displayOrder - b.displayOrder; | ||
| 150 | + // }); | ||
| 156 | 151 | ||
| 157 | - return optionFieldArr; | ||
| 158 | - } | ||
| 152 | + // return optionFieldArr; | ||
| 153 | + // } | ||
| 159 | 154 | ||
| 160 | 155 | ||
| 161 | 156 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + <button class="paypal-button <%= style %> <%= size %>" type="submit"> | ||
| 2 | + <span class="paypal-button-logo"> | ||
| 3 | + <img src="<%= logo %>" /> | ||
| 4 | + </span> | ||
| 5 | + <span class="paypal-button-content"> | ||
| 6 | + <img src="<%= wordmark %>" alt="PayPal" /> | ||
| 7 | + </span> | ||
| 8 | + </button> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + <form method="post" action="<%= url %>" class="paypal-button-widget" target="_top"> | ||
| 2 | + <% for (var key in data) { %> | ||
| 3 | + <input type="hidden" name="<%= key %>" value="<%= data[key] %>" /> | ||
| 4 | + <% } %> | ||
| 5 | + | ||
| 6 | + <%= button %> | ||
| 7 | + </form> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,9 +21,24 @@ module.exports = function (grunt) { | |||
| 21 | 21 | logo: '$LOGO$', | |
| 22 | 22 | primary: '$WORDMARK_PRIMARY$', | |
| 23 | 23 | secondary: '$WORDMARK_SECONDARY$', | |
| 24 | - strings: '$STRINGS$' | ||
| 24 | + strings: '$STRINGS$', | ||
| 25 | + templates: '$TEMPLATES$' | ||
| 25 | 26 | }; | |
| 26 | 27 | ||
| 28 | + function processTemplates(str) { | ||
| 29 | + var files = grunt.file.expand('src/theme/**/*.html'), | ||
| 30 | + templates = {}, | ||
| 31 | + name; | ||
| 32 | + | ||
| 33 | + files.forEach(function (file) { | ||
| 34 | + name = file.split(/src\/theme\/(.*).html/); | ||
| 35 | + name = name[1]; | ||
| 36 | + | ||
| 37 | + templates[name] = trim(grunt.file.read(file)); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + return str.replace(tokens.templates, JSON.stringify(templates)); | ||
| 41 | + } | ||
| 27 | 42 | ||
| 28 | 43 | function processCss(str) { | |
| 29 | 44 | var styles = trim(grunt.file.read('src/theme/css/index.css')); | |
@@ -75,6 +90,7 @@ module.exports = function (grunt) { | |||
| 75 | 90 | grunt.registerTask('themify', 'Bundles the theme files into the JavaScript.', function () { | |
| 76 | 91 | var out = grunt.file.read(src); | |
| 77 | 92 | ||
| 93 | + out = processTemplates(out); | ||
| 78 | 94 | out = processCss(out); | |
| 79 | 95 | out = processImages(out); | |
| 80 | 96 | out = processContent(out); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments