2014-09-09 18:24:27 -07:00
|
|
|
(function() {
|
|
|
|
var donationForm = document.getElementById('donation-form');
|
2014-12-23 20:22:15 -08:00
|
|
|
|
|
|
|
function field(name) {
|
|
|
|
return donationForm.querySelector(
|
|
|
|
'input[name=donation\\[' + name + '\\]]');
|
|
|
|
}
|
2014-09-09 18:24:27 -07:00
|
|
|
|
|
|
|
var checkout = StripeCheckout.configure({
|
2014-09-09 19:06:38 -07:00
|
|
|
key: donationForm.getAttribute('data-checkout-publishable-key'),
|
2014-09-09 18:41:58 -07:00
|
|
|
image: donationForm.getAttribute('data-checkout-image'),
|
2014-09-09 18:24:27 -07:00
|
|
|
token: function(token) {
|
2014-12-23 20:22:15 -08:00
|
|
|
field('stripe_token').value = token.id;
|
|
|
|
field('stripe_token_type').value = token.type;
|
|
|
|
field('donor_email').value = token.email;
|
2014-09-09 18:24:27 -07:00
|
|
|
donationForm.submit();
|
2014-12-23 20:22:15 -08:00
|
|
|
},
|
|
|
|
bitcoin: true
|
2014-09-09 18:24:27 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
donationForm.addEventListener('submit', function(e) {
|
2014-12-23 20:22:15 -08:00
|
|
|
if (!field('stripe_token').value) {
|
2014-09-09 18:24:27 -07:00
|
|
|
e.preventDefault();
|
|
|
|
|
2014-12-23 20:22:15 -08:00
|
|
|
var amount = Math.floor(parseFloat(field('amount').value) * 100);
|
2014-09-09 18:24:27 -07:00
|
|
|
|
|
|
|
if (!isNaN(amount)) {
|
|
|
|
checkout.open({
|
|
|
|
name: 'Dress to Impress',
|
|
|
|
description: 'Donation (thank you!)',
|
|
|
|
amount: amount
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-09-26 13:17:36 -07:00
|
|
|
|
|
|
|
var toggle = document.getElementById('success-thanks-toggle-description');
|
|
|
|
toggle.addEventListener('click', function() {
|
|
|
|
var desc = document.getElementById('description');
|
|
|
|
var attr = 'data-show';
|
|
|
|
if (desc.hasAttribute(attr)) {
|
|
|
|
desc.removeAttribute(attr);
|
|
|
|
} else {
|
|
|
|
desc.setAttribute(attr, true);
|
|
|
|
}
|
|
|
|
});
|
2014-09-09 18:24:27 -07:00
|
|
|
})();
|