PageSourceSearch

https://comar.tn/modules/webform/js/webform.element.other.js?v=8.9.20

js comar.tn collected 2026-10-02 03:02:41 UTC 5,123 bytes, 163 lines download raw bytes

1/**
2 * @file
3 * JavaScript behaviors for other elements.
4 */
5
6(function ($, Drupal) {
7
8  'use strict';
9
10  /**
11   * Toggle other input (text) field.
12   *
13   * @param {boolean} show
14   *   TRUE will display the text field. FALSE with hide and clear the text field.
15   * @param {object} $element
16   *   The input (text) field to be toggled.
17   * @param {string} effect
18   *   Effect.
19   */
20  function toggleOther(show, $element, effect) {
21    var $input = $element.find('input');
22    var hideEffect = (effect === false) ? 'hide' : 'slideUp';
23    var showEffect = (effect === false) ? 'show' : 'slideDown';
24
25    if (show) {
26      // Limit the other inputs width to the parent's container.
27      // If the parent container is not visible it's width will be 0
28      // and ignored.
29      var width = $element.parent().width();
30      if (width) {
31        $element.width(width);
32      }
33
34      // Display the element.
35      $element[showEffect]();
36      // If not initializing, then focus the other element.
37      if (effect !== false) {
38        $input.trigger('focus');
39      }
40      // Require the input.
41      $input.prop('required', true).attr('aria-required', 'true');
42      // Restore the input's value.
43      var value = $input.data('webform-value');
44      if (typeof value !== 'undefined') {
45        $input.val(value);
46        var input = $input.get(0);
47        // Move cursor to the beginning of the other text input.
48        // @see https://stackoverflow.com/questions/21177489/selectionstart-selectionend-on-input-type-number-no-longer-allowed-in-chrome
49        if ($.inArray(input.type, ['text', 'search', 'url', 'tel', 'password']) !== -1) {
50          input.setSelectionRange(0, 0);
51        }
52      }
53      // Refresh CodeMirror used as other element.
54      $element.parent().find('.CodeMirror').each(function (index, $element) {
55        $element.CodeMirror.refresh();
56      });
57    }
58    else {
59      // Hide the element.
60      $element[hideEffect]();
61      // Save the input's value.
62      $input.data('webform-value', $input.val());
63      // Empty and un-required the input.
64      $input.val('').prop('required', false).removeAttr('aria-required');
65    }
66  }
67
68  /**
69   * Attach handlers to select other elements.
70   *
71   * @type {Drupal~behavior}
72   */
73  Drupal.behaviors.webformSelectOther = {
74    attach: function (context) {
75      $(context).find('.js-webform-select-other').once('webform-select-other').each(function () {
76        var $element = $(this);
77
78        var $select = $element.find('select');
79        var $input = $element.find('.js-webform-select-other-input');
80
81        $select.on('change', function () {
82          var isOtherSelected = $select
83            .find('option[value="_other_"]')
84            .is(':selected');
85          toggleOther(isOtherSelected, $input);
86        });
87
88        var isOtherSelected = $select
89          .find('option[value="_other_"]')
90          .is(':selected');
91        toggleOther(isOtherSelected, $input, false);
92      });
93    }
94  };
95
96  /**
97   * Attach handlers to checkboxes other elements.
98   *
99   * @type {Drupal~behavior}
100   */
101  Drupal.behaviors.webformCheckboxesOther = {
102    attach: function (context) {
103      $(context).find('.js-webform-checkboxes-other').once('webform-checkboxes-other').each(function () {
104        var $element = $(this);
105        var $checkbox = $element.find('input[value="_other_"]');
106        var $input = $element.find('.js-webform-checkboxes-other-input');
107
108        $checkbox.on('change', function () {
109          toggleOther(this.checked, $input);
110        });
111
112        toggleOther($checkbox.is(':checked'), $input, false);
113      });
114    }
115  };
116
117  /**
118   * Attach handlers to radios other elements.
119   *
120   * @type {Drupal~behavior}
121   */
122  Drupal.behaviors.webformRadiosOther = {
123    attach: function (context) {
124      $(context).find('.js-webform-radios-other').once('webform-radios-other').each(function () {
125        var $element = $(this);
126
127        var $radios = $element.find('input[type="radio"]');
128        var $input = $element.find('.js-webform-radios-other-input');
129
130        $radios.on('change', function () {
131          toggleOther(($radios.filter(':checked').val() === '_other_'), $input);
132        });
133
134        toggleOther(($radios.filter(':checked').val() === '_other_'), $input, false);
135      });
136    }
137  };
138
139  /**
140   * Attach handlers to buttons other elements.
141   *
142   * @type {Drupal~behavior}
143   */
144  Drupal.behaviors.webformButtonsOther = {
145    attach: function (context) {
146      $(context).find('.js-webform-buttons-other').once('webform-buttons-other').each(function () {
147        var $element = $(this);
148
149        var $buttons = $element.find('input[type="radio"]');
150        var $input = $element.find('.js-webform-buttons-other-input');
151        var $container = $(this).find('.js-webform-webform-buttons');
152
153        // Create set onchange handler.
154        $container.on('change', function () {
155          toggleOther(($(this).find(':radio:checked').val() === '_other_'), $input);
156        });
157
158        toggleOther(($buttons.filter(':checked').val() === '_other_'), $input, false);
159      });
160    }
161  };
162
163})(jQuery, Drupal);

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.