2021-08-25 20:02:05 -04:00
|
|
|
const $ = function(selector) {
|
|
|
|
return document.querySelector(selector);
|
|
|
|
};
|
|
|
|
|
|
|
|
const $$ = function(selector) {
|
|
|
|
return document.querySelectorAll(selector) || [];
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeEl = function(html) {
|
|
|
|
const template = document.createElement('template');
|
|
|
|
|
|
|
|
template.innerHTML = html.trim();
|
|
|
|
|
|
|
|
return template.content.firstChild;
|
|
|
|
};
|
|
|
|
|
2021-09-03 08:00:22 -04:00
|
|
|
const clearEl = function(el) {
|
|
|
|
while (el.firstChild) {
|
|
|
|
el.removeChild(el.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-04 11:35:36 -04:00
|
|
|
const toggleEl = function(el) {
|
|
|
|
if (el.classList.contains('is-hidden')) {
|
|
|
|
el.classList.remove('is-hidden');
|
|
|
|
} else {
|
|
|
|
el.classList.add('is-hidden');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-25 20:02:05 -04:00
|
|
|
const escape = function(unsafe) {
|
|
|
|
return unsafe
|
|
|
|
.replace(/&/g, "&")
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">")
|
|
|
|
.replace(/"/g, """)
|
|
|
|
.replace(/'/g, "'");
|
|
|
|
}
|
|
|
|
|
2021-11-23 03:17:29 -05:00
|
|
|
const whenReady = function(funcp) {
|
|
|
|
if (document.readyState !== 'loading') {
|
|
|
|
funcp();
|
|
|
|
} else {
|
|
|
|
document.addEventListener('DOMContentLoaded', funcp);
|
|
|
|
}
|
|
|
|
}
|
2021-08-25 20:02:05 -04:00
|
|
|
|
2021-11-23 03:17:29 -05:00
|
|
|
export { whenReady, $, $$, makeEl, clearEl, toggleEl, escape };
|