supporter: Improve shirt selection JavaScript.

* Add an animation for state changes.
* Set the start state by triggering the event on the selection at page load.
  Firefox at least remembers the selected button on page load.  This avoids
  a situation where the user says they want a shirt, reload, and now the
  size selection is invisible because we used to hide that unconditionally.
This commit is contained in:
Brett Smith 2017-01-01 15:28:33 -05:00
parent b93cc61e8b
commit 9d855fda08

View file

@ -86,18 +86,18 @@ $(document).ready(function() {
$otherTextControl.find('.donate-box-highlight').fadeIn(10000);
}, 500);
});
$(".t-shirt-size-selector").hide();
$('input[name=on0]:radio').change(function() {
$('input[name=on0]:radio').on('change', function(event, duration) {
var $input = $(this);
var wantShirt = $input.val() == "wantGiftYes";
var $form = $input.parents('form').last();
var $tShirtSelector = $('.t-shirt-size-selector', $form);
var $noShippingSelector = $('input[name=no_shipping]', $form);
if ($input.val() == "wantGiftYes") {
$tShirtSelector.show();
$noShippingSelector.val("2");
$('input', $tShirtSelector).prop('disabled', wantShirt);
$('input[name=no_shipping]', $form).val(wantShirt ? '2' : '0');
if (wantShirt) {
$tShirtSelector.slideDown(duration);
} else {
$tShirtSelector.hide();
$noShippingSelector.val("0");
$tShirtSelector.slideUp(duration);
}
});
}).filter(':checked').trigger('change', 0);
});