PageSourceSearch

https://www.veolia.com/themes/custom/veo_site/build/assets/scripts/utils/select2-dropdownPosition.js?v=10.6.15

js veolia.com collected 2026-09-24 08:41:05 UTC 3,350 bytes, 120 lines download raw bytes

1/*!
2 * select2 - 'dropdownPosition' option
3 *
4 * Rerolled the solution from
5 * https://github.com/andreivictor/select2-dropdownPosition
6 * for new select2 version.
7 */
8;(function($) {
9
10  var Defaults = $.fn.select2.amd.require('select2/defaults');
11
12  $.extend(Defaults.defaults, {
13    dropdownPosition: 'auto'
14  });
15
16  var AttachBody = $.fn.select2.amd.require('select2/dropdown/attachBody');
17
18  var _positionDropdown = AttachBody.prototype._positionDropdown;
19
20  AttachBody.prototype._positionDropdown = function () {
21    var $window = $(window);
22
23    var isCurrentlyAbove = this.$dropdown[0].classList
24      .contains('select2-dropdown--above');
25    var isCurrentlyBelow = this.$dropdown[0].classList
26      .contains('select2-dropdown--below');
27
28    var newDirection = null;
29
30    var offset = this.$container.offset();
31
32    offset.bottom = offset.top + this.$container.outerHeight(false);
33
34    var container = {
35      height: this.$container.outerHeight(false)
36    };
37
38    container.top = offset.top;
39    container.bottom = offset.top + container.height;
40
41    var dropdown = {
42      height: this.$dropdown.outerHeight(false)
43    };
44
45    var viewport = {
46      top: $window.scrollTop(),
47      bottom: $window.scrollTop() + $window.height()
48    };
49
50    var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
51    var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
52
53    var css = {
54      left: offset.left,
55      top: container.bottom
56    };
57
58    // Determine what the parent element is to use for calculating the offset
59    var $offsetParent = this.$dropdownParent;
60
61    // For statically positioned elements, we need to get the element
62    // that is determining the offset
63    if ($offsetParent.css('position') === 'static') {
64      $offsetParent = $offsetParent.offsetParent();
65    }
66
67    var parentOffset = {
68      top: 0,
69      left: 0
70    };
71
72    if (
73      $.contains(document.body, $offsetParent[0]) ||
74      $offsetParent[0].isConnected
75    ) {
76      parentOffset = $offsetParent.offset();
77    }
78
79    css.top -= parentOffset.top;
80    css.left -= parentOffset.left;
81
82    var dropdownPositionOption = this.options.get('dropdownPosition');
83
84    if (dropdownPositionOption === 'above' || dropdownPositionOption === 'below') {
85
86      newDirection = dropdownPositionOption;
87
88    } else {
89
90      if (!isCurrentlyAbove && !isCurrentlyBelow) {
91        newDirection = 'below';
92      }
93
94      if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
95        newDirection = 'above';
96      } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
97        newDirection = 'below';
98      }
99
100    }
101
102    if (newDirection == 'above' ||
103      (isCurrentlyAbove && newDirection !== 'below')) {
104      css.top = container.top - parentOffset.top - dropdown.height;
105    }
106
107    if (newDirection != null) {
108      this.$dropdown[0].classList.remove('select2-dropdown--below');
109      this.$dropdown[0].classList.remove('select2-dropdown--above');
110      this.$dropdown[0].classList.add('select2-dropdown--' + newDirection);
111
112      this.$container[0].classList.remove('select2-container--below');
113      this.$container[0].classList.remove('select2-container--above');
114      this.$container[0].classList.add('select2-container--' + newDirection);
115    }
116
117    this.$dropdownContainer.css(css);
118  };
119
120})(window.jQuery);

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.