forked from hero/www_hero
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
|
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);
|
||
|
};
|
||
|
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;
|
||
|
}());
|
||
|
export 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."));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
if (typeof window !== 'undefined') {
|
||
|
window.Dismiss = Dismiss;
|
||
|
window.initDismisses = initDismisses;
|
||
|
}
|
||
|
export default Dismiss;
|
||
|
//# sourceMappingURL=index.js.map
|