PageSourceSearch

https://www.creatio.com/modules/contrib/webform/js/webform.element.select2.js?tltpnb

js creatio.com collected 2026-09-24 08:41:22 UTC 3,369 bytes, 104 lines download raw bytes

1/**
2 * @file
3 * JavaScript behaviors for Select2 integration.
4 */
5
6// Support for jQuery 4 #6298
7// @see https://github.com/select2/select2/issues/6298
8if (!jQuery.isArray) {
9  jQuery.isArray = Array.isArray || function (value) {
10    return Object.prototype.toString.call(value) === '[object Array]';
11  };
12}
13if (!jQuery.trim) {
14  jQuery.trim = function (text) {
15    return text == null ? "" : text.trim();
16  };
17}
18
19(function ($, Drupal, once) {
20  // @see https://select2.github.io/options.html
21  Drupal.webform = Drupal.webform || {};
22  Drupal.webform.select2 = Drupal.webform.select2 || {};
23  Drupal.webform.select2.options = Drupal.webform.select2.options || {};
24  Drupal.webform.select2.options.width = Drupal.webform.select2.options.width || '100%';
25  Drupal.webform.select2.options.widthInline = Drupal.webform.select2.options.widthInline || '50%';
26
27  /**
28   * Initialize Select2 support.
29   *
30   * @type {Drupal~behavior}
31   */
32  Drupal.behaviors.webformSelect2 = {
33    attach(context) {
34      if (!$.fn.select2) {
35        return;
36      }
37
38      $(once('webform-select2', 'select.js-webform-select2, .js-webform-select2 select', context))
39        .each(function () {
40          var $select = $(this);
41
42          var options = {};
43          if ($select.parents('.webform-element--title-inline').length) {
44            options.width = Drupal.webform.select2.options.widthInline;
45          }
46          options = $.extend(options, Drupal.webform.select2.options);
47          if ($select.data('placeholder')) {
48            options.placeholder = $select.data('placeholder');
49            if (!$select.prop('multiple')) {
50              // Allow single option to be deselected.
51              options.allowClear = true;
52            }
53          }
54          if ($select.data('limit')) {
55            options.maximumSelectionLength = $select.data('limit');
56          }
57          // Allow custom options.
58          if ($select.attr('data-options')) {
59            options = $.extend(true, options, JSON.parse($select.attr('data-options')));
60          }
61
62          $select.select2(options);
63        });
64
65    }
66  };
67
68  /**
69   * ISSUE:
70   * Hiding/showing element via #states API cause select2 dropdown to appear in the wrong position.
71   *
72   * WORKAROUND:
73   * Close (aka hide) select2 dropdown when #states API hides or shows an element.
74   *
75   * Steps to reproduce:
76   * - Add custom 'Submit button(s)'
77   * - Hide submit button
78   * - Save
79   * - Open 'Submit button(s)' dialog
80   *
81   * Dropdown body is positioned incorrectly when dropdownParent isn't statically positioned.
82   * @see https://github.com/select2/select2/issues/3303
83   */
84  $(function () {
85    if ($.fn.select2) {
86      $(document).on('state:visible state:visible-slide', function (e) {
87        $('select.select2-hidden-accessible').select2('close');
88      });
89    }
90
91    // Select2 search broken inside jQuery UI 1.10.x modal Dialog.
92    // @see https://github.com/select2/select2/issues/1246
93    if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) {
94      var ui_dialog_interaction = $.ui.dialog.prototype._allowInteraction;
95      $.ui.dialog.prototype._allowInteraction = function (e) {
96        if ($(e.target).closest('.select2-dropdown').length) {
97          return true;
98        }
99        return ui_dialog_interaction.apply(this, arguments);
100      };
101    }
102  });
103
104})(jQuery, Drupal,  once);

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.