1 // Shim for old versions of jQuery
2 if (typeof jQuery
.fn
.prop
!== 'function') {
3 jQuery
.fn
.prop
= jQuery
.fn
.attr
;
7 * Javascript Module for managing webform_civicrm options for select elements.
10 function defaultBoxes(newType
, defaultName
) {
11 var oldType
= newType
== 'radio' ? 'checkbox' : 'radio';
12 var defaultValue
= $('input[name*="[civicrm_defaults]"]:checked').val() || '';
13 $('input:'+oldType
+'[name*="[civicrm_defaults]"]').each(function() {
15 var val
= ele
.attr('value');
16 var classes
= ele
.attr('class');
17 var id
= ele
.attr('id');
18 if (newType
== 'radio') {
19 var name
= defaultName
+ '[' + defaultValue
+ ']';
22 var name
= defaultName
+ '[' + val
+ ']';
24 ele
.replaceWith('<input type="'+newType
+'" class="'+classes
+'" id="'+id
+'" name="'+name
+'" value="'+val
+'">');
27 $('input:[name*="[civicrm_defaults]"][value="'+defaultValue
+'"]').prop('checked', true);
29 $('input:checkbox.select-all-civi-defaults').change(function() {
30 if ($(this).is(':checked')) {
31 $('input.civicrm-default').not(':disabled').prop('checked', true);
34 $('input.civicrm-default, input.select-all-civi-defaults').prop('checked', false);
37 $('input:radio[name*="[civicrm_defaults]"]').change(function() {
38 if ($(this).is(':checked')) {
39 $('input:radio[name*="[civicrm_defaults]"]').attr('name', defaultName
+ '[' + $(this).val() + ']');
44 D
.behaviors
.webform_civicrmOptions
= {
45 attach: function (context
) {
46 $('input.civicrm-enabled', context
).once('wf-civi').change(function() {
47 if ($(this).is(':checked') ) {
48 $(this).parents('tr').find('input.civicrm-label, input.civicrm-default').prop('disabled', false);
51 $(this).parents('tr').find('input.civicrm-label, input.civicrm-default').prop('disabled', true).prop('checked', false);
53 if ($(this).parents('tr').find('input.civicrm-label').val() == '') {
54 var val
= $(this).parents('tr').find('span.civicrm-option-name').text();
55 $(this).parents('tr').find('input.civicrm-label').val(val
);
59 $('input.select-all-civi-options').once('wf-civi').change(function() {
60 if ($(this).is(':checked') ) {
61 $('input.civicrm-enabled, input.select-all-civi-options').prop('checked', true);
64 $('input.civicrm-enabled, input.select-all-civi-options, input.select-all-civi-defaults').prop('checked', false);
66 $('input.civicrm-enabled').change();
69 var defaultName
= 'civicrm_options_fieldset[civicrm_defaults]';
71 var multiple
= $('input[name="extra[multiple]"]');
72 if (multiple
.is(':checkbox')) {
73 multiple
.once('wf-civi').change(function() {
74 var type
= $(this).is(':checked') ? 'checkbox' : 'radio';
75 defaultBoxes(type
, defaultName
);
78 else if (multiple
.attr('value') !== '1') {
79 defaultBoxes('radio', defaultName
);
82 $('a.tabledrag-handle, a.tabledrag-toggle-weight').not('.live-options-hide a').wrap('<div class="live-options-hide" />');
84 $('input[name="extra[civicrm_live_options]"]').once('wf-civi').change(function() {
85 if ($(this).is(':checked')) {
86 switch ($(this).attr('value')) {
88 $('.live-options-hide').show();
89 $('.live-options-show').hide();
90 $('.tabledrag-hide.visible').removeClass('visible').show();
93 $('.live-options-hide').hide();
94 $('.live-options-show').show();
95 $('.tabledrag-hide:visible').addClass('visible').hide();
96 $('input.civicrm-enabled, input.select-all-civi-options').prop('checked', true);
97 $('input.civicrm-enabled').change();