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:
authorGleb Mazovetskiy <glex.spb@gmail.com>2017-09-11 17:23:33 +0300
committerGleb Mazovetskiy <glex.spb@gmail.com>2017-09-11 17:23:33 +0300
commiteb2e1a606e2c3324e7c511ba07c5ba0195801b00 (patch)
tree37c6441979f159dc13e6021fdc5322a42f374099 /assets/javascripts/bootstrap/dropdown.js
parentb12fdcd48c26cee905c3365626247f452fb941f2 (diff)
rake update[v4-dev]
Diffstat (limited to 'assets/javascripts/bootstrap/dropdown.js')
-rw-r--r--assets/javascripts/bootstrap/dropdown.js457
1 files changed, 235 insertions, 222 deletions
diff --git a/assets/javascripts/bootstrap/dropdown.js b/assets/javascripts/bootstrap/dropdown.js
index 1015eca..0c739de 100644
--- a/assets/javascripts/bootstrap/dropdown.js
+++ b/assets/javascripts/bootstrap/dropdown.js
@@ -1,3 +1,5 @@
+'use strict';
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -11,7 +13,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
* --------------------------------------------------------------------------
*/
-var Dropdown = function ($) {
+var Dropdown = function () {
/**
* Check for Popper dependency
@@ -76,23 +78,21 @@ var Dropdown = function ($) {
};
var Default = {
- placement: AttachmentMap.BOTTOM,
offset: 0,
flip: true
};
var DefaultType = {
- placement: 'string',
offset: '(number|string)',
flip: 'boolean'
+ };
- /**
- * ------------------------------------------------------------------------
- * Class Definition
- * ------------------------------------------------------------------------
- */
+ /**
+ * ------------------------------------------------------------------------
+ * Class Definition
+ * ------------------------------------------------------------------------
+ */
- };
var Dropdown = function () {
function Dropdown(element, config) {
_classCallCheck(this, Dropdown);
@@ -108,278 +108,291 @@ var Dropdown = function ($) {
// getters
- // public
+ _createClass(Dropdown, [{
+ key: 'toggle',
- Dropdown.prototype.toggle = function toggle() {
- if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) {
- return;
- }
- var parent = Dropdown._getParentFromElement(this._element);
- var isActive = $(this._menu).hasClass(ClassName.SHOW);
+ // public
- Dropdown._clearMenus();
+ value: function toggle() {
+ if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) {
+ return;
+ }
- if (isActive) {
- return;
- }
+ var parent = Dropdown._getParentFromElement(this._element);
+ var isActive = $(this._menu).hasClass(ClassName.SHOW);
- var relatedTarget = {
- relatedTarget: this._element
- };
- var showEvent = $.Event(Event.SHOW, relatedTarget);
+ Dropdown._clearMenus();
- $(parent).trigger(showEvent);
+ if (isActive) {
+ return;
+ }
- if (showEvent.isDefaultPrevented()) {
- return;
- }
+ var relatedTarget = {
+ relatedTarget: this._element
+ };
+ var showEvent = $.Event(Event.SHOW, relatedTarget);
+
+ $(parent).trigger(showEvent);
- 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 (showEvent.isDefaultPrevented()) {
+ return;
}
- }
- 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);
- }
- this._element.focus();
- this._element.setAttribute('aria-expanded', true);
+ 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;
+ }
+ }
+ 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);
+ }
- $(this._menu).toggleClass(ClassName.SHOW);
- $(parent).toggleClass(ClassName.SHOW).trigger($.Event(Event.SHOWN, relatedTarget));
- };
+ this._element.focus();
+ this._element.setAttribute('aria-expanded', true);
- Dropdown.prototype.dispose = function dispose() {
- $.removeData(this._element, DATA_KEY);
- $(this._element).off(EVENT_KEY);
- this._element = null;
- this._menu = null;
- if (this._popper !== null) {
- this._popper.destroy();
+ $(this._menu).toggleClass(ClassName.SHOW);
+ $(parent).toggleClass(ClassName.SHOW).trigger($.Event(Event.SHOWN, relatedTarget));
}
- this._popper = null;
- };
-
- Dropdown.prototype.update = function update() {
- this._inNavbar = this._detectNavbar();
- if (this._popper !== null) {
- this._popper.scheduleUpdate();
+ }, {
+ key: 'dispose',
+ value: function dispose() {
+ $.removeData(this._element, DATA_KEY);
+ $(this._element).off(EVENT_KEY);
+ this._element = null;
+ this._menu = null;
+ if (this._popper !== null) {
+ this._popper.destroy();
+ }
+ this._popper = null;
}
- };
-
- // private
-
- Dropdown.prototype._addEventListeners = function _addEventListeners() {
- var _this = this;
-
- $(this._element).on(Event.CLICK, function (event) {
- event.preventDefault();
- event.stopPropagation();
- _this.toggle();
- });
- };
-
- Dropdown.prototype._getConfig = function _getConfig(config) {
- var elementData = $(this._element).data();
- if (elementData.placement !== undefined) {
- elementData.placement = AttachmentMap[elementData.placement.toUpperCase()];
+ }, {
+ key: 'update',
+ value: function update() {
+ this._inNavbar = this._detectNavbar();
+ if (this._popper !== null) {
+ this._popper.scheduleUpdate();
+ }
}
- config = $.extend({}, this.constructor.Default, $(this._element).data(), config);
+ // private
- Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
+ }, {
+ key: '_addEventListeners',
+ value: function _addEventListeners() {
+ var _this = this;
+
+ $(this._element).on(Event.CLICK, function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+ _this.toggle();
+ });
+ }
+ }, {
+ key: '_getConfig',
+ value: function _getConfig(config) {
+ config = $.extend({}, this.constructor.Default, $(this._element).data(), config);
- return config;
- };
+ Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
- Dropdown.prototype._getMenuElement = function _getMenuElement() {
- if (!this._menu) {
- var parent = Dropdown._getParentFromElement(this._element);
- this._menu = $(parent).find(Selector.MENU)[0];
+ return config;
}
- return this._menu;
- };
-
- Dropdown.prototype._getPlacement = function _getPlacement() {
- var $parentDropdown = $(this._element).parent();
- var placement = this._config.placement;
-
- // Handle dropup
- if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) {
- placement = AttachmentMap.TOP;
- if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
- placement = AttachmentMap.TOPEND;
+ }, {
+ key: '_getMenuElement',
+ value: function _getMenuElement() {
+ if (!this._menu) {
+ var parent = Dropdown._getParentFromElement(this._element);
+ this._menu = $(parent).find(Selector.MENU)[0];
}
- } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
- placement = AttachmentMap.BOTTOMEND;
+ return this._menu;
}
- 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
+ }, {
+ key: '_getPlacement',
+ value: function _getPlacement() {
+ var $parentDropdown = $(this._element).parent();
+ var placement = AttachmentMap.BOTTOM;
+
+ // Handle dropup
+ if ($parentDropdown.hasClass(ClassName.DROPUP)) {
+ placement = AttachmentMap.TOP;
+ if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
+ placement = AttachmentMap.TOPEND;
}
+ } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
+ placement = AttachmentMap.BOTTOMEND;
}
+ return placement;
+ }
+ }, {
+ key: '_detectNavbar',
+ value: function _detectNavbar() {
+ return $(this._element).closest('.navbar').length > 0;
+ }
+ }, {
+ key: '_getPopperConfig',
+ value: 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
- };
+ if (this._inNavbar) {
+ popperConfig.modifiers.applyStyle = {
+ enabled: !this._inNavbar
+ };
+ }
+ return popperConfig;
}
- return popperConfig;
- };
- // static
+ // static
- Dropdown._jQueryInterface = function _jQueryInterface(config) {
- return this.each(function () {
- var data = $(this).data(DATA_KEY);
- var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null;
+ }], [{
+ key: '_jQueryInterface',
+ value: function _jQueryInterface(config) {
+ return this.each(function () {
+ var data = $(this).data(DATA_KEY);
+ var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null;
- if (!data) {
- data = new Dropdown(this, _config);
- $(this).data(DATA_KEY, data);
- }
-
- if (typeof config === 'string') {
- if (data[config] === undefined) {
- throw new Error('No method named "' + config + '"');
+ if (!data) {
+ data = new Dropdown(this, _config);
+ $(this).data(DATA_KEY, data);
}
- data[config]();
- }
- });
- };
- Dropdown._clearMenus = function _clearMenus(event) {
- if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
- return;
+ if (typeof config === 'string') {
+ if (typeof data[config] === 'undefined') {
+ throw new Error('No method named "' + config + '"');
+ }
+ data[config]();
+ }
+ });
}
-
- var toggles = $.makeArray($(Selector.DATA_TOGGLE));
- for (var i = 0; i < toggles.length; i++) {
- var parent = Dropdown._getParentFromElement(toggles[i]);
- var context = $(toggles[i]).data(DATA_KEY);
- var relatedTarget = {
- relatedTarget: toggles[i]
- };
-
- if (!context) {
- continue;
+ }, {
+ key: '_clearMenus',
+ value: function _clearMenus(event) {
+ if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
+ return;
}
- var dropdownMenu = context._menu;
- if (!$(parent).hasClass(ClassName.SHOW)) {
- continue;
- }
+ var toggles = $.makeArray($(Selector.DATA_TOGGLE));
+ for (var i = 0; i < toggles.length; i++) {
+ var parent = Dropdown._getParentFromElement(toggles[i]);
+ var context = $(toggles[i]).data(DATA_KEY);
+ var relatedTarget = {
+ relatedTarget: toggles[i]
+ };
- if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $.contains(parent, event.target)) {
- continue;
- }
+ if (!context) {
+ continue;
+ }
- var hideEvent = $.Event(Event.HIDE, relatedTarget);
- $(parent).trigger(hideEvent);
- if (hideEvent.isDefaultPrevented()) {
- continue;
- }
+ var dropdownMenu = context._menu;
+ if (!$(parent).hasClass(ClassName.SHOW)) {
+ continue;
+ }
- // if this is a touch-enabled device we remove the extra
- // empty mouseover listeners we added for iOS support
- if ('ontouchstart' in document.documentElement) {
- $('body').children().off('mouseover', null, $.noop);
- }
+ if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $.contains(parent, event.target)) {
+ continue;
+ }
- toggles[i].setAttribute('aria-expanded', 'false');
+ var hideEvent = $.Event(Event.HIDE, relatedTarget);
+ $(parent).trigger(hideEvent);
+ if (hideEvent.isDefaultPrevented()) {
+ continue;
+ }
- $(dropdownMenu).removeClass(ClassName.SHOW);
- $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget));
- }
- };
+ // if this is a touch-enabled device we remove the extra
+ // empty mouseover listeners we added for iOS support
+ if ('ontouchstart' in document.documentElement) {
+ $('body').children().off('mouseover', null, $.noop);
+ }
- Dropdown._getParentFromElement = function _getParentFromElement(element) {
- var parent = void 0;
- var selector = Util.getSelectorFromElement(element);
+ toggles[i].setAttribute('aria-expanded', 'false');
- if (selector) {
- parent = $(selector)[0];
+ $(dropdownMenu).removeClass(ClassName.SHOW);
+ $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget));
+ }
}
+ }, {
+ key: '_getParentFromElement',
+ value: function _getParentFromElement(element) {
+ var parent = void 0;
+ var selector = Util.getSelectorFromElement(element);
- return parent || element.parentNode;
- };
+ if (selector) {
+ parent = $(selector)[0];
+ }
- 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)) {
- return;
+ return parent || element.parentNode;
}
+ }, {
+ key: '_dataApiKeydownHandler',
+ value: 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)) {
+ return;
+ }
- event.preventDefault();
- event.stopPropagation();
+ event.preventDefault();
+ event.stopPropagation();
- if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
- return;
- }
+ if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
+ return;
+ }
- var parent = Dropdown._getParentFromElement(this);
- var isActive = $(parent).hasClass(ClassName.SHOW);
+ var parent = Dropdown._getParentFromElement(this);
+ var isActive = $(parent).hasClass(ClassName.SHOW);
- if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
+ if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
+
+ if (event.which === ESCAPE_KEYCODE) {
+ var toggle = $(parent).find(Selector.DATA_TOGGLE)[0];
+ $(toggle).trigger('focus');
+ }
- if (event.which === ESCAPE_KEYCODE) {
- var toggle = $(parent).find(Selector.DATA_TOGGLE)[0];
- $(toggle).trigger('focus');
+ $(this).trigger('click');
+ return;
}
- $(this).trigger('click');
- return;
- }
+ var items = $(parent).find(Selector.VISIBLE_ITEMS).get();
- var items = $(parent).find(Selector.VISIBLE_ITEMS).get();
+ if (!items.length) {
+ return;
+ }
- if (!items.length) {
- return;
- }
+ var index = items.indexOf(event.target);
- var index = items.indexOf(event.target);
+ if (event.which === ARROW_UP_KEYCODE && index > 0) {
+ // up
+ index--;
+ }
- if (event.which === ARROW_UP_KEYCODE && index > 0) {
- // up
- index--;
- }
+ if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
+ // down
+ index++;
+ }
- if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
- // down
- index++;
- }
+ if (index < 0) {
+ index = 0;
+ }
- if (index < 0) {
- index = 0;
+ items[index].focus();
}
-
- items[index].focus();
- };
-
- _createClass(Dropdown, null, [{
+ }, {
key: 'VERSION',
get: function get() {
return VERSION;
@@ -427,4 +440,4 @@ var Dropdown = function ($) {
};
return Dropdown;
-}(jQuery); /* global Popper */
+}(jQuery, Popper);