1 // http://civicrm.org/licensing
5 $.each(CRM
.config
.creditCardTypes
, function(key
, val
) {
6 var html
= '<a href="#" title="' + _
.escape(val
.label
) + '" class="crm-credit_card_type-icon-' + val
.css_key
+ '"><span>' + _
.escape(val
.label
) + '</span></a>';
7 $('.crm-credit_card_type-icons').append(html
);
9 $('.crm-credit_card_type-icon-' + val
.css_key
).click(function() {
10 $('#credit_card_type').val(key
);
11 $('.crm-container .credit_card_type-section a').css('opacity', 0.25);
12 $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val
.css_key
).css('opacity', 1);
17 // Hide the CC type field (redundant)
18 $('#credit_card_type, .label', '.crm-container .credit_card_type-section').hide();
20 // set the card type value as default if any found
21 var cardtype
= $('#credit_card_type').val();
23 $.each(CRM
.config
.creditCardTypes
, function(key
, val
) {
24 // highlight the selected card type icon
25 if (key
=== cardtype
) {
26 $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val
.css_key
).css('opacity', 1);
29 $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val
.css_key
).css('opacity', 0.25);
34 // Select according to the number entered
35 $('.crm-container input#credit_card_number').change(function() {
36 var ccnumber
= $(this).val();
38 // Remove spaces and dashes
39 ccnumber
= ccnumber
.replace(/[- ]/g, '');
40 $(this).val(ccnumber
);
42 // Semi-hide all images, we will un-hide the right one afterwards
43 $('.crm-container .credit_card_type-section a').css('opacity', 0.25);
44 $('#credit_card_type').val('');
46 setCardtype(ccnumber
);
49 function setCardtype(ccnumber
) {
50 $.each(CRM
.config
.creditCardTypes
, function(key
, spec
) {
51 if (ccnumber
.match('^' + spec
.pattern
+ '$')) {
52 $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + spec
.css_key
).css('opacity', 1);
53 $('select#credit_card_type').val(key
);