-
Notifications
You must be signed in to change notification settings - Fork 10
/
donation.js
126 lines (118 loc) · 5.57 KB
/
donation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* donation page extra js, nice one-time/recur switcher
*
*/
/*jslint indent: 2 */
/*global CRM, ts */
CRM.$(function ($) {
'use strict';
var recurSettings = (typeof CRM.contributionrecur == 'undefined') ? CRM.vars.contributionrecur : CRM.contributionrecur;
if ($.trim($("#crm-main-content-wrapper #intro_text").html()).length > 0) {
$('#crm-main-content-wrapper').has('#intro_text').addClass('has-intro-text');
$('.crm-contribution-main-form-block').has('#intro_text').before($('#intro_text'));
}
$('#priceset-div').before('<div class="gift-type-select"><div id="monthly-gift"><label>Monthly Gift</label></div><div id="one-time-gift"><label>One-time Gift</label></div></div>');
if ($('#is_recur').prop('checked')) {
setRecur();
}
else {
setOneTime();
}
$('#one-time-gift').click(function() {
$('#is_recur').prop('checked',false);
setOneTime();
});
$('#monthly-gift').click(function() {
$('#is_recur').prop('checked',true);
setRecur();
});
$("#is_recur").change(function() {
if (this.checked) {
setRecur();
}
else {
setOneTime();
}
});
/* when choosing a radio amount, if amount is zero, move the cursor to the other amount box, otherwise zero out the other amount box */
$(recurSettings.one_time_gift_section).find('input').click(function() {
var amt = parseFloat($(this).attr('data-amount'));
if (amt == 0) {
$(recurSettings.other_one_time_amount_section).find('input').focus();
}
else {
$(recurSettings.other_one_time_amount_section).find('input').val('0').blur();
}
});
$(recurSettings.monthly_gift_section).find('input').click(function() {
var amt = parseFloat($(this).attr('data-amount'));
if (amt == 0) {
$(recurSettings.other_amount_section).find('input').focus();
}
else {
$(recurSettings.other_amount_section).find('input').val('0').blur();
}
});
/* when a user clicks in the other amount, set the radio amount to zero */
$(recurSettings.other_one_time_amount_section).find('input').focus(function() {
var amt = parseFloat($(recurSettings.one_time_gift_section).find('input:checked').attr('data-amount'));
if (0 < amt) {
$(recurSettings.one_time_gift_section).find('input').prop('checked',false);
$(recurSettings.one_time_gift_section).find('input').filter(zeroDataAmount).trigger('click');
}
});
$(recurSettings.other_amount_section).find('input').focus(function() {
var amt = parseFloat($(recurSettings.monthly_gift_section).find('input:checked').attr('data-amount'));
if (0 < amt) {
$(recurSettings.monthly_gift_section).find('input').prop('checked',false).blur();
$(recurSettings.monthly_gift_section).find('input').filter(zeroDataAmount).trigger('click').blur(); // .prop('checked',true);
}
});
/* filter function to identify the 0 amount radio option */
function zeroDataAmount(index, elem) {
var amt = parseFloat($(elem).attr('data-amount'));
return (amt == 0);
}
// when switching to recur, set all the one-time 'data' values to 0!
function setRecur() {
$('#one-time-gift').removeClass('selected');
$('#monthly-gift').addClass('selected');
var giftAmount = $(recurSettings.one_time_gift_section).find('input:checked').attr('data-amount');
var otherGiftAmount = $(recurSettings.other_one_time_amount_section).find('input').val();
$(recurSettings.one_time_gift_section).find('input').prop('checked',false);
$(recurSettings.one_time_gift_section).find('input').filter(zeroDataAmount).trigger('click');
$(recurSettings.one_time_gift_section).hide('slow');
$(recurSettings.other_one_time_amount_section).find('input').val('0').blur();
$(recurSettings.other_one_time_amount_section).hide('slow');
$(recurSettings.monthly_gift_section).find('input').prop('checked',false);
$(recurSettings.monthly_gift_section).show('slow');
$(recurSettings.other_amount_section).show('slow');
$(recurSettings.monthly_gift_section).find('input').prop('checked',false);
var calcThis = $(recurSettings.monthly_gift_section).find('input[data-amount="'+giftAmount+'"]').trigger('click');
if (calcThis.length > 0) {
calculateCheckboxLineItemValue(calcThis);
}
$(recurSettings.other_amount_section).find('input').val(otherGiftAmount).blur();
$('#amount_sum_label').text('Recurring gift amount');
}
function setOneTime() {
$('#one-time-gift').addClass('selected');
$('#monthly-gift').removeClass('selected');
var giftAmount = $(recurSettings.monthly_gift_section).find('input:checked').attr('data-amount');
var otherGiftAmount = $(recurSettings.other_amount_section).find('input').val();
$(recurSettings.monthly_gift_section).find('input').prop('checked',false).blur();
$(recurSettings.monthly_gift_section).find('input').filter(zeroDataAmount).trigger('click').blur(); // .prop('checked',true);
$(recurSettings.monthly_gift_section).hide('slow');
$(recurSettings.other_amount_section).find('input').val('0').blur();
$(recurSettings.other_amount_section).hide('slow');
$(recurSettings.one_time_gift_section).show('slow');
$(recurSettings.other_one_time_amount_section).show('slow');
$(recurSettings.one_time_gift_section).find('input').prop('checked',false).blur();
var calcThis = $(recurSettings.one_time_gift_section).find('input[data-amount="'+giftAmount+'"]').trigger('click');
if (calcThis.length > 0) {
calculateCheckboxLineItemValue(calcThis);
}
$(recurSettings.other_one_time_amount_section).find('input').val(otherGiftAmount).blur();
$('#amount_sum_label').text('One-time gift amount');
}
});