2023-02-19 07:06:14 +03:00
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2022-01-29 00:00:11 +03:00
|
|
|
|
2023-09-26 08:56:20 +03:00
|
|
|
function onPronounsDropdownUpdate() {
|
|
|
|
const pronounsCustom = document.getElementById('pronouns-custom');
|
2023-09-26 09:21:52 +03:00
|
|
|
const pronounsDropdown = document.getElementById('pronouns-dropdown');
|
|
|
|
const pronounsInput = pronounsDropdown.querySelector('input');
|
2024-02-26 22:43:04 +03:00
|
|
|
// must be kept in sync with `routers/web/user/setting/profile.go`
|
2023-09-26 08:56:20 +03:00
|
|
|
const isCustom = !(
|
2023-09-26 09:21:52 +03:00
|
|
|
pronounsInput.value === '' ||
|
2023-09-26 08:56:20 +03:00
|
|
|
pronounsInput.value === 'he/him' ||
|
|
|
|
pronounsInput.value === 'she/her' ||
|
|
|
|
pronounsInput.value === 'they/them' ||
|
2023-09-26 20:54:18 +03:00
|
|
|
pronounsInput.value === 'it/its' ||
|
2024-02-24 21:24:12 +03:00
|
|
|
pronounsInput.value === 'any pronouns'
|
2023-09-26 08:56:20 +03:00
|
|
|
);
|
|
|
|
if (isCustom) {
|
2023-09-26 09:21:52 +03:00
|
|
|
if (pronounsInput.value === '!') {
|
|
|
|
pronounsCustom.value = '';
|
|
|
|
} else {
|
|
|
|
pronounsCustom.value = pronounsInput.value;
|
|
|
|
}
|
2023-09-26 08:56:20 +03:00
|
|
|
pronounsCustom.style.display = '';
|
|
|
|
} else {
|
|
|
|
pronounsCustom.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function onPronounsCustomUpdate() {
|
|
|
|
const pronounsCustom = document.getElementById('pronouns-custom');
|
|
|
|
const pronounsInput = document.querySelector('#pronouns-dropdown input');
|
|
|
|
pronounsInput.value = pronounsCustom.value;
|
|
|
|
}
|
|
|
|
|
2021-10-16 20:28:04 +03:00
|
|
|
export function initUserSettings() {
|
2024-03-25 21:37:55 +03:00
|
|
|
if (!document.querySelectorAll('.user.settings.profile').length) return;
|
2024-02-16 18:52:50 +03:00
|
|
|
|
|
|
|
const usernameInput = document.getElementById('username');
|
|
|
|
if (!usernameInput) return;
|
|
|
|
usernameInput.addEventListener('input', function () {
|
|
|
|
const prompt = document.getElementById('name-change-prompt');
|
|
|
|
const promptRedirect = document.getElementById('name-change-redirect-prompt');
|
|
|
|
if (this.value.toLowerCase() !== this.getAttribute('data-name').toLowerCase()) {
|
|
|
|
showElem(prompt);
|
|
|
|
showElem(promptRedirect);
|
|
|
|
} else {
|
|
|
|
hideElem(prompt);
|
|
|
|
hideElem(promptRedirect);
|
|
|
|
}
|
|
|
|
});
|
2023-09-26 08:56:20 +03:00
|
|
|
|
|
|
|
const pronounsDropdown = document.getElementById('pronouns-dropdown');
|
|
|
|
const pronounsCustom = document.getElementById('pronouns-custom');
|
|
|
|
const pronounsInput = pronounsDropdown.querySelector('input');
|
2024-02-26 22:43:04 +03:00
|
|
|
|
|
|
|
// If JS is disabled, the page will show the custom input, as the dropdown requires JS to work.
|
|
|
|
// JS progressively enhances the input by adding a dropdown, but it works regardless.
|
2023-09-26 08:56:20 +03:00
|
|
|
pronounsCustom.removeAttribute('name');
|
|
|
|
pronounsDropdown.style.display = '';
|
2024-02-26 22:43:04 +03:00
|
|
|
|
2023-09-26 08:56:20 +03:00
|
|
|
onPronounsDropdownUpdate();
|
|
|
|
pronounsInput.addEventListener('change', onPronounsDropdownUpdate);
|
|
|
|
pronounsCustom.addEventListener('input', onPronounsCustomUpdate);
|
2021-10-16 20:28:04 +03:00
|
|
|
}
|