aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/button.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/button.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/button.js106
1 files changed, 50 insertions, 56 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/button.js b/vendor/twbs/bootstrap/js/dist/button.js
index 92a3640fc..669fb2990 100644
--- a/vendor/twbs/bootstrap/js/dist/button.js
+++ b/vendor/twbs/bootstrap/js/dist/button.js
@@ -1,6 +1,6 @@
/*!
- * Bootstrap button.js v4.4.1 (https://getbootstrap.com/)
- * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
+ * Bootstrap button.js v4.5.0 (https://getbootstrap.com/)
+ * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
(function (global, factory) {
@@ -9,7 +9,7 @@
(global = global || self, global.Button = factory(global.jQuery));
}(this, (function ($) { 'use strict';
- $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
+ $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
@@ -34,39 +34,31 @@
*/
var NAME = 'button';
- var VERSION = '4.4.1';
+ var VERSION = '4.5.0';
var DATA_KEY = 'bs.button';
var EVENT_KEY = "." + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
- var ClassName = {
- ACTIVE: 'active',
- BUTTON: 'btn',
- FOCUS: 'focus'
- };
- var Selector = {
- DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
- DATA_TOGGLES: '[data-toggle="buttons"]',
- DATA_TOGGLE: '[data-toggle="button"]',
- DATA_TOGGLES_BUTTONS: '[data-toggle="buttons"] .btn',
- INPUT: 'input:not([type="hidden"])',
- ACTIVE: '.active',
- BUTTON: '.btn'
- };
- var Event = {
- CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
- FOCUS_BLUR_DATA_API: "focus" + EVENT_KEY + DATA_API_KEY + " " + ("blur" + EVENT_KEY + DATA_API_KEY),
- LOAD_DATA_API: "load" + EVENT_KEY + DATA_API_KEY
- };
+ var CLASS_NAME_ACTIVE = 'active';
+ var CLASS_NAME_BUTTON = 'btn';
+ var CLASS_NAME_FOCUS = 'focus';
+ var SELECTOR_DATA_TOGGLE_CARROT = '[data-toggle^="button"]';
+ var SELECTOR_DATA_TOGGLES = '[data-toggle="buttons"]';
+ var SELECTOR_DATA_TOGGLE = '[data-toggle="button"]';
+ var SELECTOR_DATA_TOGGLES_BUTTONS = '[data-toggle="buttons"] .btn';
+ var SELECTOR_INPUT = 'input:not([type="hidden"])';
+ var SELECTOR_ACTIVE = '.active';
+ var SELECTOR_BUTTON = '.btn';
+ var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
+ var EVENT_FOCUS_BLUR_DATA_API = "focus" + EVENT_KEY + DATA_API_KEY + " " + ("blur" + EVENT_KEY + DATA_API_KEY);
+ var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY;
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
- var Button =
- /*#__PURE__*/
- function () {
+ var Button = /*#__PURE__*/function () {
function Button(element) {
this._element = element;
} // Getters
@@ -78,33 +70,30 @@
_proto.toggle = function toggle() {
var triggerChangeEvent = true;
var addAriaPressed = true;
- var rootElement = $(this._element).closest(Selector.DATA_TOGGLES)[0];
+ var rootElement = $(this._element).closest(SELECTOR_DATA_TOGGLES)[0];
if (rootElement) {
- var input = this._element.querySelector(Selector.INPUT);
+ var input = this._element.querySelector(SELECTOR_INPUT);
if (input) {
if (input.type === 'radio') {
- if (input.checked && this._element.classList.contains(ClassName.ACTIVE)) {
+ if (input.checked && this._element.classList.contains(CLASS_NAME_ACTIVE)) {
triggerChangeEvent = false;
} else {
- var activeElement = rootElement.querySelector(Selector.ACTIVE);
+ var activeElement = rootElement.querySelector(SELECTOR_ACTIVE);
if (activeElement) {
- $(activeElement).removeClass(ClassName.ACTIVE);
+ $(activeElement).removeClass(CLASS_NAME_ACTIVE);
}
}
- } else if (input.type === 'checkbox') {
- if (this._element.tagName === 'LABEL' && input.checked === this._element.classList.contains(ClassName.ACTIVE)) {
- triggerChangeEvent = false;
- }
- } else {
- // if it's not a radio button or checkbox don't add a pointless/invalid checked property to the input
- triggerChangeEvent = false;
}
if (triggerChangeEvent) {
- input.checked = !this._element.classList.contains(ClassName.ACTIVE);
+ // if it's not a radio button or checkbox don't add a pointless/invalid checked property to the input
+ if (input.type === 'checkbox' || input.type === 'radio') {
+ input.checked = !this._element.classList.contains(CLASS_NAME_ACTIVE);
+ }
+
$(input).trigger('change');
}
@@ -115,11 +104,11 @@
if (!(this._element.hasAttribute('disabled') || this._element.classList.contains('disabled'))) {
if (addAriaPressed) {
- this._element.setAttribute('aria-pressed', !this._element.classList.contains(ClassName.ACTIVE));
+ this._element.setAttribute('aria-pressed', !this._element.classList.contains(CLASS_NAME_ACTIVE));
}
if (triggerChangeEvent) {
- $(this._element).toggleClass(ClassName.ACTIVE);
+ $(this._element).toggleClass(CLASS_NAME_ACTIVE);
}
}
};
@@ -161,17 +150,18 @@
*/
- $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
+ $(document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE_CARROT, function (event) {
var button = event.target;
+ var initialButton = button;
- if (!$(button).hasClass(ClassName.BUTTON)) {
- button = $(button).closest(Selector.BUTTON)[0];
+ if (!$(button).hasClass(CLASS_NAME_BUTTON)) {
+ button = $(button).closest(SELECTOR_BUTTON)[0];
}
if (!button || button.hasAttribute('disabled') || button.classList.contains('disabled')) {
event.preventDefault(); // work around Firefox bug #1540995
} else {
- var inputBtn = button.querySelector(Selector.INPUT);
+ var inputBtn = button.querySelector(SELECTOR_INPUT);
if (inputBtn && (inputBtn.hasAttribute('disabled') || inputBtn.classList.contains('disabled'))) {
event.preventDefault(); // work around Firefox bug #1540995
@@ -179,38 +169,42 @@
return;
}
+ if (initialButton.tagName === 'LABEL' && inputBtn && inputBtn.type === 'checkbox') {
+ event.preventDefault(); // work around event sent to label and input
+ }
+
Button._jQueryInterface.call($(button), 'toggle');
}
- }).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
- var button = $(event.target).closest(Selector.BUTTON)[0];
- $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
+ }).on(EVENT_FOCUS_BLUR_DATA_API, SELECTOR_DATA_TOGGLE_CARROT, function (event) {
+ var button = $(event.target).closest(SELECTOR_BUTTON)[0];
+ $(button).toggleClass(CLASS_NAME_FOCUS, /^focus(in)?$/.test(event.type));
});
- $(window).on(Event.LOAD_DATA_API, function () {
+ $(window).on(EVENT_LOAD_DATA_API, function () {
// ensure correct active class is set to match the controls' actual values/states
// find all checkboxes/readio buttons inside data-toggle groups
- var buttons = [].slice.call(document.querySelectorAll(Selector.DATA_TOGGLES_BUTTONS));
+ var buttons = [].slice.call(document.querySelectorAll(SELECTOR_DATA_TOGGLES_BUTTONS));
for (var i = 0, len = buttons.length; i < len; i++) {
var button = buttons[i];
- var input = button.querySelector(Selector.INPUT);
+ var input = button.querySelector(SELECTOR_INPUT);
if (input.checked || input.hasAttribute('checked')) {
- button.classList.add(ClassName.ACTIVE);
+ button.classList.add(CLASS_NAME_ACTIVE);
} else {
- button.classList.remove(ClassName.ACTIVE);
+ button.classList.remove(CLASS_NAME_ACTIVE);
}
} // find all button toggles
- buttons = [].slice.call(document.querySelectorAll(Selector.DATA_TOGGLE));
+ buttons = [].slice.call(document.querySelectorAll(SELECTOR_DATA_TOGGLE));
for (var _i = 0, _len = buttons.length; _i < _len; _i++) {
var _button = buttons[_i];
if (_button.getAttribute('aria-pressed') === 'true') {
- _button.classList.add(ClassName.ACTIVE);
+ _button.classList.add(CLASS_NAME_ACTIVE);
} else {
- _button.classList.remove(ClassName.ACTIVE);
+ _button.classList.remove(CLASS_NAME_ACTIVE);
}
}
});