This commit is contained in:
@@ -726,15 +726,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
document.addEventListener('pkt:open-consent', openConsentModal);
|
||||
|
||||
const avatarPreviewClassPrefixes = [
|
||||
'pkt-avatar--head-',
|
||||
'pkt-avatar--hair-',
|
||||
'pkt-avatar--beard-',
|
||||
'pkt-avatar--glasses-',
|
||||
'pkt-avatar--hat-',
|
||||
'pkt-avatar--outfit-',
|
||||
];
|
||||
|
||||
const updateAvatarPreview = (form) => {
|
||||
const preview = form.querySelector('[data-avatar-preview] .pkt-avatar');
|
||||
if (!preview) return;
|
||||
@@ -745,28 +736,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const input = form.querySelector(`[data-avatar-field="${field}"]`);
|
||||
return input ? input.value : '';
|
||||
};
|
||||
const readColor = (field) => {
|
||||
const checked = form.querySelector(`[data-avatar-field="${field}"]:checked`);
|
||||
return checked ? checked.getAttribute('data-avatar-color') || '' : '';
|
||||
};
|
||||
const image = preview.querySelector('.pkt-avatar__img');
|
||||
if (!image) return;
|
||||
|
||||
avatarPreviewClassPrefixes.forEach((prefix) => {
|
||||
Array.from(preview.classList)
|
||||
.filter((className) => className.startsWith(prefix))
|
||||
.forEach((className) => preview.classList.remove(className));
|
||||
});
|
||||
const preset = readValue('avatar_preset');
|
||||
if (!preset) return;
|
||||
|
||||
preview.classList.add(`pkt-avatar--head-${readValue('avatar_head_shape')}`);
|
||||
preview.classList.add(`pkt-avatar--hair-${readValue('avatar_hair_style')}`);
|
||||
preview.classList.add(`pkt-avatar--beard-${readValue('avatar_beard_style')}`);
|
||||
preview.classList.add(`pkt-avatar--glasses-${readValue('avatar_glasses_style')}`);
|
||||
preview.classList.add(`pkt-avatar--hat-${readValue('avatar_hat_style')}`);
|
||||
preview.classList.add(`pkt-avatar--outfit-${readValue('avatar_outfit_style')}`);
|
||||
preview.style.setProperty('--avatar-skin', readColor('avatar_skin_tone'));
|
||||
preview.style.setProperty('--avatar-hair', readColor('avatar_hair_color'));
|
||||
preview.style.setProperty('--avatar-eye', readColor('avatar_eye_color'));
|
||||
preview.style.setProperty('--avatar-hat', readColor('avatar_hat_color'));
|
||||
preview.style.setProperty('--avatar-outfit', readColor('avatar_outfit_color'));
|
||||
image.src = `/assets/avatars/presets/${preset}.png`;
|
||||
};
|
||||
|
||||
document.querySelectorAll('[data-avatar-builder]').forEach((form) => {
|
||||
@@ -775,6 +751,37 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
field.addEventListener('change', () => updateAvatarPreview(form));
|
||||
field.addEventListener('input', () => updateAvatarPreview(form));
|
||||
});
|
||||
|
||||
const setActivePresetGroup = (groupKey) => {
|
||||
form.querySelectorAll('[data-avatar-preset-filter]').forEach((button) => {
|
||||
const active = button.getAttribute('data-avatar-preset-filter') === groupKey;
|
||||
button.classList.toggle('is-active', active);
|
||||
button.setAttribute('aria-selected', active ? 'true' : 'false');
|
||||
});
|
||||
form.querySelectorAll('[data-avatar-preset-group]').forEach((group) => {
|
||||
group.classList.toggle('is-active', group.getAttribute('data-avatar-preset-group') === groupKey);
|
||||
});
|
||||
};
|
||||
|
||||
const checkedPreset = form.querySelector('[data-avatar-field="avatar_preset"]:checked');
|
||||
if (checkedPreset) {
|
||||
const activeGroup = checkedPreset.closest('[data-avatar-preset-group]')?.getAttribute('data-avatar-preset-group');
|
||||
if (activeGroup) setActivePresetGroup(activeGroup);
|
||||
}
|
||||
|
||||
form.querySelectorAll('[data-avatar-preset-filter]').forEach((button) => {
|
||||
button.addEventListener('click', () => {
|
||||
const groupKey = button.getAttribute('data-avatar-preset-filter');
|
||||
if (groupKey) setActivePresetGroup(groupKey);
|
||||
});
|
||||
});
|
||||
|
||||
form.querySelectorAll('[data-avatar-field="avatar_preset"]').forEach((field) => {
|
||||
field.addEventListener('change', () => {
|
||||
const activeGroup = field.closest('[data-avatar-preset-group]')?.getAttribute('data-avatar-preset-group');
|
||||
if (activeGroup) setActivePresetGroup(activeGroup);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-nav-events]').forEach(link => {
|
||||
|
||||
Reference in New Issue
Block a user