PageSourceSearch

https://aktion.solidarische-moderne.de/wp-content/uploads/civicrm/…/radiobuttons/radiobuttons.js?r=BFEjSde_DE

js solidarische-moderne.de collected 2026-10-02 08:29:19 UTC 4,064 bytes, 104 lines download raw bytes

1(function($, _, ts) {
2
3  /**
4   * Make radio buttons more pretty.
5   */
6  CRM.radiobuttonsFormRadiosAsButtons = function(selector, options) {
7    options = typeof options !== 'undefined' ? options : {};
8
9    var button_width = options.button_width || '';
10    var button_width_class = (button_width ? 'crm-radio-wrapper-' + button_width + 'px' : '');
11    var hide_zero_value = options.hide_zero_value || false;
12    var mandatory_field = options.mandatory_field || false;
13    var preserve_class = options.preserve_class || 'content';
14
15    $(document).on('crmLoad', function(e) {
16      if ($('.crm-form-radio', selector).size()) {
17        var $new = $('<div>', {'class': preserve_class + ' radiobuttons-form-radios-as-buttons'});
18
19        $('.crm-form-radio', selector).each(function() {
20          var $this = $(this);
21          var $oldparent = $(this).parent();
22          var $label = $('label[for=' + $(this).attr('id') + ']');
23          var id = 'crm-radio-' + $this.attr('name') + '-wrapper';
24          var $div = $('<div>', {id: id, 'class': 'crm-radio-wrapper ' + button_width_class});
25
26          // On the Payment Type field "prop" did not work. Using "is" is said to be
27          // slower, but should work everywhere.
28          if ($this.is(':checked')) {
29            $div.addClass('selected');
30          }
31
32          $this.removeClass('crm-form-radio');
33          $div.append($this);
34          $div.append($label);
35          $new.append($div);
36
37          if (hide_zero_value && $(this).val() == 0) {
38            $div.hide();
39          }
40
41          // Hide empty dom elements
42          if ($oldparent.is(':empty')) {
43            $oldparent.remove();
44          }
45        });
46
47        // Weird leftover from messing with the DOM (oldparent seems to get flattened)
48        // Hide any leftover empty price-set-row (notably if using 'quick' pricesets)
49        $('.price-set-row', selector).each(function() {
50          if ($(this).is(':empty') || $(this).children().length == 0) {
51            console.log('empty - removing');
52            $(this).remove();
53          }
54        });
55
56        // Check for other non-radio divs, such as recurHelp
57        $('*:not(.crm-form-radio)', selector).appendTo($new);
58
59        // This is to make sure we do not have stray nbsps.
60        $(selector).replaceWith($new);
61      }
62
63      // Add a 'selected' class on clicked labels
64      // Uses delegated events because of DOM manipulations (c.f. issue #4)
65      $(document).on('click', selector + ' .crm-radio-wrapper label', function(e) {
66        $this = $(this);
67        $tbody = $this.parent().parent();
68
69        var already_selected = $this.parent().hasClass('selected');
70        $('.crm-radio-wrapper', $tbody).removeClass('selected');
71
72        // Allow deselecting
73        if (already_selected && !mandatory_field) {
74          $this.parent().find('input[type=radio]').prop('checked', false);
75          e.preventDefault();
76        }
77        else {
78          $this.parent().addClass('selected');
79          // This is mostly because selecting text will not always select the radio input
80          // but checking for selection.type == "Range" causes other weird behaviours
81          var $radio = $this.parent().find('input[type=radio]');
82          if ($radio.attr('name') == 'payment_processor_id') {
83            // PP buttons are picky and listen only for change
84            $radio.prop('checked', true).trigger('change');
85          }
86          else {
87            // This seems to work better for pricesets
88            $radio.prop('checked', true).trigger('click');
89          }
90        }
91      });
92
93      // Add a class on the initial selector, for easier CSS theming, but do it only once
94      $(selector).addClass('radiobuttons-form-radios-as-buttons');
95
96      // This is a hack, because it ends up running twice, but since we created new divs,
97      // make sure the right ones are displayed
98      if (typeof CRM.pricesetvisibilityInitialState != 'undefined') {
99        CRM.pricesetvisibilityInitialState();
100      }
101    });
102  };
103
104})(CRM.$, CRM._, CRM.ts('radiobuttons'));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.