www_hero/node_modules/flowbite/lib/cjs/components/dismiss/index.js

68 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-05-03 04:39:20 +00:00
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initDismisses = void 0;
var Default = {
transition: 'transition-opacity',
duration: 300,
timing: 'ease-out',
onHide: function () { },
};
var Dismiss = /** @class */ (function () {
function Dismiss(targetEl, triggerEl, options) {
if (targetEl === void 0) { targetEl = null; }
if (triggerEl === void 0) { triggerEl = null; }
if (options === void 0) { options = Default; }
this._targetEl = targetEl;
this._triggerEl = triggerEl;
this._options = __assign(__assign({}, Default), options);
this._init();
}
Dismiss.prototype._init = function () {
var _this = this;
if (this._triggerEl) {
this._triggerEl.addEventListener('click', function () {
_this.hide();
});
}
};
Dismiss.prototype.hide = function () {
var _this = this;
this._targetEl.classList.add(this._options.transition, "duration-".concat(this._options.duration), this._options.timing, 'opacity-0');
setTimeout(function () {
_this._targetEl.classList.add('hidden');
}, this._options.duration);
// callback function
this._options.onHide(this, this._targetEl);
};
return Dismiss;
}());
function initDismisses() {
document.querySelectorAll('[data-dismiss-target]').forEach(function ($triggerEl) {
var targetId = $triggerEl.getAttribute('data-dismiss-target');
var $dismissEl = document.querySelector(targetId);
if ($dismissEl) {
new Dismiss($dismissEl, $triggerEl);
}
else {
console.error("The dismiss element with id \"".concat(targetId, "\" does not exist. Please check the data-dismiss-target attribute."));
}
});
}
exports.initDismisses = initDismisses;
if (typeof window !== 'undefined') {
window.Dismiss = Dismiss;
window.initDismisses = initDismisses;
}
exports.default = Dismiss;
//# sourceMappingURL=index.js.map