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.

66 lines
1.9 KiB

  1. // This file will be loaded on settings pages, regardless of theme.
  2. import escapeTextContentForBrowser from 'escape-html';
  3. const { delegate } = require('rails-ujs');
  4. import emojify from '../mastodon/features/emoji/emoji';
  5. delegate(document, '#account_display_name', 'input', ({ target }) => {
  6. const name = document.querySelector('.card .display-name strong');
  7. if (name) {
  8. if (target.value) {
  9. name.innerHTML = emojify(escapeTextContentForBrowser(target.value));
  10. } else {
  11. name.textContent = document.querySelector('#default_account_display_name').textContent;
  12. }
  13. }
  14. });
  15. delegate(document, '#account_avatar', 'change', ({ target }) => {
  16. const avatar = document.querySelector('.card .avatar img');
  17. const [file] = target.files || [];
  18. const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
  19. avatar.src = url;
  20. });
  21. delegate(document, '#account_header', 'change', ({ target }) => {
  22. const header = document.querySelector('.card .card__img img');
  23. const [file] = target.files || [];
  24. const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
  25. header.src = url;
  26. });
  27. delegate(document, '#account_locked', 'change', ({ target }) => {
  28. const lock = document.querySelector('.card .display-name i');
  29. if (target.checked) {
  30. lock.style.display = 'inline';
  31. } else {
  32. lock.style.display = 'none';
  33. }
  34. });
  35. delegate(document, '.input-copy input', 'click', ({ target }) => {
  36. target.select();
  37. });
  38. delegate(document, '.input-copy button', 'click', ({ target }) => {
  39. const input = target.parentNode.querySelector('.input-copy__wrapper input');
  40. input.focus();
  41. input.select();
  42. try {
  43. if (document.execCommand('copy')) {
  44. input.blur();
  45. target.parentNode.classList.add('copied');
  46. setTimeout(() => {
  47. target.parentNode.classList.remove('copied');
  48. }, 700);
  49. }
  50. } catch (err) {
  51. console.error(err);
  52. }
  53. });