1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-05 10:18:45 +09:00
YuruToot/app/javascript/core/settings.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-11-19 08:12:52 +09:00
// This file will be loaded on settings pages, regardless of theme.
2017-11-21 15:13:37 +09:00
const { length } = require('stringz');
const { delegate } = require('rails-ujs');
2017-11-19 08:12:52 +09:00
2017-12-04 16:26:40 +09:00
import { processBio } from 'flavours/glitch/util/bio_metadata';
2017-12-01 12:29:47 +09:00
2017-11-21 15:13:37 +09:00
delegate(document, '.account_display_name', 'input', ({ target }) => {
const nameCounter = document.querySelector('.name-counter');
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
if (nameCounter) {
nameCounter.textContent = 30 - length(target.value);
}
});
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
delegate(document, '.account_note', 'input', ({ target }) => {
const noteCounter = document.querySelector('.note-counter');
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
if (noteCounter) {
const noteWithoutMetadata = processBio(target.value).text;
noteCounter.textContent = 500 - length(noteWithoutMetadata);
}
});
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
delegate(document, '#account_avatar', 'change', ({ target }) => {
const avatar = document.querySelector('.card.compact .avatar img');
const [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
avatar.src = url;
});
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
delegate(document, '#account_header', 'change', ({ target }) => {
const header = document.querySelector('.card.compact');
const [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
2017-11-19 08:12:52 +09:00
2017-11-21 15:13:37 +09:00
header.style.backgroundImage = `url(${url})`;
2017-11-19 08:12:52 +09:00
});