Files

56 lines
1.2 KiB
JavaScript

window.Kronick = window.Kronick || {};
Kronick.state = Kronick.state || {};
Kronick.createId = function createId() {
if (
window.crypto
&& typeof window.crypto.randomUUID === 'function'
) {
return window.crypto.randomUUID();
}
return [
Date.now(),
Math.random().toString(36).slice(2)
].join('-');
};
Kronick.escapeHtml = function escapeHtml(value) {
return String(value)
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#039;');
};
Kronick.escapeAttribute = function escapeAttribute(value) {
return Kronick.escapeHtml(value);
};
Kronick.setStatus = function setStatus(
message,
state = ''
) {
const statusBar =
document.getElementById('statusBar');
const statusIndicator =
document.getElementById('statusIndicator');
if (statusBar) {
statusBar.innerText = message;
}
if (!statusIndicator) {
return;
}
statusIndicator.className =
'status-indicator';
if (state) {
statusIndicator.classList.add(state);
}
};