@brizy/ui
Version:
React elements in Brizy style
32 lines (31 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.detachClick = exports.attachClick = void 0;
const nodeStack = new Map();
const handleClick = (e) => {
nodeStack.forEach(nodeCb => {
nodeCb(e);
});
};
const attachClick = (id, node, cb) => {
var _a;
const _window = (_a = node === null || node === void 0 ? void 0 : node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.window;
if (_window) {
if (nodeStack.size === 0) {
_window.addEventListener("click", handleClick);
}
nodeStack.set(id, cb);
}
};
exports.attachClick = attachClick;
const detachClick = (id, node) => {
var _a;
const _window = (_a = node === null || node === void 0 ? void 0 : node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.window;
if (_window) {
nodeStack.delete(id);
if (nodeStack.size === 0) {
_window.removeEventListener("click", handleClick);
}
}
};
exports.detachClick = detachClick;