initial commit

This commit is contained in:
2024-07-28 17:57:30 +02:00
commit ed6e7d72b1
12 changed files with 308 additions and 0 deletions

29
js/pride-settings.js Normal file
View File

@ -0,0 +1,29 @@
const folder_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.folder-flavour select');
const button_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.button-flavour select');
const submit_button = document.querySelectorAll('.pride_flags_user_settings .settings-pride-submit');
fetch('/index.php/apps/pride_flags/settings')
.then(res => JSON.parse(res))
.then(({folderPrideVariant, buttonPrideVariant}) => {
folder_selector.value = folderPrideVariant;
button_selector.value = buttonPrideVariant;
});
function save() {
const payload = {
folderVariant: folder_selector.value,
buttonVariant: button_selector.value,
}
fetch('index.php/apps/pride_flags/settings', {
method: 'POST',
body: JSON.stringify(payload),
headers: {
"Content-Type": "application/json",
}
}).then(response => {
if (response.ok) {
window.location.reload();
}
})
}
submit_button.on('click', e => save());

66
js/pride.js Normal file
View File

@ -0,0 +1,66 @@
const flags = [
{
id: 'pride',
colors: ['#E04641', '#DE7E41', '#E4D56F', '#55B85F', '#2473B5', '#6F5DA5'],
transform: 'rotate(90)'
}, {
id: 'trans',
colors: ['#55CDFC', '#F7A8B8', '#FFFFFF', '#F7A8B8', '#55CDFC'],
transform: 'rotate(90)'
}
];
const generateGradient = colors => {
const steps = colors.length;
return colors.map((color, index) => { return [
[color, (index / steps)],
[color, (index + 1) / steps]
]}).flat();
};
const generateStops = (colors, opacity) => {
return generateGradient(colors).map(([color, offset]) => {
return `<stop stop-color="${color}" stop-opacity="${opacity}" offset="${offset * 100}%"></stop>`;
});
};
const makeLinearGradientSvg = (id, colors, opacity, transform) => {
return `<svg xmlns="http://www.w3.org/2000/svg" id="svg-${id}" preserveAspectRatio="none" width="100%" height="100%">
<defs>
<linearGradient id="gradient-${id}" gradientTransform="${transform}">
${generateStops(colors, opacity).join('\n')}
</linearGradient>
</defs>
<style>
rect { height: 100%; width: 100%; }
</style>
<rect fill="url(#gradient-${id})" width="100%" height="100%" />
</svg>`;
};
flags.forEach(flag => {
const svg_html = makeLinearGradientSvg(flag.id, flag.colors, flag.opacity ?? '0.8', flag.transform ?? 'rotate(0)');
const container = document.createElement('div');
container.classList.add('hidden-visually');
container.ariaHidden = true;
container.innerHTML = svg_html;
const style_c = document.createElement('style');
style_c.textContent = `
body {
--image-background-pride-${flag.id}: url('data:image/svg+xml;base64,${btoa(svg_html)}');
}
#app-navigation ul > li.active,
.button-vue--vue-primary,
.preview-card__header,
.profile__primary-action-button,
.app-navigation-entry.active {
background-image: var(--image-background-pride-trans) !important;
}
.material-design-icon__svg,
.checkbox-radio-switch svg {
fill: url(#gradient-trans);
}
`;
document.body.prepend(container);
document.head.prepend(style_c);
});