2017-11-18 18:12:52 -05:00
|
|
|
// This file will be loaded on settings pages, regardless of theme.
|
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
const { length } = require('stringz');
|
|
|
|
const { delegate } = require('rails-ujs');
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-30 22:29:47 -05:00
|
|
|
import { processBio } from 'themes/glitch/util/bio_metadata';
|
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
delegate(document, '.account_display_name', 'input', ({ target }) => {
|
|
|
|
const nameCounter = document.querySelector('.name-counter');
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
if (nameCounter) {
|
|
|
|
nameCounter.textContent = 30 - length(target.value);
|
|
|
|
}
|
|
|
|
});
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
delegate(document, '.account_note', 'input', ({ target }) => {
|
|
|
|
const noteCounter = document.querySelector('.note-counter');
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
if (noteCounter) {
|
|
|
|
const noteWithoutMetadata = processBio(target.value).text;
|
|
|
|
noteCounter.textContent = 500 - length(noteWithoutMetadata);
|
|
|
|
}
|
|
|
|
});
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05: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-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
avatar.src = url;
|
|
|
|
});
|
2017-11-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05: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-18 18:12:52 -05:00
|
|
|
|
2017-11-21 01:13:37 -05:00
|
|
|
header.style.backgroundImage = `url(${url})`;
|
2017-11-18 18:12:52 -05:00
|
|
|
});
|
2017-11-30 22:29:47 -05:00
|
|
|
|
|
|
|
delegate(document, '#user_setting_theme', 'change', ({ target }) => {
|
|
|
|
target.form.submit();
|
|
|
|
});
|