2012-05-15 23:31:49 +00:00
|
|
|
var $j = jQuery.noConflict();
|
|
|
|
// give pledge box focus
|
|
|
|
$j(function() {
|
|
|
|
$j('#id_preapproval_amount').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
// if amount in pledge box is too small to qualify for premium, call attention to it
|
|
|
|
// and disable the input button with a helpful message
|
|
|
|
// when they fix it, revert to original styling and reactivate button
|
|
|
|
|
|
|
|
$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-16 00:58:07 +00:00
|
|
|
var canonicalize = function(amt) {
|
|
|
|
// takes an input button from the premiums list
|
|
|
|
// finds the premium amount its associated the span class
|
|
|
|
// converts to usable integer form and returns
|
|
|
|
amt = amt.siblings('span.menu-item-price').html();
|
|
|
|
amt = amt.split('$')[1];
|
|
|
|
amt = parseInt(amt);
|
|
|
|
return amt;
|
|
|
|
}
|
|
|
|
|
|
|
|
var mayday = function() {
|
|
|
|
// highlights pledge box and submit button in alert color
|
|
|
|
// disables submit button and overwrites with help text
|
|
|
|
inputbox.css({'border-color': '#e35351', 'background-color': '#e35351', 'color': 'white'});
|
|
|
|
submitbutton.css({'background-color': '#e35351', 'cursor': 'default', 'font-weight': 'normal', 'font-size': '15px'});
|
|
|
|
submitbutton.val("You must pledge at least $"+amount+" for that premium");
|
|
|
|
submitbutton.attr('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
var allclear = function() {
|
|
|
|
// returns pledge box and submit button to conventional colors
|
|
|
|
// enables submit button and rewrites with original text
|
|
|
|
inputbox.css({'border-color': '#8dc63f', 'background-color': 'white', 'color': '#3d4e53'});
|
|
|
|
submitbutton.css({'background-color': '#8dc63f', 'cursor': 'pointer', 'font-weight': 'bold', 'font-size': '17px'});
|
|
|
|
submitbutton.val("Modify Pledge");
|
|
|
|
submitbutton.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
2012-05-15 23:31:49 +00:00
|
|
|
$j('#premiums_list input').on("click", function() {
|
2012-05-16 00:58:07 +00:00
|
|
|
// when user clicks a premium, ensure it is compatible with the pledge box amount
|
|
|
|
amount = canonicalize($j(this));
|
2012-05-15 23:31:49 +00:00
|
|
|
current = inputbox.val();
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
inputbox.keyup(function() {
|
2012-05-16 00:58:07 +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
|
|
|
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-05-16 00:58:07 +00:00
|
|
|
amount = canonicalize($j('input[type=radio]:checked'));
|
2012-05-15 23:31:49 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|