You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 regels
732 B

  1. // assets/scripts/utils.js
  2. const ESCAPES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
  3. export const ANIMATION_MS = 280;
  4. export const FADE_MS = 180;
  5. export const MINUTES_PER_DAY = 1440;
  6. export function esc(str) {
  7. return String(str ?? '').replace(/[&<>"']/g, c => ESCAPES[c]);
  8. }
  9. export function createTranslator(namespace, defaults = {}) {
  10. return (key) => window[namespace]?.i18n?.[key] ?? defaults[key] ?? key;
  11. }
  12. export function removeWithAnimation(el, className) {
  13. el.classList.add(className);
  14. setTimeout(() => el.remove(), ANIMATION_MS);
  15. }
  16. export function animateIn(el, className) {
  17. requestAnimationFrame(() => requestAnimationFrame(() => {
  18. el.classList.remove(className);
  19. }));
  20. }