Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- var rememberLevel = readCookie('levelId');
- var otherAmt = readCookie('otherAmt');
- var coverFees = readCookie('coverFees');
- var deleteCookie = function(name) {
- document.cookie = name + '=;expires= Thu, 01 Jan 1970 00:00:01 GMT;';
- };
- var formatMoney = function(amount) {
- amountInCents = Number(amount);
- var i = parseInt(amount = Math.abs(+amount || 0).toFixed(2), 10) + '',
- j = (j = i.length) > 3 ? j % 3 : 0,
- formattedMoney = '$' + (j ? i.substr(0, j) + ',' : '') +
- i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + ',') +
- '.' + Math.abs(amount - i).toFixed(2).slice(2);
- formattedMoney = formattedMoney.replace('.00', '');
- return formattedMoney;
- }
- var populateBtn = function(activeAmt) {
- if ($('#cover_fees').is(':checked')) {
- var btnText = 'Donate ' + activeAmt;
- }
- else {
- var btnText = 'Donate';
- }
- if ($('#pstep_next').length > 0) {
- $('#pstep_next').text(btnText);
- }
- if ($('#pstep_finish').length > 0) {
- $('#pstep_finish').text(btnText);
- }
- }
- var getAmt = function() {
- if ($('.other-amount input[type="radio"]').is(':checked')) {
- selectAmt = Number(delimitNumbers($('.donation-level-user-entered input').val()));
- document.cookie="levelId=other";
- document.cookie="otherAmt=" + selectAmt;
- }
- else {
- $("[id^=level_standardexpanded]").each(function() {
- if ($(this).is(':checked')) {
- var selectedLevelId = $(this).prop('id');
- selectAmt = Number(delimitNumbers($(this).parent().next().children('.donation-level-amount-container').text()));
- document.cookie="levelId=" + selectedLevelId;
- }
- });
- }
- activeAmtAdd = Number(strRound(delimitNumbers(selectAmt)*.06248),2);
- activeAmtAdd = activeAmtAdd + .26;
- activeAmt = strRound(delimitNumbers(selectAmt + activeAmtAdd));
- activeAmtFormat = formatMoney(activeAmt);
- paypalAmtAdd = Number(strRound(delimitNumbers(selectAmt)*.0585),2);
- paypalAmtAdd = paypalAmtAdd + .3;
- paypalAmt = strRound(delimitNumbers(paypalAmtAdd + selectAmt));
- paypalAmtFormat = formatMoney(paypalAmt);
- $('.cover_fees_total').html('for a total of <strong>' + activeAmtFormat + ' (Credit Card)</strong> or <strong>' + paypalAmtFormat + ' (PayPal)');
- paymentType = $('.payment-type-selections input[name="responsive_payment_typepay_typeradio"]').val();
- if ($('.external-payment .payment-type-option').hasClass('selected')) {
- console.log('use paypal');
- donateAmt = paypalAmtFormat;
- }
- else {
- console.log('use cc');
- donateAmt = activeAmtFormat;
- }
- }
- function delimitNumbers(str) {
- return (str + '').replace(/[^\d.-]/g, '');
- }
- function removeNonNumbers(str) {
- return (str + '').replace(/[^0-9\.]+/g, '');
- }
- function strRound(str) {
- str = removeNonNumbers(str).split('.', 2);
- if (str[1]) {
- str[1] = str[1].substring(0,2);
- }
- str = str.join('.');
- return str;
- }
- function readCookie(name) {
- var nameEQ = name + '=';
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
- }
- return null;
- }
- $('#cc_fees_row').insertAfter('.donation-levels');
- $('.donation-level-user-entered').parent().addClass('other-amount');
- if(rememberLevel != undefined || rememberLevel != null) {
- $('#' + rememberLevel).prop('checked', true);
- $('.donation-level-user-entered input[type="text"]').val('');
- if (rememberLevel == 'other') {
- $('.other-amount input[type="radio"]').prop('checked', true);
- $('.donation-level-user-entered input[type="text"]').val(otherAmt);
- }
- }
- if (coverFees == 'true') {
- $('#cover_fees').prop('checked', true);
- $('#cover_feeshidden').val('true');
- getAmt();
- populateBtn(donateAmt);
- } else {
- $('#cover_feeshidden').val('false');
- }
- $('#cover_fees, .donation-level-container').change(function(){
- if ($('#cover_fees').is(':checked')) {
- getAmt();
- }
- else {
- getAmt();
- deleteCookie('coverFees');
- deleteCookie('levelId');
- deleteCookie('otherAmt');
- }
- populateBtn(donateAmt);
- });
- $('.internal-payment a').click(function(){
- populateBtn(activeAmtFormat);
- });
- $('.external-payment a').click(function(){
- populateBtn(paypalAmtFormat);
- });
- $('#ProcessForm').submit(function() {
- if ($('#cover_fees').is(':checked')) {
- getAmt();
- $('#cover_feeshidden').val('true');
- $('.other-amount input[type="radio"]').prop('checked', true);
- $('.donation-level-user-entered input[type="text"]').val(donateAmt);
- document.cookie = 'coverFees=true';
- return true;
- }
- else {
- $('#cover_feeshidden').val('false');
- deleteCookie('coverFees');
- deleteCookie('levelId');
- deleteCookie('otherAmt');
- return true;
- }
- });
- });
Add Comment
Please, Sign In to add comment