twbs--bootstrap/js/dist/button.js

167 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-09-30 17:28:03 -04:00
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-06 00:05:12 -04:00
2017-09-30 17:28:03 -04:00
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2016-10-09 20:26:51 -04:00
2015-05-07 20:07:38 -04:00
/**
* --------------------------------------------------------------------------
2017-10-19 12:40:37 -04:00
* Bootstrap (v4.0.0-beta.2): button.js
2015-05-07 20:07:38 -04:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
2017-09-06 00:05:12 -04:00
var Button = function () {
2015-05-07 20:07:38 -04:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'button';
2017-10-19 12:40:37 -04:00
var VERSION = '4.0.0-beta.2';
2015-05-07 20:07:38 -04:00
var DATA_KEY = 'bs.button';
2017-09-30 17:28:03 -04:00
var EVENT_KEY = "." + DATA_KEY;
2015-05-13 15:48:34 -04:00
var DATA_API_KEY = '.data-api';
2015-05-07 20:07:38 -04:00
var JQUERY_NO_CONFLICT = $.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 = {
2017-09-30 17:28:03 -04:00
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)
2017-09-13 01:24:15 -04:00
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2015-05-07 20:07:38 -04:00
2017-09-13 01:24:15 -04:00
};
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
var Button =
/*#__PURE__*/
function () {
function Button(element) {
2015-05-08 01:26:40 -04:00
this._element = element;
2017-09-30 17:28:03 -04:00
} // getters
2015-08-13 00:12:03 -04:00
2017-09-06 00:05:12 -04:00
2017-09-30 17:28:03 -04:00
var _proto = Button.prototype;
2017-09-06 00:05:12 -04:00
2017-09-30 17:28:03 -04:00
// public
_proto.toggle = function toggle() {
var triggerChangeEvent = true;
var addAriaPressed = true;
var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0];
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
if (rootElement) {
var input = $(this._element).find(Selector.INPUT)[0];
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
if (input) {
if (input.type === 'radio') {
if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) {
triggerChangeEvent = false;
} else {
var activeElement = $(rootElement).find(Selector.ACTIVE)[0];
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
if (activeElement) {
$(activeElement).removeClass(ClassName.ACTIVE);
2015-05-07 20:07:38 -04:00
}
}
2017-09-30 17:28:03 -04:00
}
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
if (triggerChangeEvent) {
if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) {
return;
2017-05-16 03:59:44 -04:00
}
2017-09-06 00:05:12 -04:00
2017-09-30 17:28:03 -04:00
input.checked = !$(this._element).hasClass(ClassName.ACTIVE);
$(input).trigger('change');
2015-05-07 20:07:38 -04:00
}
2017-09-30 17:28:03 -04:00
input.focus();
addAriaPressed = false;
2015-05-07 20:07:38 -04:00
}
2017-09-30 17:28:03 -04:00
}
2016-10-09 20:26:51 -04:00
2017-09-30 17:28:03 -04:00
if (addAriaPressed) {
this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE));
2017-04-16 16:54:07 -04:00
}
2017-09-30 17:28:03 -04:00
if (triggerChangeEvent) {
$(this._element).toggleClass(ClassName.ACTIVE);
2015-05-13 15:48:34 -04:00
}
2017-09-30 17:28:03 -04:00
};
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
_proto.dispose = function dispose() {
$.removeData(this._element, DATA_KEY);
this._element = null;
}; // static
2015-05-07 20:07:38 -04:00
2016-10-09 20:26:51 -04:00
2017-09-30 17:28:03 -04:00
Button._jQueryInterface = function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
2016-10-09 20:26:51 -04:00
2017-09-30 17:28:03 -04:00
if (!data) {
data = new Button(this);
$(this).data(DATA_KEY, data);
}
if (config === 'toggle') {
data[config]();
}
});
};
_createClass(Button, null, [{
key: "VERSION",
2015-08-13 00:12:03 -04:00
get: function get() {
return VERSION;
}
2015-05-07 20:07:38 -04:00
}]);
return Button;
2016-10-09 20:26:51 -04:00
}();
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
2015-05-07 20:07:38 -04:00
2017-09-30 17:28:03 -04:00
2015-05-13 15:48:34 -04:00
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
2015-05-07 20:07:38 -04:00
event.preventDefault();
var button = event.target;
if (!$(button).hasClass(ClassName.BUTTON)) {
button = $(button).closest(Selector.BUTTON);
}
Button._jQueryInterface.call($(button), 'toggle');
2015-05-13 15:48:34 -04:00
}).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
2015-05-07 20:07:38 -04:00
var button = $(event.target).closest(Selector.BUTTON)[0];
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
2017-07-02 13:40:27 -04:00
});
2015-05-07 20:07:38 -04:00
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
2017-07-02 13:40:27 -04:00
$.fn[NAME] = Button._jQueryInterface;
2015-05-07 20:07:38 -04:00
$.fn[NAME].Constructor = Button;
2017-09-30 17:28:03 -04:00
2015-05-07 20:07:38 -04:00
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Button._jQueryInterface;
};
return Button;
2017-10-15 18:51:44 -04:00
}($);
2017-04-22 02:58:09 -04:00
//# sourceMappingURL=button.js.map