1(function($) { 2 $.fn.cpdonation = function() { 3 return this.each(function() { 4 // Donation widget elements 5 var widget = $(this); 6 var itemNameEl = $(this).find('.item_name'); 7 var amountEl = $(this).find('.amount'); 8 9 var amount2El = $(this).find('.amount2'); 10 var fixedAmountEl = $(this).find('.fixed-amount'); 11 var additionalFixedEl = $(this).find('.additional-fixed'); 12 var quantityEl = $(this).find('.quantity'); 13 var categoryEl = $(this).find('.donation_category'); 14 var commentsEl = $(this).find('.comments'); 15 16 var totalAmountEl = $(this).find('.total_amt'); 17 var submitButton = $(this).find('.paypalSubmit'); 18 var cpQuantityEl = $(this).find('.cp_quantity'); 19 20 // Default values 21 var itemName = itemNameEl.val(); 22 var defaultDonation = fixedAmountEl.html(); 23 var q = 0; 24 25 if(additionalFixedEl) { 26 var additionalFixed = parseFloat(additionalFixedEl.html()); 27 if(!isNaN(additionalFixed)) { 28 var initialAmount = parseFloat(defaultDonation) + additionalFixed; 29 totalAmountEl.html(initialAmount); 30 amountEl.val(initialAmount); 31 } 32 } 33 34 amountEl.on('keydown', function(e){if(!((e.keyCode > 47 && e.keyCode < 59) || ( e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode == 110 || e.keyCode == 190) || e.keyCode == 8)){e.preventDefault();}}); 35 36 // Type 1 37 amountEl.on('keyup', function(){ 38 var donation = amountEl.val(); 39 if(!isNaN(donation)){ 40 var total = donation; 41 amountEl.val(total); 42 totalAmountEl.html(total); 43 if(additionalFixedEl) { 44 if(!isNaN(additionalFixed)) { 45 total = total + additionalFixed; 46 totalAmountEl.html(total); 47 amountEl.val(total); 48 } 49 } 50 }else{ 51 totalAmountEl.html(defaultDonation); 52 } 53 }); 54 55 //Type 2 56 amount2El.on('keyup', function(){ 57 var donation = parseFloat(fixedAmountEl.html()); 58 var quantity = (q != 0) ? q : 1; 59 var additionalDonation = parseFloat(amount2El.val()); 60 if(!isNaN(additionalDonation)){ 61 var total = additionalDonation+(donation*quantity); 62 amountEl.val(total); 63 totalAmountEl.html(total); 64 if(additionalFixedEl) { 65 if(!isNaN(additionalFixed)) { 66 total = total + additionalFixed; 67 totalAmountEl.html(total); 68 amountEl.val(total); 69 } 70 } 71 }else{ 72 totalAmountEl.html(defaultDonation); 73 } 74 }); 75 76 //Type 3 and Type 4 77 quantityEl.change(function(){ 78 //amount2El.val(''); 79 var quantity = (parseFloat($(this).find('option:selected').val()) > 1) ? parseFloat($(this).find('option:selected').val()) : 1; 80 q = quantity; 81 if(!isNaN(quantity)){ 82 var total = quantity*parseFloat(fixedAmountEl.html())+amount2El.val()*1; 83 cpQuantityEl.val(quantity); 84 if(additionalFixedEl) { 85 additionalFixed = parseFloat(additionalFixedEl.html()); 86 if(!isNaN(additionalFixed)) { 87 total = total + additionalFixed; 88 } 89 } 90 amountEl.val(total); 91 totalAmountEl.html(total); 92 }else{ 93 totalAmountEl.html(defaultDonation); 94 } 95 }); 96 97 //Submit 98 submitButton.on('click', function() { 99 var quantity = cpQuantityEl.val(); 100 if (quantity != '0') { 101 itemNameEl.val(itemName + ' (quantity ' + quantity + ')'); 102 } 103 if(typeof(categoryEl.val()) != 'undefined') { 104 var tempName = itemNameEl.val(); 105 itemNameEl.val(tempName + ' Category: ' + categoryEl.val()); 106 } 107 if(typeof(commentsEl.val()) != 'undefined') { 108 var tempName = itemNameEl.val(); 109 itemNameEl.val(tempName + ' Comments: ' + commentsEl.val()); 110 } 111 widget.submit(); 112 }); 113 }); 114 } 115})(jQuery); 116 117jQuery(document).ready(function() { 118 jQuery('.cpDonation').cpdonation(); 119});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.