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.

52 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. import emojify from '../mastodon/features/emoji/emoji';
  5. delegate(document, '#account_display_name', 'input', ({ target }) => {
  6. const nameCounter = document.querySelector('.name-counter');
  7. const name = document.querySelector('.card .display-name strong');
  8. if (nameCounter) {
  9. nameCounter.textContent = 30 - length(target.value);
  10. }
  11. if (name) {
  12. name.innerHTML = emojify(target.value);
  13. }
  14. });
  15. delegate(document, '#account_note', 'input', ({ target }) => {
  16. const noteCounter = document.querySelector('.note-counter');
  17. if (noteCounter) {
  18. noteCounter.textContent = 500 - length(target.value);
  19. }
  20. });
  21. delegate(document, '#account_avatar', 'change', ({ target }) => {
  22. const avatar = document.querySelector('.card .avatar img');
  23. const [file] = target.files || [];
  24. const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
  25. avatar.src = url;
  26. });
  27. delegate(document, '#account_header', 'change', ({ target }) => {
  28. const header = document.querySelector('.card .card__img img');
  29. const [file] = target.files || [];
  30. const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
  31. header.src = url;
  32. });
  33. delegate(document, '#account_locked', 'change', ({ target }) => {
  34. const lock = document.querySelector('.card .display-name i');
  35. if (target.checked) {
  36. lock.style.display = 'inline';
  37. } else {
  38. lock.style.display = 'none';
  39. }
  40. });