forked from Automattic/camptix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camptix.js
48 lines (38 loc) · 1.51 KB
/
camptix.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
/**
* CampTix Javascript
*
* Hopefully runs during wp_footer.
*/
(function($){
var tix = $( '#tix' )
$( tix ).addClass( 'tix-js' );
if ( $( tix ).hasClass( 'tix-has-dynamic-receipts' ) ) {
refresh_receipt_emails = function() {
var fields = $('.tix-field-email');
var html = '';
var previously_checked = $('[name="tix_receipt_email_js"]:checked').val();
var checked = false;
for ( var i = 0; i < fields.length; i++ ) {
var value = fields[i].value;
if ( value.length < 1 ) continue;
var field = $('<div><label><input type="radio" name="tix_receipt_email_js" /> <span>container</span></label><br /></div>');
$(field).find('span').text(value);
$(field).find('input').attr('value', value);
if ( previously_checked != undefined && previously_checked == value && ! checked )
checked = $(field).find('input').attr('checked','checked');
html += $(field).html();
}
if ( html.length < 1 )
html = '<label>Please enter the e-mail addresses in the forms above.</label>';
if ( html == $('#tix-receipt-emails-list').html() )
return;
$('#tix-receipt-emails-list').html(html);
previously_checked = $('[name="tix_receipt_email_js"]:checked').val();
if ( previously_checked == undefined || previously_checked.length < 1 )
$('#tix-receipt-emails-list input:first').attr('checked','checked');
}
$('.tix-field-email').change(refresh_receipt_emails);
$('.tix-field-email').keyup(refresh_receipt_emails);
$(document).ready(refresh_receipt_emails);
}
}(jQuery));