2014-12-02 16:27:04 +00:00
|
|
|
/* Copyright (C) 2012-2013 Denver Gingerich,
|
|
|
|
** Copyright (C) 2013-2014 Bradley M. Kuhn.
|
2014-12-03 21:55:17 +00:00
|
|
|
** License: GPLv3-or-later
|
2014-12-02 16:27:04 +00:00
|
|
|
** Find a copy of GPL at https://sfconservancy.org/GPLv3
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('.toggle-content').hide();
|
|
|
|
|
|
|
|
$('.toggle-control')
|
|
|
|
.addClass('clickable')
|
|
|
|
.bind('click', function() {
|
|
|
|
var $control = $(this);
|
|
|
|
var $parent = $control.parents('.toggle-unit');
|
|
|
|
|
|
|
|
$parent.toggleClass('expanded');
|
|
|
|
$parent.find('.toggle-content').slideToggle();
|
|
|
|
|
|
|
|
// if control has HTML5 data attributes, use to update text
|
|
|
|
if ($parent.hasClass('expanded')) {
|
|
|
|
$control.html($control.attr('data-expanded-text'));
|
|
|
|
} else {
|
|
|
|
$control.html($control.attr('data-text'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('a.donate-now')
|
|
|
|
.addClass('clickable')
|
|
|
|
.bind('click', function() {
|
|
|
|
var $control = $('#donate-box');
|
|
|
|
|
|
|
|
$control.toggleClass('expanded');
|
|
|
|
$control.find('.toggle-content').slideUp("slow");
|
|
|
|
$control.find('.toggle-content').slideDown("slow");
|
|
|
|
});
|
2014-12-03 21:20:57 +00:00
|
|
|
$(".t-shirt-size-selector").hide();
|
2014-12-03 18:33:26 +00:00
|
|
|
$('input[name=os1]:radio').change(function() {
|
|
|
|
var input=$(this);
|
|
|
|
var value = input.val();
|
|
|
|
if (value == "Yes") {
|
|
|
|
$(".t-shirt-size-selector").show();
|
Modify PayPal "no_shipping" var via t-shirt choice
According to
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
no_shipping has the following values:
0: prompt for an address, but do not require one
1: do not prompt for an address
2: prompt for an address, and require one
The default is 0.
Ideally, any time they change wantGift, even in a pure HTML form, we'd
change it between 0 and 2 as appropriate (i.e., we need the address if
they want the t-shirt).
However, I couldn't find an easy way to make this modification in pure
CSS or HTML, so it only happens in Javascript-enabled browsers.
This is still graceful degradation, since the only impact is in cases
where a non-Javascript user fails to give us an address, and we have to
email later to get the shipping address.
2014-12-03 23:50:53 +00:00
|
|
|
$("#no_shipping").val("2");
|
2014-12-03 18:33:26 +00:00
|
|
|
} else {
|
|
|
|
$(".t-shirt-size-selector").hide();
|
Modify PayPal "no_shipping" var via t-shirt choice
According to
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
no_shipping has the following values:
0: prompt for an address, but do not require one
1: do not prompt for an address
2: prompt for an address, and require one
The default is 0.
Ideally, any time they change wantGift, even in a pure HTML form, we'd
change it between 0 and 2 as appropriate (i.e., we need the address if
they want the t-shirt).
However, I couldn't find an easy way to make this modification in pure
CSS or HTML, so it only happens in Javascript-enabled browsers.
This is still graceful degradation, since the only impact is in cases
where a non-Javascript user fails to give us an address, and we have to
email later to get the shipping address.
2014-12-03 23:50:53 +00:00
|
|
|
$("#no_shipping").val("0");
|
2014-12-03 18:33:26 +00:00
|
|
|
}
|
|
|
|
});
|
2014-12-04 01:40:41 +00:00
|
|
|
$('*#amount').addClass("valid");
|
|
|
|
$('*#amount').on('input', function() {
|
2014-12-02 16:31:43 +00:00
|
|
|
var input=$(this);
|
|
|
|
var value = input.val();
|
2014-12-04 01:40:41 +00:00
|
|
|
var errorElement=$("span#error", input.parent());
|
2014-12-02 22:04:05 +00:00
|
|
|
var noCommaValue = value;
|
|
|
|
noCommaValue = value.replace(/,/g, "");
|
|
|
|
var re = /^((\d{1,3}(,?\d{3})*?(\.\d{0,2})?)|\d+(\.\d{0,2})?)$/;
|
2014-12-03 23:10:45 +00:00
|
|
|
var isValid = ( re.test(value) &&
|
|
|
|
parseInt(noCommaValue) >= parseInt(input.attr("minimum")));
|
2014-12-02 16:31:43 +00:00
|
|
|
if (isValid) {
|
|
|
|
input.removeClass("invalid").addClass("valid");
|
|
|
|
errorElement.removeClass("form-error-show").addClass("form-error");
|
2014-12-02 22:26:55 +00:00
|
|
|
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
|
2014-12-02 16:31:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
input.removeClass("valid").addClass("invalid");
|
|
|
|
errorElement.removeClass("form-error").addClass("form-error-show");
|
|
|
|
}
|
2014-12-02 18:30:18 +00:00
|
|
|
});
|
2014-12-02 22:26:55 +00:00
|
|
|
$("#supporter-form-submit").click(function(event){
|
2014-12-03 23:10:45 +00:00
|
|
|
var valid = $('.amount').hasClass("valid");
|
2014-12-02 22:26:55 +00:00
|
|
|
if (! valid) {
|
|
|
|
$("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
|
|
|
|
.css("font-weight", "bold").css("font-size", "150%");
|
|
|
|
event.preventDefault();
|
|
|
|
} else {
|
|
|
|
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
|
|
|
|
}
|
|
|
|
});
|
2014-12-02 18:30:18 +00:00
|
|
|
/* Handle toggling of annual/monthly form selections */
|
|
|
|
$('.supporter-type-selection#monthly').hide();
|
|
|
|
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
|
|
|
|
|
|
|
|
$("a[href$='monthly']").bind('click', function() {
|
|
|
|
$('.supporter-type-selection#annual').hide();
|
|
|
|
$('.supporter-type-selection#monthly').show();
|
|
|
|
$('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
|
|
|
|
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
|
2014-12-02 23:02:32 +00:00
|
|
|
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
|
2014-12-02 18:30:18 +00:00
|
|
|
});
|
|
|
|
$("a[href$='annual']").bind('click', function() {
|
|
|
|
$('.supporter-type-selection#annual').show();
|
|
|
|
$('.supporter-type-selection#monthly').hide();
|
|
|
|
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
|
|
|
|
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
|
|
|
|
});
|
2014-12-02 23:25:42 +00:00
|
|
|
$( ".footnote-mark" ).tooltip({
|
|
|
|
items: "a",
|
|
|
|
hide: { duration: 5000 },
|
|
|
|
position: {
|
|
|
|
my: "center bottom-20",
|
|
|
|
at: "center left",
|
|
|
|
using: function( position, feedback ) {
|
|
|
|
$( this ).css( position );
|
|
|
|
$( "<div>" )
|
|
|
|
.addClass( "arrow" )
|
|
|
|
.addClass( feedback.vertical )
|
|
|
|
.addClass( feedback.horizontal )
|
|
|
|
.appendTo( this );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: function() {
|
|
|
|
return $('.footnote-1-text').text();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-12-02 18:30:18 +00:00
|
|
|
|
|
|
|
$(window).load(function () {
|
|
|
|
verifySelctionCorrectOnPageLoad = function() {
|
|
|
|
var ourURL = document.URL;
|
|
|
|
if (ourURL.search("#monthly") > 0) {
|
|
|
|
$('.supporter-type-selection#annual').hide();
|
|
|
|
$('.supporter-type-selection#monthly').show();
|
|
|
|
$('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
|
|
|
|
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
|
|
|
|
}
|
|
|
|
if (ourURL.search("#annual") > 0) {
|
|
|
|
$('.supporter-type-selection#monthly').hide();
|
|
|
|
$('.supporter-type-selection#annual').show();
|
|
|
|
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
|
|
|
|
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (location.hash) {
|
|
|
|
setTimeout(verifySelctionCorrectOnPageLoad, 1);
|
|
|
|
}
|
|
|
|
window.addEventListener("hashchange", verifySelctionCorrectOnPageLoad);
|
|
|
|
});
|