1(function($) { 2 3 var Defaults = $.fn.select2.amd.require('select2/defaults'); 4 5 $.extend(Defaults.defaults, { 6 dropdownPosition: 'auto' 7 }); 8 9 var AttachBody = $.fn.select2.amd.require('select2/dropdown/attachBody'); 10 11 var _positionDropdown = AttachBody.prototype._positionDropdown; 12 13 AttachBody.prototype._positionDropdown = function() { 14 15 var $window = $(window); 16 17 var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above'); 18 var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below'); 19 20 var newDirection = null; 21 22 var offset = this.$container.offset(); 23 24 offset.bottom = offset.top + this.$container.outerHeight(false); 25 26 var container = { 27 height: this.$container.outerHeight(false) 28 }; 29 30 container.top = offset.top; 31 container.bottom = offset.top + container.height; 32 33 var dropdown = { 34 height: this.$dropdown.outerHeight(false) 35 }; 36 37 var viewport = { 38 top: $window.scrollTop(), 39 bottom: $window.scrollTop() + $window.height() 40 }; 41 42 var enoughRoomAbove = viewport.top < (offset.top - dropdown.height); 43 var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height); 44 45 var css = { 46 left: offset.left, 47 top: container.bottom 48 }; 49 50 // Determine what the parent element is to use for calciulating the offset 51 var $offsetParent = this.$dropdownParent; 52 53 // For statically positoned elements, we need to get the element 54 // that is determining the offset 55 if ($offsetParent.css('position') === 'static') { 56 $offsetParent = $offsetParent.offsetParent(); 57 } 58 59 var parentOffset = $offsetParent.offset(); 60 61 css.top -= parentOffset.top 62 css.left -= parentOffset.left; 63 64 var dropdownPositionOption = this.options.get('dropdownPosition'); 65 66 if (dropdownPositionOption === 'above' || dropdownPositionOption === 'below') { 67 newDirection = dropdownPositionOption; 68 } else { 69 70 if (!isCurrentlyAbove && !isCurrentlyBelow) { 71 newDirection = 'below'; 72 } 73 74 if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) { 75 newDirection = 'above'; 76 } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) { 77 newDirection = 'below'; 78 } 79 80 } 81 82 if (newDirection == 'above' || 83 (isCurrentlyAbove && newDirection !== 'below')) { 84 css.top = container.top - parentOffset.top - dropdown.height; 85 } 86 87 if (newDirection != null) { 88 this.$dropdown 89 .removeClass('select2-dropdown--below select2-dropdown--above') 90 .addClass('select2-dropdown--' + newDirection); 91 this.$container 92 .removeClass('select2-container--below select2-container--above') 93 .addClass('select2-container--' + newDirection); 94 } 95 96 this.$dropdownContainer.css(css); 97 98 }; 99 100})(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.