2023-02-19 05:06:14 +01:00
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2022-01-28 22:00:11 +01:00
|
|
|
|
2024-04-06 15:23:43 +02:00
|
|
|
function onPronounsDropdownUpdate() {
|
|
|
|
const pronounsCustom = document.getElementById('pronouns-custom');
|
|
|
|
const pronounsDropdown = document.getElementById('pronouns-dropdown');
|
|
|
|
const pronounsInput = pronounsDropdown.querySelector('input');
|
|
|
|
// must be kept in sync with `routers/web/user/setting/profile.go`
|
|
|
|
const isCustom = !(
|
|
|
|
pronounsInput.value === '' ||
|
|
|
|
pronounsInput.value === 'he/him' ||
|
|
|
|
pronounsInput.value === 'she/her' ||
|
|
|
|
pronounsInput.value === 'they/them' ||
|
|
|
|
pronounsInput.value === 'it/its' ||
|
|
|
|
pronounsInput.value === 'any pronouns'
|
|
|
|
);
|
|
|
|
if (isCustom) {
|
|
|
|
if (pronounsInput.value === '!') {
|
|
|
|
pronounsCustom.value = '';
|
|
|
|
} else {
|
|
|
|
pronounsCustom.value = pronounsInput.value;
|
|
|
|
}
|
|
|
|
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 19:28:04 +02:00
|
|
|
export function initUserSettings() {
|
2024-03-25 19:37:55 +01:00
|
|
|
if (!document.querySelectorAll('.user.settings.profile').length) return;
|
2024-02-16 16:52:50 +01: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);
|
|
|
|
}
|
|
|
|
});
|
2024-04-06 15:23:43 +02:00
|
|
|
|
|
|
|
const pronounsDropdown = document.getElementById('pronouns-dropdown');
|
|
|
|
const pronounsCustom = document.getElementById('pronouns-custom');
|
|
|
|
const pronounsInput = pronounsDropdown.querySelector('input');
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
pronounsCustom.removeAttribute('name');
|
|
|
|
pronounsInput.setAttribute('name', 'pronouns');
|
|
|
|
pronounsDropdown.style.display = '';
|
|
|
|
|
|
|
|
onPronounsDropdownUpdate();
|
|
|
|
pronounsInput.addEventListener('change', onPronounsDropdownUpdate);
|
|
|
|
pronounsCustom.addEventListener('input', onPronounsCustomUpdate);
|
2021-10-16 19:28:04 +02:00
|
|
|
}
|