Do not create a Popper.js instance when we don't need it

This commit is contained in:
Johann-S 2017-10-27 09:51:08 +02:00
parent 6b884dcd76
commit 6d00ed586b

View File

@ -143,6 +143,8 @@ const Dropdown = (($) => {
return return
} }
// Disable totally Popper.js for Dropdown in Navbar
if (!this._inNavbar) {
/** /**
* Check for Popper dependency * Check for Popper dependency
* Popper - https://popper.js.org * Popper - https://popper.js.org
@ -150,7 +152,6 @@ const Dropdown = (($) => {
if (typeof Popper === 'undefined') { if (typeof Popper === 'undefined') {
throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)') throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)')
} }
let element = this._element let element = this._element
// for dropup with alignment we use the parent as popper container // for dropup with alignment we use the parent as popper container
if ($(parent).hasClass(ClassName.DROPUP)) { if ($(parent).hasClass(ClassName.DROPUP)) {
@ -159,6 +160,8 @@ const Dropdown = (($) => {
} }
} }
this._popper = new Popper(element, this._menu, this._getPopperConfig()) this._popper = new Popper(element, this._menu, this._getPopperConfig())
}
// if this is a touch-enabled device we add extra // if this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children; // empty mouseover listeners to the body's immediate children;
@ -185,9 +188,9 @@ const Dropdown = (($) => {
this._menu = null this._menu = null
if (this._popper !== null) { if (this._popper !== null) {
this._popper.destroy() this._popper.destroy()
}
this._popper = null this._popper = null
} }
}
update() { update() {
this._inNavbar = this._detectNavbar() this._inNavbar = this._detectNavbar()
@ -275,12 +278,6 @@ const Dropdown = (($) => {
} }
} }
// Disable Popper.js for Dropdown in Navbar
if (this._inNavbar) {
popperConfig.modifiers.applyStyle = {
enabled: !this._inNavbar
}
}
return popperConfig return popperConfig
} }