Remove redundant ready() wrapper (#26533)

This commit is contained in:
Christian Schmidt 2023-08-18 12:06:08 +02:00 committed by GitHub
parent 1cb978bcc3
commit bb51c0676d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 245 additions and 248 deletions

View File

@ -65,7 +65,6 @@ function loaded() {
}; };
}; };
ready(() => {
const locale = document.documentElement.lang; const locale = document.documentElement.lang;
const dateTimeFormat = new Intl.DateTimeFormat(locale, { const dateTimeFormat = new Intl.DateTimeFormat(locale, {
@ -219,9 +218,9 @@ function loaded() {
const message = (statusEl.dataset.spoiler === 'expanded') ? (localeData['status.show_less'] || 'Show less') : (localeData['status.show_more'] || 'Show more'); const message = (statusEl.dataset.spoiler === 'expanded') ? (localeData['status.show_less'] || 'Show less') : (localeData['status.show_more'] || 'Show more');
spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format(); spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format();
}); });
}); }
delegate(document, '#account_display_name', 'input', ({ target }) => { delegate(document, '#account_display_name', 'input', ({ target }) => {
const name = document.querySelector('.card .display-name strong'); const name = document.querySelector('.card .display-name strong');
if (name) { if (name) {
if (target.value) { if (target.value) {
@ -230,17 +229,17 @@ function loaded() {
name.textContent = target.dataset.default; name.textContent = target.dataset.default;
} }
} }
}); });
delegate(document, '#account_avatar', 'change', ({ target }) => { delegate(document, '#account_avatar', 'change', ({ target }) => {
const avatar = document.querySelector('.card .avatar img'); const avatar = document.querySelector('.card .avatar img');
const [file] = target.files || []; const [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc; const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
avatar.src = url; avatar.src = url;
}); });
const getProfileAvatarAnimationHandler = (swapTo) => { const getProfileAvatarAnimationHandler = (swapTo) => {
//animate avatar gifs on the profile page when moused over //animate avatar gifs on the profile page when moused over
return ({ target }) => { return ({ target }) => {
const swapSrc = target.getAttribute(swapTo); const swapSrc = target.getAttribute(swapTo);
@ -249,21 +248,21 @@ function loaded() {
target.src = swapSrc; target.src = swapSrc;
} }
}; };
}; };
delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original')); delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original'));
delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static')); delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static'));
delegate(document, '#account_header', 'change', ({ target }) => { delegate(document, '#account_header', 'change', ({ target }) => {
const header = document.querySelector('.card .card__img img'); const header = document.querySelector('.card .card__img img');
const [file] = target.files || []; const [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc; const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
header.src = url; header.src = url;
}); });
delegate(document, '#account_locked', 'change', ({ target }) => { delegate(document, '#account_locked', 'change', ({ target }) => {
const lock = document.querySelector('.card .display-name i'); const lock = document.querySelector('.card .display-name i');
if (lock) { if (lock) {
@ -273,15 +272,15 @@ function loaded() {
lock.dataset.hidden = 'true'; lock.dataset.hidden = 'true';
} }
} }
}); });
delegate(document, '.input-copy input', 'click', ({ target }) => { delegate(document, '.input-copy input', 'click', ({ target }) => {
target.focus(); target.focus();
target.select(); target.select();
target.setSelectionRange(0, target.value.length); target.setSelectionRange(0, target.value.length);
}); });
delegate(document, '.input-copy button', 'click', ({ target }) => { delegate(document, '.input-copy button', 'click', ({ target }) => {
const input = target.parentNode.querySelector('.input-copy__wrapper input'); const input = target.parentNode.querySelector('.input-copy__wrapper input');
const oldReadOnly = input.readonly; const oldReadOnly = input.readonly;
@ -305,9 +304,9 @@ function loaded() {
} }
input.readonly = oldReadOnly; input.readonly = oldReadOnly;
}); });
const toggleSidebar = () => { const toggleSidebar = () => {
const sidebar = document.querySelector('.sidebar ul'); const sidebar = document.querySelector('.sidebar ul');
const toggleButton = document.querySelector('.sidebar__toggle__icon'); const toggleButton = document.querySelector('.sidebar__toggle__icon');
@ -321,31 +320,29 @@ function loaded() {
toggleButton.classList.toggle('active'); toggleButton.classList.toggle('active');
sidebar.classList.toggle('visible'); sidebar.classList.toggle('visible');
}; };
delegate(document, '.sidebar__toggle__icon', 'click', () => { delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar(); toggleSidebar();
}); });
delegate(document, '.sidebar__toggle__icon', 'keydown', e => { delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') { if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
toggleSidebar(); toggleSidebar();
} }
}); });
// Empty the honeypot fields in JS in case something like an extension // Empty the honeypot fields in JS in case something like an extension
// automatically filled them. // automatically filled them.
delegate(document, '#registration_new_user,#new_user', 'submit', () => { delegate(document, '#registration_new_user,#new_user', 'submit', () => {
['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => { ['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => {
const field = document.getElementById(id); const field = document.getElementById(id);
if (field) { if (field) {
field.value = ''; field.value = '';
} }
}); });
}); });
}
function main() { function main() {
ready(loaded); ready(loaded);