diff options
Diffstat (limited to 'assets/javascripts/bootstrap/dropdown.js')
-rw-r--r-- | assets/javascripts/bootstrap/dropdown.js | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/assets/javascripts/bootstrap/dropdown.js b/assets/javascripts/bootstrap/dropdown.js index 7cb1696..99b38a1 100644 --- a/assets/javascripts/bootstrap/dropdown.js +++ b/assets/javascripts/bootstrap/dropdown.js @@ -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(); } @@ -228,14 +220,38 @@ var Dropdown = function ($) { 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; }; + Dropdown.prototype._detectNavbar = function _detectNavbar() { + return $(this._element).closest('.navbar').length > 0; + }; + + Dropdown.prototype._getPopperConfig = function _getPopperConfig() { + var popperConfig = { + placement: this._getPlacement(), + modifiers: { + offset: { + offset: this._config.offset + }, + flip: { + enabled: this._config.flip + } + } + }; + + // Disable Popper.js for Dropdown in Navbar + if (this._inNavbar) { + popperConfig.modifiers.applyStyle = { + enabled: !this._inNavbar + }; + } + return popperConfig; + }; + // static Dropdown._jQueryInterface = function _jQueryInterface(config) { |