0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-11 03:52:27 +01:00
Bootstrap/js/dist/button.js

193 lines
5.9 KiB
JavaScript
Raw Permalink Normal View History

2018-07-23 17:51:14 -07:00
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
(global.Button = factory(global.jQuery));
}(this, (function ($) { 'use strict';
$ = $ && $.hasOwnProperty('default') ? $['default'] : $;
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);
}
}
2017-09-05 21:05:12 -07:00
2018-07-23 17:51:14 -07:00
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
2016-10-09 17:26:51 -07:00
2015-05-07 17:07:38 -07:00
/**
2018-07-23 17:51:14 -07:00
* --------------------------------------------------------------------------
2018-07-23 19:25:52 -07:00
* Bootstrap (v4.1.3): button.js
2018-07-23 17:51:14 -07:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
2015-05-07 17:07:38 -07:00
*/
2018-07-23 17:51:14 -07:00
var Button = function ($$$1) {
2017-09-12 22:24:15 -07:00
/**
* ------------------------------------------------------------------------
2018-07-23 17:51:14 -07:00
* Constants
2017-09-12 22:24:15 -07:00
* ------------------------------------------------------------------------
*/
2018-07-23 17:51:14 -07:00
var NAME = 'button';
2018-07-23 19:25:52 -07:00
var VERSION = '4.1.3';
2018-07-23 17:51:14 -07:00
var DATA_KEY = 'bs.button';
var EVENT_KEY = "." + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $$$1.fn[NAME];
var ClassName = {
ACTIVE: 'active',
BUTTON: 'btn',
FOCUS: 'focus'
};
var Selector = {
DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
DATA_TOGGLE: '[data-toggle="buttons"]',
INPUT: 'input',
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)
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
};
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
var Button =
/*#__PURE__*/
function () {
function Button(element) {
this._element = element;
} // Getters
2015-08-12 21:12:03 -07:00
2017-09-05 21:05:12 -07:00
2018-07-23 17:51:14 -07:00
var _proto = Button.prototype;
2017-09-05 21:05:12 -07:00
2018-07-23 17:51:14 -07:00
// Public
_proto.toggle = function toggle() {
var triggerChangeEvent = true;
var addAriaPressed = true;
var rootElement = $$$1(this._element).closest(Selector.DATA_TOGGLE)[0];
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
if (rootElement) {
var input = this._element.querySelector(Selector.INPUT);
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
if (input) {
if (input.type === 'radio') {
if (input.checked && this._element.classList.contains(ClassName.ACTIVE)) {
triggerChangeEvent = false;
} else {
var activeElement = rootElement.querySelector(Selector.ACTIVE);
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
if (activeElement) {
$$$1(activeElement).removeClass(ClassName.ACTIVE);
}
2015-05-07 17:07:38 -07:00
}
}
2018-07-23 17:51:14 -07:00
if (triggerChangeEvent) {
if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) {
return;
}
input.checked = !this._element.classList.contains(ClassName.ACTIVE);
$$$1(input).trigger('change');
2017-05-16 09:59:44 +02:00
}
2017-09-05 21:05:12 -07:00
2018-07-23 17:51:14 -07:00
input.focus();
addAriaPressed = false;
2015-05-07 17:07:38 -07:00
}
2018-07-23 17:51:14 -07:00
}
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
if (addAriaPressed) {
this._element.setAttribute('aria-pressed', !this._element.classList.contains(ClassName.ACTIVE));
2015-05-07 17:07:38 -07:00
}
2016-10-09 17:26:51 -07:00
2018-07-23 17:51:14 -07:00
if (triggerChangeEvent) {
$$$1(this._element).toggleClass(ClassName.ACTIVE);
}
};
2017-09-30 14:28:03 -07:00
2018-07-23 17:51:14 -07:00
_proto.dispose = function dispose() {
$$$1.removeData(this._element, DATA_KEY);
this._element = null;
}; // Static
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
Button._jQueryInterface = function _jQueryInterface(config) {
return this.each(function () {
var data = $$$1(this).data(DATA_KEY);
2016-10-09 17:26:51 -07:00
2018-07-23 17:51:14 -07:00
if (!data) {
data = new Button(this);
$$$1(this).data(DATA_KEY, data);
}
2016-10-09 17:26:51 -07:00
2018-07-23 17:51:14 -07:00
if (config === 'toggle') {
data[config]();
}
});
};
2017-09-30 14:28:03 -07:00
2018-07-23 17:51:14 -07:00
_createClass(Button, null, [{
key: "VERSION",
get: function get() {
return VERSION;
2017-09-30 14:28:03 -07:00
}
2018-07-23 17:51:14 -07:00
}]);
2017-09-30 14:28:03 -07:00
2018-07-23 17:51:14 -07:00
return Button;
}();
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
$$$1(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
event.preventDefault();
var button = event.target;
2017-09-30 14:28:03 -07:00
2018-07-23 17:51:14 -07:00
if (!$$$1(button).hasClass(ClassName.BUTTON)) {
button = $$$1(button).closest(Selector.BUTTON);
}
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
Button._jQueryInterface.call($$$1(button), 'toggle');
}).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
var button = $$$1(event.target).closest(Selector.BUTTON)[0];
$$$1(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
$$$1.fn[NAME] = Button._jQueryInterface;
$$$1.fn[NAME].Constructor = Button;
2015-05-07 17:07:38 -07:00
2018-07-23 17:51:14 -07:00
$$$1.fn[NAME].noConflict = function () {
$$$1.fn[NAME] = JQUERY_NO_CONFLICT;
return Button._jQueryInterface;
};
2017-09-30 14:28:03 -07:00
2018-07-23 17:51:14 -07:00
return Button;
}($);
2015-05-07 17:07:38 -07:00
return Button;
2018-07-23 17:51:14 -07:00
})));
//# sourceMappingURL=button.js.map