-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22713 from colemanw/billingBlockCleanup
[REF] Cleanup billingBlock.js
- Loading branch information
Showing
1 changed file
with
47 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,61 @@ | ||
// http://civicrm.org/licensing | ||
(function($) { | ||
(function($, _) { | ||
|
||
/** | ||
* Adds the icons of enabled credit cards | ||
* Handles clicking on a icon. | ||
* Changes the icon depending on the credit card number. | ||
* Removes spaces and dashes from credit card numbers. | ||
*/ | ||
function civicrm_billingblock_creditcard_helper() { | ||
$(function() { | ||
$.each(CRM.config.creditCardTypes, function(key, val) { | ||
var html = '<a href="#" data-card_type=" + key + " title="' + val + '" class="crm-credit_card_type-icon-' + val.css_key + '"><span>' + val.label + '</span></a>'; | ||
$('.crm-credit_card_type-icons').append(html); | ||
$(function() { | ||
$.each(CRM.config.creditCardTypes, function(key, val) { | ||
var html = '<a href="#" title="' + _.escape(val.label) + '" class="crm-credit_card_type-icon-' + val.css_key + '"><span>' + _.escape(val.label) + '</span></a>'; | ||
$('.crm-credit_card_type-icons').append(html); | ||
|
||
$('.crm-credit_card_type-icon-' + val.css_key).click(function() { | ||
$('#credit_card_type').val(key); | ||
$('.crm-container .credit_card_type-section a').css('opacity', 0.25); | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 1); | ||
return false; | ||
}); | ||
$('.crm-credit_card_type-icon-' + val.css_key).click(function() { | ||
$('#credit_card_type').val(key); | ||
$('.crm-container .credit_card_type-section a').css('opacity', 0.25); | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 1); | ||
return false; | ||
}); | ||
}); | ||
|
||
// Hide the CC type field (redundant) | ||
$('#credit_card_type, .label', '.crm-container .credit_card_type-section').hide(); | ||
// Hide the CC type field (redundant) | ||
$('#credit_card_type, .label', '.crm-container .credit_card_type-section').hide(); | ||
|
||
// set the card type value as default if any found | ||
var cardtype = $('#credit_card_type').val(); | ||
if (cardtype) { | ||
$.each(CRM.config.creditCardTypes, function(key, val) { | ||
// highlight the selected card type icon | ||
if (key === cardtype) { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 1); | ||
} | ||
else { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 0.25); | ||
} | ||
}); | ||
} | ||
// set the card type value as default if any found | ||
var cardtype = $('#credit_card_type').val(); | ||
if (cardtype) { | ||
$.each(CRM.config.creditCardTypes, function(key, val) { | ||
// highlight the selected card type icon | ||
if (key === cardtype) { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 1); | ||
} | ||
else { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + val.css_key).css('opacity', 0.25); | ||
} | ||
}); | ||
} | ||
|
||
// Select according to the number entered | ||
$('.crm-container input#credit_card_number').change(function() { | ||
var ccnumber = cj(this).val(); | ||
// Select according to the number entered | ||
$('.crm-container input#credit_card_number').change(function() { | ||
var ccnumber = $(this).val(); | ||
|
||
// Remove spaces and dashes | ||
ccnumber = ccnumber.replace(/[- ]/g, ''); | ||
cj(this).val(ccnumber); | ||
// Remove spaces and dashes | ||
ccnumber = ccnumber.replace(/[- ]/g, ''); | ||
$(this).val(ccnumber); | ||
|
||
// Semi-hide all images, we will un-hide the right one afterwards | ||
$('.crm-container .credit_card_type-section a').css('opacity', 0.25); | ||
$('#credit_card_type').val(''); | ||
// Semi-hide all images, we will un-hide the right one afterwards | ||
$('.crm-container .credit_card_type-section a').css('opacity', 0.25); | ||
$('#credit_card_type').val(''); | ||
|
||
civicrm_billingblock_set_card_type(ccnumber); | ||
}); | ||
setCardtype(ccnumber); | ||
}); | ||
} | ||
|
||
function civicrm_billingblock_set_card_type(ccnumber) { | ||
var card_values = CRM.config.creditCardTypes; | ||
$.each(card_values, function(key, spec) { | ||
if (ccnumber.match('^' + spec.pattern + '$')) { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + spec.css_key).css('opacity', 1); | ||
$('select#credit_card_type').val(key); | ||
return false; | ||
} | ||
}); | ||
} | ||
function setCardtype(ccnumber) { | ||
$.each(CRM.config.creditCardTypes, function(key, spec) { | ||
if (ccnumber.match('^' + spec.pattern + '$')) { | ||
$('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + spec.css_key).css('opacity', 1); | ||
$('select#credit_card_type').val(key); | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
civicrm_billingblock_creditcard_helper(); | ||
}); | ||
|
||
})(CRM.$); | ||
})(CRM.$, CRM._); |