diff options
| author | Mark Otto <[email protected]> | 2017-06-18 02:19:34 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2017-06-18 02:19:34 -0700 |
| commit | 74f1d002b4a943364e14749af5e0a8538497c59a (patch) | |
| tree | 3f720e07d30c39199e0a15f623e6e6fe32bf0e49 /js/src | |
| parent | 09e3509ff3b4ffcec0832d501cd0c766e86ec7f7 (diff) | |
| parent | 845320fe8cb9af7b6073a20fa3f293ebc46eff32 (diff) | |
| download | bootstrap-74f1d002b4a943364e14749af5e0a8538497c59a.tar.xz bootstrap-74f1d002b4a943364e14749af5e0a8538497c59a.zip | |
Merge branch 'v4-dev' into colors-redux
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/dropdown.js | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js index acc3ed453..057cfa433 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -96,10 +96,11 @@ const Dropdown = (($) => { class Dropdown { constructor(element, config) { - this._element = element - this._popper = null - this._config = this._getConfig(config) - this._menu = this._getMenuElement() + this._element = element + this._popper = null + this._config = this._getConfig(config) + this._menu = this._getMenuElement() + this._inNavbar = this._detectNavbar() this._addEventListeners() } @@ -153,17 +154,7 @@ const Dropdown = (($) => { 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; @@ -195,6 +186,7 @@ const Dropdown = (($) => { } update() { + this._inNavbar = this._detectNavbar() if (this._popper !== null) { this._popper.scheduleUpdate() } @@ -250,13 +242,40 @@ const Dropdown = (($) => { if ($(this._menu).hasClass(ClassName.MENURIGHT)) { placement = AttachmentMap.TOPEND } + } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) { + placement = AttachmentMap.BOTTOMEND } - else { - if ($(this._menu).hasClass(ClassName.MENURIGHT)) { - placement = AttachmentMap.BOTTOMEND + return placement + } + + _detectNavbar() { + return $(this._element).closest('.navbar').length > 0 + } + + _getPopperConfig() { + const popperConfig = { + placement : this._getPlacement(), + modifiers : { + offset : { + offset : this._config.offset + }, + flip : { + enabled : this._config.flip + } } } - return placement + + if (this._inNavbar) { + popperConfig.modifiers.AfterApplyStyle = { + enabled: true, + order: 901, // ApplyStyle order + 1 + fn: () => { + // reset Popper styles + $(this._menu).attr('style', '') + } + } + } + return popperConfig } // static |
