1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-30 07:19:13 +02:00
This commit is contained in:
Mark Otto
2018-02-11 14:53:29 -08:00
parent f81f419b22
commit e373fbea92
24 changed files with 175 additions and 80 deletions

20
js/dist/dropdown.js vendored
View File

@@ -75,12 +75,14 @@ var Dropdown = function ($) {
var Default = {
offset: 0,
flip: true,
boundary: 'scrollParent'
boundary: 'scrollParent',
reference: 'toggle'
};
var DefaultType = {
offset: '(number|string|function)',
flip: 'boolean',
boundary: '(string|element)'
boundary: '(string|element)',
reference: '(string|element)'
/**
* ------------------------------------------------------------------------
* Class Definition
@@ -141,11 +143,15 @@ var Dropdown = function ($) {
throw new TypeError('Bootstrap dropdown require Popper.js (https://popper.js.org)');
}
var element = this._element; // For dropup with alignment we use the parent as popper container
var referenceElement = this._element;
if ($(parent).hasClass(ClassName.DROPUP)) {
if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) {
element = parent;
if (this._config.reference === 'parent') {
referenceElement = parent;
} else if (Util.isElement(this._config.reference)) {
referenceElement = this._config.reference; // Check if it's jQuery element
if (typeof this._config.reference.jquery !== 'undefined') {
referenceElement = this._config.reference[0];
}
} // If boundary is not `scrollParent`, then set position to `static`
// to allow the menu to "escape" the scroll parent's boundaries
@@ -156,7 +162,7 @@ var Dropdown = function ($) {
$(parent).addClass(ClassName.POSITION_STATIC);
}
this._popper = new Popper(element, this._menu, this._getPopperConfig());
this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig());
} // If this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children;
// only needed because of broken event delegation on iOS