feat(groups): вставка фото из буфера обмена в модалке фото
This commit is contained in:
@@ -537,6 +537,35 @@ function previewPhotoFile() {
|
|||||||
prev.style.display = 'block';
|
prev.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pasteGroupPhotoFile(e) {
|
||||||
|
const modal = document.getElementById('photoFormModal');
|
||||||
|
if (!modal || !modal.classList.contains('open')) return;
|
||||||
|
if (editingPhotoId) return;
|
||||||
|
const active = document.activeElement;
|
||||||
|
if (active && active.id === 'photoCaption') return;
|
||||||
|
const items = e.clipboardData && e.clipboardData.items;
|
||||||
|
if (!items) return;
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.type && item.type.startsWith('image/')) {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
if (!file) continue;
|
||||||
|
e.preventDefault();
|
||||||
|
let named = file;
|
||||||
|
if (!/\.[a-z0-9]{2,5}$/i.test(file.name || '')) {
|
||||||
|
const m = /^image\/([a-z0-9.+-]+)$/i.exec(file.type || '');
|
||||||
|
let ext = m ? m[1].toLowerCase() : 'png';
|
||||||
|
if (ext === 'jpeg') ext = 'jpg';
|
||||||
|
named = new File([file], `photo-${Date.now()}.${ext}`, { type: file.type || 'image/png', lastModified: file.lastModified });
|
||||||
|
}
|
||||||
|
const dt = new DataTransfer();
|
||||||
|
dt.items.add(named);
|
||||||
|
document.getElementById('photoFile').files = dt.files;
|
||||||
|
previewPhotoFile();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function savePhotoForm() {
|
async function savePhotoForm() {
|
||||||
const caption = document.getElementById('photoCaption').value.trim();
|
const caption = document.getElementById('photoCaption').value.trim();
|
||||||
const taken_at = document.getElementById('photoTakenAt').value;
|
const taken_at = document.getElementById('photoTakenAt').value;
|
||||||
@@ -710,6 +739,7 @@ async function downloadGroupFiles() {
|
|||||||
document.getElementById('newGroup').addEventListener('keydown', e => { if (e.key === 'Enter') addGroup(); });
|
document.getElementById('newGroup').addEventListener('keydown', e => { if (e.key === 'Enter') addGroup(); });
|
||||||
document.getElementById('addGroupBtn').addEventListener('click', addGroup);
|
document.getElementById('addGroupBtn').addEventListener('click', addGroup);
|
||||||
document.getElementById('photoFile').addEventListener('change', previewPhotoFile);
|
document.getElementById('photoFile').addEventListener('change', previewPhotoFile);
|
||||||
|
document.addEventListener('paste', pasteGroupPhotoFile);
|
||||||
document.getElementById('photoForm').addEventListener('submit', e => {
|
document.getElementById('photoForm').addEventListener('submit', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
savePhotoForm();
|
savePhotoForm();
|
||||||
|
|||||||
Reference in New Issue
Block a user