stylescape
Version:
Stylescape is a visual identity framework developed by Scape Agency.
37 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExclusiveDetails = void 0;
class ExclusiveDetails {
constructor(selector) {
this.detailsElements = document.querySelectorAll(selector);
this.bindEvents();
}
bindEvents() {
this.detailsElements.forEach((details) => {
details.addEventListener('click', (e) => this.handleDetailsClick(e, details));
});
document.addEventListener('click', (e) => this.handleClickOutside(e));
}
handleDetailsClick(event, details) {
event.stopPropagation();
this.detailsElements.forEach((otherDetails) => {
if (otherDetails !== details) {
otherDetails.removeAttribute('open');
}
});
}
handleClickOutside(event) {
const target = event.target;
const isClickInside = Array.from(this.detailsElements).some((details) => details.contains(target));
if (!isClickInside) {
this.closeAll();
}
}
closeAll() {
this.detailsElements.forEach((details) => {
details.removeAttribute('open');
});
}
}
exports.ExclusiveDetails = ExclusiveDetails;
//# sourceMappingURL=ExclusiveDetails.js.map