Remove redundant ready() wrapper (#26533)

main
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 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');
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');
if (name) {
if (target.value) {
@ -230,17 +229,17 @@ function loaded() {
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 [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
avatar.src = url;
});
});
const getProfileAvatarAnimationHandler = (swapTo) => {
const getProfileAvatarAnimationHandler = (swapTo) => {
//animate avatar gifs on the profile page when moused over
return ({ target }) => {
const swapSrc = target.getAttribute(swapTo);
@ -249,21 +248,21 @@ function loaded() {
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 [file] = target.files || [];
const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
header.src = url;
});
});
delegate(document, '#account_locked', 'change', ({ target }) => {
delegate(document, '#account_locked', 'change', ({ target }) => {
const lock = document.querySelector('.card .display-name i');
if (lock) {
@ -273,15 +272,15 @@ function loaded() {
lock.dataset.hidden = 'true';
}
}
});
});
delegate(document, '.input-copy input', 'click', ({ target }) => {
delegate(document, '.input-copy input', 'click', ({ target }) => {
target.focus();
target.select();
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 oldReadOnly = input.readonly;
@ -305,9 +304,9 @@ function loaded() {
}
input.readonly = oldReadOnly;
});
});
const toggleSidebar = () => {
const toggleSidebar = () => {
const sidebar = document.querySelector('.sidebar ul');
const toggleButton = document.querySelector('.sidebar__toggle__icon');
@ -321,31 +320,29 @@ function loaded() {
toggleButton.classList.toggle('active');
sidebar.classList.toggle('visible');
};
};
delegate(document, '.sidebar__toggle__icon', 'click', () => {
delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar();
});
});
delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
toggleSidebar();
}
});
});
// Empty the honeypot fields in JS in case something like an extension
// automatically filled them.
delegate(document, '#registration_new_user,#new_user', 'submit', () => {
// Empty the honeypot fields in JS in case something like an extension
// automatically filled them.
delegate(document, '#registration_new_user,#new_user', 'submit', () => {
['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => {
const field = document.getElementById(id);
if (field) {
field.value = '';
}
});
});
}
});
function main() {
ready(loaded);