-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* AgnosticWipe 0.1.0
*
* A utility function that safely removes all child nodes of a given element,
* now with configurable debugging capabilities (log/warn) similar to all Agnostic
* modules developed by us.
*
* Developed by Claudio González (claudio@banshee.pro)
* for Banshee Technologies - https://www.banshee.pro
*
* MIT License
* Copyright (c) 2024 Banshee Technologies. All rights reserved.
*/
let globalDebugLogWipe = false;
let globalDebugWarnWipe = false;
export function agnosticWipe({ debugLog = false, debugWarn = false } = {}) {
globalDebugLogWipe = debugLog;
globalDebugWarnWipe = debugWarn;
return function (targetSelector) {
const targetElement = document.querySelector(targetSelector);
if (!targetElement) {
if (globalDebugWarnWipe) {
console.warn(`AgnosticWipe: Target element with selector "${targetSelector}" does not exist.`);
}
return;
}
if (globalDebugLogWipe) {
console.log(`AgnosticWipe: Wiping content of "${targetSelector}".`);
}
while (targetElement.firstChild) {
targetElement.removeChild(targetElement.firstChild);
}
if (globalDebugLogWipe) {
console.log(`AgnosticWipe: Content of "${targetSelector}" has been wiped.`);
}
};
}