1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-23 05:33:02 +02:00
This commit is contained in:
Mark Otto
2017-06-18 00:14:35 -07:00
parent 035b7349f9
commit 72a0093200
8 changed files with 193 additions and 132 deletions

47
js/dist/dropdown.js vendored
View File

@@ -101,6 +101,7 @@ var Dropdown = function ($) {
this._popper = null;
this._config = this._getConfig(config);
this._menu = this._getMenuElement();
this._inNavbar = this._detectNavbar();
this._addEventListeners();
}
@@ -141,17 +142,7 @@ var Dropdown = function ($) {
element = parent;
}
}
this._popper = new Popper(element, this._menu, {
placement: this._getPlacement(),
modifiers: {
offset: {
offset: this._config.offset
},
flip: {
enabled: this._config.flip
}
}
});
this._popper = new Popper(element, this._menu, this._getPopperConfig());
// if this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children;
@@ -180,6 +171,7 @@ var Dropdown = function ($) {
};
Dropdown.prototype.update = function update() {
this._inNavbar = this._detectNavbar();
if (this._popper !== null) {
this._popper.scheduleUpdate();
}
@@ -231,10 +223,41 @@ var Dropdown = function ($) {
} else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
placement = AttachmentMap.BOTTOMEND;
}
return placement;
};
Dropdown.prototype._detectNavbar = function _detectNavbar() {
return $(this._element).closest('.navbar').length > 0;
};
Dropdown.prototype._getPopperConfig = function _getPopperConfig() {
var _this2 = this;
var popperConfig = {
placement: this._getPlacement(),
modifiers: {
offset: {
offset: this._config.offset
},
flip: {
enabled: this._config.flip
}
}
};
if (this._inNavbar) {
popperConfig.modifiers.AfterApplyStyle = {
enabled: true,
order: 901, // ApplyStyle order + 1
fn: function fn() {
// reset Popper styles
$(_this2._menu).attr('style', '');
}
};
}
return popperConfig;
};
// static
Dropdown._jQueryInterface = function _jQueryInterface(config) {

File diff suppressed because one or more lines are too long