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.

39 lines
1.3 KiB

7 years ago
  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 { processBio } from 'flavours/glitch/util/bio_metadata';
  5. delegate(document, '.account_display_name', 'input', ({ target }) => {
  6. const nameCounter = document.querySelector('.name-counter');
  7. if (nameCounter) {
  8. nameCounter.textContent = 30 - length(target.value);
  9. }
  10. });
  11. delegate(document, '.account_note', 'input', ({ target }) => {
  12. const noteCounter = document.querySelector('.note-counter');
  13. if (noteCounter) {
  14. const noteWithoutMetadata = processBio(target.value).text;
  15. noteCounter.textContent = 500 - length(noteWithoutMetadata);
  16. }
  17. });
  18. delegate(document, '#account_avatar', 'change', ({ target }) => {
  19. const avatar = document.querySelector('.card.compact .avatar img');
  20. const [file] = target.files || [];
  21. const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
  22. avatar.src = url;
  23. });
  24. delegate(document, '#account_header', 'change', ({ target }) => {
  25. const header = document.querySelector('.card.compact');
  26. const [file] = target.files || [];
  27. const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
  28. header.style.backgroundImage = `url(${url})`;
  29. });