Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap-rubygem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/bootstrap/dropdown.js')
-rw-r--r--assets/javascripts/bootstrap/dropdown.js101
1 files changed, 64 insertions, 37 deletions
diff --git a/assets/javascripts/bootstrap/dropdown.js b/assets/javascripts/bootstrap/dropdown.js
index e83f0fd..5250119 100644
--- a/assets/javascripts/bootstrap/dropdown.js
+++ b/assets/javascripts/bootstrap/dropdown.js
@@ -1,30 +1,23 @@
+function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.0.0-beta.2): dropdown.js
+ * Bootstrap (v4.0.0-beta.3): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
-var Dropdown = function () {
- /**
- * Check for Popper dependency
- * Popper - https://popper.js.org
- */
- if (typeof Popper === 'undefined') {
- throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)');
- }
+var Dropdown = function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
-
-
var NAME = 'dropdown';
- var VERSION = '4.0.0-beta.2';
+ var VERSION = '4.0.0-beta.3';
var DATA_KEY = 'bs.dropdown';
var EVENT_KEY = "." + DATA_KEY;
var DATA_API_KEY = '.data-api';
@@ -56,8 +49,11 @@ var Dropdown = function () {
DISABLED: 'disabled',
SHOW: 'show',
DROPUP: 'dropup',
+ DROPRIGHT: 'dropright',
+ DROPLEFT: 'dropleft',
MENURIGHT: 'dropdown-menu-right',
- MENULEFT: 'dropdown-menu-left'
+ MENULEFT: 'dropdown-menu-left',
+ POSITION_STATIC: 'position-static'
};
var Selector = {
DATA_TOGGLE: '[data-toggle="dropdown"]',
@@ -70,15 +66,21 @@ var Dropdown = function () {
TOP: 'top-start',
TOPEND: 'top-end',
BOTTOM: 'bottom-start',
- BOTTOMEND: 'bottom-end'
+ BOTTOMEND: 'bottom-end',
+ RIGHT: 'right-start',
+ RIGHTEND: 'right-end',
+ LEFT: 'left-start',
+ LEFTEND: 'left-end'
};
var Default = {
offset: 0,
- flip: true
+ flip: true,
+ boundary: 'scrollParent'
};
var DefaultType = {
offset: '(number|string|function)',
- flip: 'boolean'
+ flip: 'boolean',
+ boundary: '(string|element)'
/**
* ------------------------------------------------------------------------
* Class Definition
@@ -127,21 +129,40 @@ var Dropdown = function () {
if (showEvent.isDefaultPrevented()) {
return;
- }
+ } // Disable totally Popper.js for Dropdown in Navbar
- var element = this._element; // for dropup with alignment we use the parent as popper container
- if ($(parent).hasClass(ClassName.DROPUP)) {
- if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) {
- element = parent;
+ if (!this._inNavbar) {
+ /**
+ * Check for Popper dependency
+ * Popper - https://popper.js.org
+ */
+ if (typeof Popper === 'undefined') {
+ throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)');
}
- }
- this._popper = new Popper(element, this._menu, this._getPopperConfig()); // if this is a touch-enabled device we add extra
+ var element = this._element; // for dropup with alignment we use the parent as popper container
+
+ if ($(parent).hasClass(ClassName.DROPUP)) {
+ if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) {
+ element = parent;
+ }
+ } // If boundary is not `scrollParent`, then set position to `static`
+ // to allow the menu to "escape" the scroll parent's boundaries
+ // https://github.com/twbs/bootstrap/issues/24251
+
+
+ if (this._config.boundary !== 'scrollParent') {
+ $(parent).addClass(ClassName.POSITION_STATIC);
+ }
+
+ 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;
// only needed because of broken event delegation on iOS
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
+
if ('ontouchstart' in document.documentElement && !$(parent).closest(Selector.NAVBAR_NAV).length) {
$('body').children().on('mouseover', null, $.noop);
}
@@ -162,9 +183,9 @@ var Dropdown = function () {
if (this._popper !== null) {
this._popper.destroy();
- }
- this._popper = null;
+ this._popper = null;
+ }
};
_proto.update = function update() {
@@ -188,7 +209,7 @@ var Dropdown = function () {
};
_proto._getConfig = function _getConfig(config) {
- config = $.extend({}, this.constructor.Default, $(this._element).data(), config);
+ config = _extends({}, this.constructor.Default, $(this._element).data(), config);
Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
return config;
};
@@ -213,6 +234,10 @@ var Dropdown = function () {
if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
placement = AttachmentMap.TOPEND;
}
+ } else if ($parentDropdown.hasClass(ClassName.DROPRIGHT)) {
+ placement = AttachmentMap.RIGHT;
+ } else if ($parentDropdown.hasClass(ClassName.DROPLEFT)) {
+ placement = AttachmentMap.LEFT;
} else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
placement = AttachmentMap.BOTTOMEND;
}
@@ -231,7 +256,7 @@ var Dropdown = function () {
if (typeof this._config.offset === 'function') {
offsetConf.fn = function (data) {
- data.offsets = $.extend({}, data.offsets, _this2._config.offset(data.offsets) || {});
+ data.offsets = _extends({}, data.offsets, _this2._config.offset(data.offsets) || {});
return data;
};
} else {
@@ -244,17 +269,12 @@ var Dropdown = function () {
offset: offsetConf,
flip: {
enabled: this._config.flip
+ },
+ preventOverflow: {
+ boundariesElement: this._config.boundary
}
- } // Disable Popper.js for Dropdown in Navbar
-
+ }
};
-
- if (this._inNavbar) {
- popperConfig.modifiers.applyStyle = {
- enabled: !this._inNavbar
- };
- }
-
return popperConfig;
}; // static
@@ -340,7 +360,14 @@ var Dropdown = function () {
};
Dropdown._dataApiKeydownHandler = function _dataApiKeydownHandler(event) {
- if (!REGEXP_KEYDOWN.test(event.which) || /button/i.test(event.target.tagName) && event.which === SPACE_KEYCODE || /input|textarea/i.test(event.target.tagName)) {
+ // If not input/textarea:
+ // - And not a key in REGEXP_KEYDOWN => not a dropdown command
+ // If input/textarea:
+ // - If space key => not a dropdown command
+ // - If key is other than escape
+ // - If key is not up or down => not a dropdown command
+ // - If trigger inside the menu => not a dropdown command
+ if (/input|textarea/i.test(event.target.tagName) ? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && (event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE || $(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) {
return;
}