0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-13 01:08:58 +01:00
Bootstrap/js/dist/util/component-functions.js

42 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-05-13 08:07:23 +02:00
/*!
* Bootstrap component-functions.js v5.3.0-alpha3 (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2022-05-13 08:07:23 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('../dom/event-handler.js'), require('../dom/selector-engine.js'), require('./index.js')) :
typeof define === 'function' && define.amd ? define(['exports', '../dom/event-handler', '../dom/selector-engine', './index'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComponentFunctions = {}, global.EventHandler, global.SelectorEngine, global.Index));
})(this, (function (exports, EventHandler, SelectorEngine, index_js) { 'use strict';
2022-05-13 08:07:23 +02:00
/**
* --------------------------------------------------------------------------
* Bootstrap util/component-functions.js
2022-05-13 08:07:23 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
const enableDismissTrigger = (component, method = 'hide') => {
const clickEvent = `click.dismiss${component.EVENT_KEY}`;
const name = component.NAME;
EventHandler.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
2022-05-13 08:07:23 +02:00
if (['A', 'AREA'].includes(this.tagName)) {
event.preventDefault();
}
if (index_js.isDisabled(this)) {
2022-05-13 08:07:23 +02:00
return;
}
const target = SelectorEngine.getElementFromSelector(this) || this.closest(`.${name}`);
const instance = component.getOrCreateInstance(target);
2022-05-13 08:07:23 +02:00
// Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
2022-05-13 08:07:23 +02:00
instance[method]();
});
};
exports.enableDismissTrigger = enableDismissTrigger;
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2022-05-13 08:07:23 +02:00
}));
//# sourceMappingURL=component-functions.js.map