aboutsummaryrefslogtreecommitdiff
path: root/js/src/dropdown.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/dropdown.js')
-rw-r--r--js/src/dropdown.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 234d23447..3a910996b 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -1,16 +1,16 @@
-/* global Popper */
-
+import $ from 'jquery'
+import Popper from 'popper.js'
import Util from './util'
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.0.0-alpha.6): dropdown.js
+ * Bootstrap (v4.0.0-beta): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
-const Dropdown = (($) => {
+const Dropdown = (() => {
/**
* Check for Popper dependency
@@ -27,7 +27,7 @@ const Dropdown = (($) => {
*/
const NAME = 'dropdown'
- const VERSION = '4.0.0-alpha.6'
+ const VERSION = '4.0.0-beta'
const DATA_KEY = 'bs.dropdown'
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
@@ -75,14 +75,12 @@ const Dropdown = (($) => {
}
const Default = {
- placement : AttachmentMap.BOTTOM,
offset : 0,
flip : true
}
const DefaultType = {
- placement : 'string',
- offset : '(number|string)',
+ offset : '(number|string|function)',
flip : 'boolean'
}
@@ -203,11 +201,6 @@ const Dropdown = (($) => {
}
_getConfig(config) {
- const elementData = $(this._element).data()
- if (elementData.placement !== undefined) {
- elementData.placement = AttachmentMap[elementData.placement.toUpperCase()]
- }
-
config = $.extend(
{},
this.constructor.Default,
@@ -234,10 +227,10 @@ const Dropdown = (($) => {
_getPlacement() {
const $parentDropdown = $(this._element).parent()
- let placement = this._config.placement
+ let placement = AttachmentMap.BOTTOM
// Handle dropup
- if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) {
+ if ($parentDropdown.hasClass(ClassName.DROPUP)) {
placement = AttachmentMap.TOP
if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
placement = AttachmentMap.TOPEND
@@ -253,12 +246,19 @@ const Dropdown = (($) => {
}
_getPopperConfig() {
+ const offsetConf = {}
+ if (typeof this._config.offset === 'function') {
+ offsetConf.fn = (data) => {
+ data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {})
+ return data
+ }
+ } else {
+ offsetConf.offset = this._config.offset
+ }
const popperConfig = {
placement : this._getPlacement(),
modifiers : {
- offset : {
- offset : this._config.offset
- },
+ offset : offsetConf,
flip : {
enabled : this._config.flip
}
@@ -287,7 +287,7 @@ const Dropdown = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
@@ -445,6 +445,6 @@ const Dropdown = (($) => {
return Dropdown
-})(jQuery)
+})($, Popper)
export default Dropdown