2012-05-15 23:31:49 +00:00
|
|
|
var $j = jQuery.noConflict();
|
|
|
|
// give pledge box focus
|
|
|
|
$j(function() {
|
|
|
|
$j('#id_preapproval_amount').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$j().ready(function() {
|
2012-05-16 00:58:07 +00:00
|
|
|
// cache these to speed things up
|
2012-05-15 23:31:49 +00:00
|
|
|
var inputbox = $j('#id_preapproval_amount');
|
|
|
|
var submitbutton = $j('#pledgesubmit');
|
2012-05-21 18:06:48 +00:00
|
|
|
var fakesubmitbutton = $j('#fakepledgesubmit');
|
2012-08-01 12:52:39 +00:00
|
|
|
var anonbox = $j('#anonbox input');
|
2012-08-01 16:08:31 +00:00
|
|
|
var ackSection = $j('#ack_section');
|
2012-08-06 19:44:43 +00:00
|
|
|
var supporterName = $j('#pass_supporter_name').html();
|
2012-10-18 18:17:11 +00:00
|
|
|
var ackName = $j('#id_ack_name').val();
|
|
|
|
var ackDedication = $j('#id_ack_dedication').val();
|
2014-12-15 05:56:08 +00:00
|
|
|
var giveForm = $j('#give_form');
|
|
|
|
var activeOffer = $j('li:has(#offers_list input[type=radio]:checked)');
|
2012-08-06 19:44:43 +00:00
|
|
|
if(ackDedication == 'None') {
|
|
|
|
ackDedication = '';
|
|
|
|
}
|
2012-08-01 12:52:53 +00:00
|
|
|
var acks = {
|
2012-08-06 19:44:43 +00:00
|
|
|
ack_name: ackName,
|
|
|
|
ack_dedication: ackDedication
|
2012-08-01 12:52:53 +00:00
|
|
|
};
|
2012-08-01 13:08:07 +00:00
|
|
|
|
2012-10-18 18:17:11 +00:00
|
|
|
var ackAnon = $j('#id_anonymous').val();
|
2012-08-06 19:44:43 +00:00
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
// we're not letting people submit arbitrary links
|
|
|
|
$j('#id_ack_link').attr('disabled', 'disabled');
|
2012-05-15 23:31:49 +00:00
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
// take an input button from the premiums list
|
|
|
|
// find the premium amount in its associated span class
|
|
|
|
// convert to usable integer form and return
|
2012-05-16 00:58:07 +00:00
|
|
|
var canonicalize = function(amt) {
|
|
|
|
amt = amt.siblings('span.menu-item-price').html();
|
|
|
|
amt = amt.split('$')[1];
|
|
|
|
amt = parseInt(amt);
|
|
|
|
return amt;
|
|
|
|
}
|
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
// if amount in pledge box is too small to qualify for premium, highlight pledge
|
|
|
|
// box and submit button in alert color and disable the pledge input button
|
|
|
|
// with a helpful message
|
2012-05-16 00:58:07 +00:00
|
|
|
var mayday = function() {
|
|
|
|
inputbox.css({'border-color': '#e35351', 'background-color': '#e35351', 'color': 'white'});
|
2012-08-01 12:52:39 +00:00
|
|
|
fakesubmitbutton.val("Pledge at least $"+amount+" to claim that premium");
|
2012-05-21 18:06:48 +00:00
|
|
|
fakesubmitbutton.show();
|
|
|
|
submitbutton.hide();
|
2012-05-16 00:58:07 +00:00
|
|
|
submitbutton.attr('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
// when pledge covers premium again, revert to original styling and reactivate button
|
2012-05-16 00:58:07 +00:00
|
|
|
var allclear = function() {
|
|
|
|
inputbox.css({'border-color': '#8dc63f', 'background-color': 'white', 'color': '#3d4e53'});
|
2012-05-21 18:06:48 +00:00
|
|
|
fakesubmitbutton.hide();
|
|
|
|
submitbutton.show();
|
2012-05-16 00:58:07 +00:00
|
|
|
submitbutton.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
2012-08-06 19:44:43 +00:00
|
|
|
// make acknowledgements input area active
|
2012-08-01 12:52:39 +00:00
|
|
|
var activate = function(mySpan) {
|
|
|
|
$j('#'+mySpan).removeClass('ack_inactive').addClass('ack_active');
|
|
|
|
$j('#'+mySpan+' input').removeAttr('disabled');
|
2012-08-01 12:52:53 +00:00
|
|
|
ack = acks[mySpan];
|
|
|
|
$j('#id_'+mySpan).val(ack);
|
2012-08-01 12:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make mandatory premium input area inactive: greyed-out and not modifiable
|
|
|
|
var deactivate = function(mySpan) {
|
|
|
|
$j('#'+mySpan).removeClass('ack_active').addClass('ack_inactive');
|
2012-08-01 12:52:53 +00:00
|
|
|
$j('#'+mySpan+' input[type=text]').val('').attr('disabled', 'disabled');
|
2012-08-01 12:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fill mandatory premium link input with supporter page
|
|
|
|
var activateLink = function() {
|
|
|
|
$j('#ack_link').removeClass('ack_inactive').addClass('ack_active');
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty mandatory premium link
|
|
|
|
var deactivateLink = function() {
|
|
|
|
$j('#ack_link').removeClass('ack_active').addClass('ack_inactive');
|
|
|
|
}
|
|
|
|
|
|
|
|
var anonymizeName = function() {
|
|
|
|
deactivate('ack_name');
|
2012-08-01 12:52:53 +00:00
|
|
|
$j('#id_ack_name').val('Anonymous');
|
2012-08-01 12:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// selectively highlight/grey out acknowledgements supporter is eligible for
|
|
|
|
var rectifyAcknowledgements = function(current) {
|
|
|
|
var anon = anonbox.prop("checked");
|
2012-10-13 02:31:18 +00:00
|
|
|
if (!current) {
|
|
|
|
current = 0 ;
|
|
|
|
}
|
2012-08-01 12:52:39 +00:00
|
|
|
if (current < 25) {
|
|
|
|
deactivate('ack_name');
|
|
|
|
deactivateLink();
|
|
|
|
deactivate('ack_dedication');
|
2012-08-01 16:08:31 +00:00
|
|
|
ackSection.html('');
|
2012-08-01 12:52:39 +00:00
|
|
|
} else if (current >= 25 && current < 50) {
|
|
|
|
deactivateLink();
|
|
|
|
deactivate('ack_dedication');
|
|
|
|
if (anon) {
|
|
|
|
anonymizeName();
|
|
|
|
} else {
|
|
|
|
activate('ack_name');
|
|
|
|
}
|
2012-08-01 16:08:31 +00:00
|
|
|
ackSection.html(' as a Supporter');
|
2012-08-01 12:52:39 +00:00
|
|
|
} else if (current >= 50 && current < 100) {
|
|
|
|
deactivate('ack_dedication');
|
|
|
|
if (anon) {
|
|
|
|
anonymizeName();
|
|
|
|
deactivateLink();
|
|
|
|
} else {
|
|
|
|
activate('ack_name');
|
|
|
|
activateLink();
|
|
|
|
}
|
2012-08-01 16:08:31 +00:00
|
|
|
ackSection.html(' as a Benefactor');
|
2012-08-01 12:52:39 +00:00
|
|
|
} else if (current >= 100) {
|
|
|
|
activate('ack_dedication');
|
|
|
|
if (anon) {
|
|
|
|
anonymizeName();
|
|
|
|
deactivateLink();
|
|
|
|
} else {
|
|
|
|
activate('ack_name');
|
|
|
|
activateLink();
|
|
|
|
}
|
2012-08-01 16:08:31 +00:00
|
|
|
ackSection.html(' as a Bibliophile');
|
2012-08-01 12:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize the acknowledgements fields. if we've prefilled the pledge info,
|
|
|
|
// use that.
|
|
|
|
current = inputbox.val();
|
2012-08-06 19:44:43 +00:00
|
|
|
if (ackAnon == 'True') {
|
|
|
|
anonbox.prop("checked", true);
|
|
|
|
}
|
2012-10-13 02:31:18 +00:00
|
|
|
rectifyAcknowledgements(current);
|
2012-08-01 12:52:39 +00:00
|
|
|
|
|
|
|
// when user clicks a premium, ensure it is compatible with the pledge box amount
|
2012-10-05 15:53:06 +00:00
|
|
|
// if pledge box was empty, assume they wanted value of premium
|
2012-05-15 23:31:49 +00:00
|
|
|
$j('#premiums_list input').on("click", function() {
|
2014-12-15 05:56:08 +00:00
|
|
|
|
2012-05-16 00:58:07 +00:00
|
|
|
amount = canonicalize($j(this));
|
2012-05-15 23:31:49 +00:00
|
|
|
current = inputbox.val();
|
2012-10-05 15:53:06 +00:00
|
|
|
if (current == "" && !isNaN(amount)) {
|
|
|
|
inputbox.val(amount);
|
2012-10-05 16:00:20 +00:00
|
|
|
rectifyAcknowledgements(amount);
|
2012-10-05 15:53:06 +00:00
|
|
|
} else if (current<amount) {
|
2012-05-16 00:58:07 +00:00
|
|
|
mayday();
|
2012-05-15 23:31:49 +00:00
|
|
|
} else if (submitbutton.attr('disabled')) {
|
2012-05-16 00:58:07 +00:00
|
|
|
allclear();
|
2012-05-15 23:31:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-15 05:56:08 +00:00
|
|
|
// when user clicks an offer
|
|
|
|
$j('#offers_list li').on("click", function() {
|
|
|
|
if ( $j(this).attr('id') == 'give_offer'){
|
|
|
|
$j('#anonbox').addClass('off');
|
|
|
|
giveForm.removeClass('off').addClass('on');
|
|
|
|
$j(this).find('input[type=radio]').attr('checked', 'checked');
|
|
|
|
} else {
|
|
|
|
var radio = $j(this).find('input[type=radio]');
|
|
|
|
if (radio.length ) {
|
|
|
|
giveForm.removeClass('on').addClass('off');
|
|
|
|
$j('#anonbox').removeClass('off');
|
|
|
|
radio.attr('checked', 'checked');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
// when user changes the pledge box contents, ensure they are compatible
|
|
|
|
// with the selected pledge
|
2012-05-15 23:31:49 +00:00
|
|
|
inputbox.keyup(function() {
|
|
|
|
current = $j(this).val();
|
2012-05-16 18:03:14 +00:00
|
|
|
|
|
|
|
if (current[0] == '$') {
|
|
|
|
// remove leading $ to prevent form validation error
|
|
|
|
current = current.slice(1);
|
|
|
|
$j(this).val(current);
|
|
|
|
}
|
|
|
|
|
2012-08-01 12:52:39 +00:00
|
|
|
try {
|
|
|
|
amount = canonicalize($j('input[type=radio]:checked'));
|
|
|
|
} catch(error) {
|
|
|
|
amount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current<amount && amount !=0) {
|
2012-05-16 00:58:07 +00:00
|
|
|
mayday();
|
2012-05-15 23:31:49 +00:00
|
|
|
} else if (submitbutton.attr('disabled')) {
|
2012-05-16 00:58:07 +00:00
|
|
|
allclear();
|
2012-05-15 23:31:49 +00:00
|
|
|
}
|
2012-08-01 12:52:39 +00:00
|
|
|
|
|
|
|
rectifyAcknowledgements(current);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when supporter clicks the anonymity box, change name & link field to
|
|
|
|
// display whatever acks page will display: WYSIWYG
|
|
|
|
anonbox.change(function() {
|
|
|
|
rectifyAcknowledgements(current);
|
|
|
|
});
|
|
|
|
|
2012-08-01 12:52:53 +00:00
|
|
|
// if supporters enter a name or dedication, keep track of them
|
|
|
|
// so they doesn't get thrown away if they decrease & re-increase pledge, or
|
2012-08-01 12:52:39 +00:00
|
|
|
// anonymize and then de-anonymize
|
|
|
|
$j('#ack_name input[type=text]').change(function() {
|
2012-08-01 12:52:53 +00:00
|
|
|
acks['ack_name'] = $j(this).val();
|
|
|
|
});
|
|
|
|
$j('#ack_dedication input[type=text]').change(function() {
|
|
|
|
acks['ack_dedication'] = $j(this).val();
|
2012-08-01 12:52:39 +00:00
|
|
|
});
|
|
|
|
|
2012-05-15 23:31:49 +00:00
|
|
|
});
|