1 // http://civicrm.org/licensing
3 function civicrm_billingblock_add_cc_logos() {
4 $.each(CRM
.config
.creditCardTypes
, function(key
, val
) {
5 var html
= '<a href="#" title="' + val
+ '" class="crm-credit_card_type-logo-' + key
+ '"><span>' + val
+ '</span></a>';
6 $('.crm-credit_card_type-logos').append(html
);
8 cj('.crm-credit_card_type-logo-' + key
).click(function() {
9 cj('#crm-container .credit_card_type-section #credit_card_type').val(val
);
10 cj('#crm-container .credit_card_type-section a').css('opacity', 0.4);
11 cj('#crm-container .credit_card_type-section .crm-credit_card_type-logo-' + key
).css('opacity', 1);
15 // Hide the CC type field (redundant)
16 $('#crm-container .credit_card_type-section select#credit_card_type').hide();
17 $('#crm-container .credit_card_type-section .label').hide();
19 // Select according to the number entered
20 cj('#crm-container input#credit_card_number').change(function() {
21 var ccnumtype
= cj(this).val().substr(0, 4);
23 // Semi-hide all images, we will un-hide the right one afterwards
24 cj('#crm-container .credit_card_type-section a').css('opacity', 0.4);
25 cj('#credit_card_type').val('');
27 // https://en.wikipedia.org/wiki/Credit_card_numbers
28 if (ccnumtype
.substr(0, 1) == '3') {
29 cj('#credit_card_type').val('Amex');
30 cj('#crm-container .credit_card_type-section .crm-credit_card_type-logo-visa').css('opacity', 1);
32 else if (ccnumtype
.substr(0, 2) >= '51' && ccnumtype
.substr(0, 2) <= '55') {
33 cj('#credit_card_type').val('MasterCard');
34 cj('#crm-container .credit_card_type-section .crm-credit_card_type-logo-mastercard').css('opacity', 1);
36 else if (ccnumtype
.substr(0, 1) == '4') {
37 cj('#credit_card_type').val('Visa');
38 cj('#crm-container .credit_card_type-section .crm-credit_card_type-logo-visa').css('opacity', 1);
44 civicrm_billingblock_add_cc_logos();
46 $('#crm-container').on('crmFormLoad', '*', function() {
47 civicrm_billingblock_add_cc_logos();