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

147 lines
4.7 KiB
JavaScript
Raw Normal View History

2018-11-13 06:41:12 +00:00
/*!
2021-10-09 06:33:12 +00:00
* Bootstrap button.js v5.1.3 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 18:50:01 +00:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2018-11-13 06:41:12 +00:00
*/
2018-07-24 00:51:14 +00:00
(function (global, factory) {
2021-08-04 15:41:51 +00:00
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) :
typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.EventHandler, global.Base));
2021-10-05 15:50:18 +00:00
})(this, (function (EventHandler, BaseComponent) { 'use strict';
2018-07-24 00:51:14 +00:00
2021-10-05 15:50:18 +00:00
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
2020-09-14 15:12:06 +00:00
2021-10-05 15:50:18 +00:00
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
2021-08-04 15:41:51 +00:00
/**
* --------------------------------------------------------------------------
2021-10-09 06:33:12 +00:00
* Bootstrap (v5.1.3): util/index.js
2021-08-04 15:41:51 +00:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
2021-03-23 16:26:54 +00:00
const getjQuery = () => {
const {
jQuery
} = window;
2019-08-27 13:03:21 +00:00
2020-11-23 13:17:16 +00:00
if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
2019-08-27 13:03:21 +00:00
return jQuery;
}
return null;
};
2019-03-01 16:31:34 +00:00
const DOMContentLoadedCallbacks = [];
2021-03-23 16:26:54 +00:00
const onDOMContentLoaded = callback => {
2020-11-11 17:07:37 +00:00
if (document.readyState === 'loading') {
// add listener on the first call when the document is in loading state
if (!DOMContentLoadedCallbacks.length) {
document.addEventListener('DOMContentLoaded', () => {
DOMContentLoadedCallbacks.forEach(callback => callback());
});
}
DOMContentLoadedCallbacks.push(callback);
2020-11-11 17:07:37 +00:00
} else {
callback();
}
};
const defineJQueryPlugin = plugin => {
2021-03-23 16:26:54 +00:00
onDOMContentLoaded(() => {
const $ = getjQuery();
/* istanbul ignore if */
2020-12-03 14:18:59 +00:00
if ($) {
const name = plugin.NAME;
2021-03-23 16:26:54 +00:00
const JQUERY_NO_CONFLICT = $.fn[name];
$.fn[name] = plugin.jQueryInterface;
$.fn[name].Constructor = plugin;
2020-12-03 14:18:59 +00:00
2021-03-23 16:26:54 +00:00
$.fn[name].noConflict = () => {
$.fn[name] = JQUERY_NO_CONFLICT;
return plugin.jQueryInterface;
};
2020-12-03 14:18:59 +00:00
}
});
};
2020-12-03 14:18:59 +00:00
2021-03-23 16:26:54 +00:00
/**
* --------------------------------------------------------------------------
2021-10-09 06:33:12 +00:00
* Bootstrap (v5.1.3): button.js
2021-03-23 16:26:54 +00:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
2020-12-03 14:18:59 +00:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
2021-03-23 16:26:54 +00:00
const NAME = 'button';
const DATA_KEY = 'bs.button';
const EVENT_KEY = `.${DATA_KEY}`;
const DATA_API_KEY = '.data-api';
const CLASS_NAME_ACTIVE = 'active';
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]';
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
2019-10-08 06:39:10 +00:00
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2015-05-08 00:07:38 +00:00
2021-10-05 15:50:18 +00:00
class Button extends BaseComponent__default.default {
2021-03-23 16:26:54 +00:00
// Getters
static get NAME() {
return NAME;
2021-03-23 16:26:54 +00:00
} // Public
2017-09-06 04:05:12 +00:00
2021-03-23 16:26:54 +00:00
toggle() {
2020-06-16 18:50:01 +00:00
// Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE));
2019-01-04 16:29:45 +00:00
} // Static
2016-10-10 00:26:51 +00:00
2021-03-23 16:26:54 +00:00
static jQueryInterface(config) {
2018-11-13 06:41:12 +00:00
return this.each(function () {
const data = Button.getOrCreateInstance(this);
2017-09-30 21:28:03 +00:00
2018-11-13 06:41:12 +00:00
if (config === 'toggle') {
data[config]();
2017-09-30 21:28:03 +00:00
}
2018-11-13 06:41:12 +00:00
});
2021-03-23 16:26:54 +00:00
}
2015-05-08 00:07:38 +00:00
2021-03-23 16:26:54 +00:00
}
2018-11-13 06:41:12 +00:00
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
2015-05-08 00:07:38 +00:00
2017-09-30 21:28:03 +00:00
2021-10-05 15:50:18 +00:00
EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
2018-11-13 06:41:12 +00:00
event.preventDefault();
2021-03-23 16:26:54 +00:00
const button = event.target.closest(SELECTOR_DATA_TOGGLE);
const data = Button.getOrCreateInstance(button);
2019-03-01 16:31:34 +00:00
data.toggle();
});
2018-11-13 06:41:12 +00:00
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
2020-11-11 17:07:37 +00:00
* add .Button to jQuery only if jQuery is present
2018-11-13 06:41:12 +00:00
*/
2015-05-08 00:07:38 +00:00
defineJQueryPlugin(Button);
2015-05-08 00:07:38 +00:00
return Button;
2018-07-24 00:51:14 +00:00
2021-10-05 15:50:18 +00:00
}));
2018-07-24 00:51:14 +00:00
//# sourceMappingURL=button.js.map