Guest User

Untitled

a guest
Aug 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2. var rememberLevel = readCookie('levelId');
  3. var otherAmt = readCookie('otherAmt');
  4. var coverFees = readCookie('coverFees');
  5.  
  6. var deleteCookie = function(name) {
  7. document.cookie = name + '=;expires= Thu, 01 Jan 1970 00:00:01 GMT;';
  8. };
  9.  
  10. var formatMoney = function(amount) {
  11. amountInCents = Number(amount);
  12. var i = parseInt(amount = Math.abs(+amount || 0).toFixed(2), 10) + '',
  13. j = (j = i.length) > 3 ? j % 3 : 0,
  14. formattedMoney = '$' + (j ? i.substr(0, j) + ',' : '') +
  15. i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + ',') +
  16. '.' + Math.abs(amount - i).toFixed(2).slice(2);
  17.  
  18. formattedMoney = formattedMoney.replace('.00', '');
  19.  
  20. return formattedMoney;
  21. }
  22.  
  23. var populateBtn = function(activeAmt) {
  24. if ($('#cover_fees').is(':checked')) {
  25. var btnText = 'Donate ' + activeAmt;
  26. }
  27. else {
  28. var btnText = 'Donate';
  29. }
  30. if ($('#pstep_next').length > 0) {
  31. $('#pstep_next').text(btnText);
  32. }
  33. if ($('#pstep_finish').length > 0) {
  34. $('#pstep_finish').text(btnText);
  35. }
  36. }
  37.  
  38. var getAmt = function() {
  39. if ($('.other-amount input[type="radio"]').is(':checked')) {
  40. selectAmt = Number(delimitNumbers($('.donation-level-user-entered input').val()));
  41. document.cookie="levelId=other";
  42. document.cookie="otherAmt=" + selectAmt;
  43. }
  44. else {
  45. $("[id^=level_standardexpanded]").each(function() {
  46. if ($(this).is(':checked')) {
  47. var selectedLevelId = $(this).prop('id');
  48. selectAmt = Number(delimitNumbers($(this).parent().next().children('.donation-level-amount-container').text()));
  49. document.cookie="levelId=" + selectedLevelId;
  50. }
  51. });
  52. }
  53. activeAmtAdd = Number(strRound(delimitNumbers(selectAmt)*.06248),2);
  54. activeAmtAdd = activeAmtAdd + .26;
  55. activeAmt = strRound(delimitNumbers(selectAmt + activeAmtAdd));
  56. activeAmtFormat = formatMoney(activeAmt);
  57.  
  58. paypalAmtAdd = Number(strRound(delimitNumbers(selectAmt)*.0585),2);
  59. paypalAmtAdd = paypalAmtAdd + .3;
  60. paypalAmt = strRound(delimitNumbers(paypalAmtAdd + selectAmt));
  61. paypalAmtFormat = formatMoney(paypalAmt);
  62.  
  63.  
  64. $('.cover_fees_total').html('for a total of <strong>' + activeAmtFormat + ' (Credit Card)</strong> or <strong>' + paypalAmtFormat + ' (PayPal)');
  65.  
  66. paymentType = $('.payment-type-selections input[name="responsive_payment_typepay_typeradio"]').val();
  67.  
  68. if ($('.external-payment .payment-type-option').hasClass('selected')) {
  69. console.log('use paypal');
  70. donateAmt = paypalAmtFormat;
  71. }
  72. else {
  73. console.log('use cc');
  74. donateAmt = activeAmtFormat;
  75. }
  76. }
  77.  
  78. function delimitNumbers(str) {
  79. return (str + '').replace(/[^\d.-]/g, '');
  80. }
  81.  
  82. function removeNonNumbers(str) {
  83. return (str + '').replace(/[^0-9\.]+/g, '');
  84. }
  85.  
  86. function strRound(str) {
  87. str = removeNonNumbers(str).split('.', 2);
  88. if (str[1]) {
  89. str[1] = str[1].substring(0,2);
  90. }
  91. str = str.join('.');
  92. return str;
  93. }
  94.  
  95. function readCookie(name) {
  96. var nameEQ = name + '=';
  97. var ca = document.cookie.split(';');
  98. for(var i=0;i < ca.length;i++) {
  99. var c = ca[i];
  100. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  101. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  102. }
  103. return null;
  104. }
  105.  
  106. $('#cc_fees_row').insertAfter('.donation-levels');
  107. $('.donation-level-user-entered').parent().addClass('other-amount');
  108.  
  109. if(rememberLevel != undefined || rememberLevel != null) {
  110. $('#' + rememberLevel).prop('checked', true);
  111. $('.donation-level-user-entered input[type="text"]').val('');
  112.  
  113. if (rememberLevel == 'other') {
  114. $('.other-amount input[type="radio"]').prop('checked', true);
  115. $('.donation-level-user-entered input[type="text"]').val(otherAmt);
  116. }
  117. }
  118.  
  119.  
  120. if (coverFees == 'true') {
  121. $('#cover_fees').prop('checked', true);
  122. $('#cover_feeshidden').val('true');
  123. getAmt();
  124. populateBtn(donateAmt);
  125. } else {
  126. $('#cover_feeshidden').val('false');
  127. }
  128.  
  129. $('#cover_fees, .donation-level-container').change(function(){
  130. if ($('#cover_fees').is(':checked')) {
  131. getAmt();
  132. }
  133. else {
  134. getAmt();
  135. deleteCookie('coverFees');
  136. deleteCookie('levelId');
  137. deleteCookie('otherAmt');
  138. }
  139. populateBtn(donateAmt);
  140. });
  141.  
  142. $('.internal-payment a').click(function(){
  143. populateBtn(activeAmtFormat);
  144. });
  145.  
  146. $('.external-payment a').click(function(){
  147. populateBtn(paypalAmtFormat);
  148. });
  149.  
  150. $('#ProcessForm').submit(function() {
  151. if ($('#cover_fees').is(':checked')) {
  152. getAmt();
  153. $('#cover_feeshidden').val('true');
  154. $('.other-amount input[type="radio"]').prop('checked', true);
  155. $('.donation-level-user-entered input[type="text"]').val(donateAmt);
  156. document.cookie = 'coverFees=true';
  157. return true;
  158. }
  159. else {
  160. $('#cover_feeshidden').val('false');
  161. deleteCookie('coverFees');
  162. deleteCookie('levelId');
  163. deleteCookie('otherAmt');
  164. return true;
  165. }
  166. });
  167. });
Add Comment
Please, Sign In to add comment