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.

51 lines
1.5 KiB

  1. // This file will be loaded on settings pages, regardless of theme.
  2. const { length } = require('stringz');
  3. const { delegate } = require('rails-ujs');
  4. delegate(document, '#account_display_name', 'input', ({ target }) => {
  5. const nameCounter = document.querySelector('.name-counter');
  6. const name = document.querySelector('.card .display-name strong');
  7. if (nameCounter) {
  8. nameCounter.textContent = 30 - length(target.value);
  9. }
  10. if (name) {
  11. name.innerHTML = emojify(target.value);
  12. }
  13. });
  14. delegate(document, '#account_note', 'input', ({ target }) => {
  15. const noteCounter = document.querySelector('.note-counter');
  16. if (noteCounter) {
  17. noteCounter.textContent = 160 - length(target.value);
  18. }
  19. });
  20. delegate(document, '#account_avatar', 'change', ({ target }) => {
  21. const avatar = document.querySelector('.card .avatar img');
  22. const [file] = target.files || [];
  23. const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
  24. avatar.src = url;
  25. });
  26. delegate(document, '#account_header', 'change', ({ target }) => {
  27. const header = document.querySelector('.card .card__img img');
  28. const [file] = target.files || [];
  29. const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
  30. header.src = url;
  31. });
  32. delegate(document, '#account_locked', 'change', ({ target }) => {
  33. const lock = document.querySelector('.card .display-name i');
  34. if (target.checked) {
  35. lock.style.display = 'inline';
  36. } else {
  37. lock.style.display = 'none';
  38. }
  39. });