Release v2.0: URL upload, BBCode sharing, QR codes
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+108
-13
@@ -1,10 +1,31 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initUploadForm();
|
||||
initCopyButtons();
|
||||
initShareModal();
|
||||
});
|
||||
|
||||
function initUploadForm() {
|
||||
const dropzone = document.getElementById("dropzone");
|
||||
const photoInput = document.getElementById("photoInput");
|
||||
const preview = document.getElementById("preview");
|
||||
const previewImg = document.getElementById("previewImg");
|
||||
const previewName = document.getElementById("previewName");
|
||||
const submitBtn = document.getElementById("submitBtn");
|
||||
const uploadForm = document.getElementById("uploadForm");
|
||||
const tabButtons = document.querySelectorAll(".upload-tabs__btn");
|
||||
const panels = document.querySelectorAll(".upload-panel");
|
||||
|
||||
if (!uploadForm) return;
|
||||
|
||||
tabButtons.forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const tab = btn.dataset.tab;
|
||||
tabButtons.forEach((item) => item.classList.toggle("upload-tabs__btn--active", item === btn));
|
||||
panels.forEach((panel) => {
|
||||
panel.classList.toggle("upload-panel--active", panel.dataset.panel === tab);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (!dropzone || !photoInput) return;
|
||||
|
||||
@@ -40,6 +61,25 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
}
|
||||
});
|
||||
|
||||
uploadForm.addEventListener("submit", (e) => {
|
||||
const activePanel = document.querySelector(".upload-panel--active");
|
||||
if (!activePanel) return;
|
||||
|
||||
if (activePanel.dataset.panel === "urls") {
|
||||
const urls = document.getElementById("imageUrls");
|
||||
if (!urls || !urls.value.trim()) {
|
||||
e.preventDefault();
|
||||
showToast("Укажите хотя бы одну ссылку");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (activePanel.dataset.panel === "files" && photoInput.files.length === 0) {
|
||||
e.preventDefault();
|
||||
showToast("Выберите файлы для загрузки");
|
||||
}
|
||||
});
|
||||
|
||||
function assignFiles(fileList) {
|
||||
const dt = new DataTransfer();
|
||||
const limit = Math.min(fileList.length, maxFiles);
|
||||
@@ -68,26 +108,81 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
};
|
||||
reader.readAsDataURL(first);
|
||||
}
|
||||
}
|
||||
|
||||
function initCopyButtons() {
|
||||
document.querySelectorAll(".copy-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
const url = btn.dataset.url;
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
showToast("Ссылка скопирована!");
|
||||
} catch {
|
||||
const input = document.createElement("input");
|
||||
input.value = url;
|
||||
document.body.appendChild(input);
|
||||
input.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
showToast("Ссылка скопирована!");
|
||||
const targetId = btn.dataset.target;
|
||||
const url = targetId
|
||||
? document.getElementById(targetId)?.value
|
||||
: btn.dataset.url;
|
||||
|
||||
if (!url) return;
|
||||
|
||||
const copied = await copyText(url);
|
||||
if (copied) {
|
||||
const label = btn.textContent.trim();
|
||||
showToast(label === "BBCode" ? "BBCode скопирован!" : "Скопировано!");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initShareModal() {
|
||||
const modal = document.getElementById("shareModal");
|
||||
if (!modal) return;
|
||||
|
||||
const urlInput = document.getElementById("shareModalUrl");
|
||||
const bbcodeInput = document.getElementById("shareModalBbcode");
|
||||
const htmlInput = document.getElementById("shareModalHtml");
|
||||
const qrImg = document.getElementById("shareModalQr");
|
||||
const nameEl = document.getElementById("shareModalName");
|
||||
|
||||
document.querySelectorAll(".share-qr-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
urlInput.value = btn.dataset.url || "";
|
||||
bbcodeInput.value = btn.dataset.bbcode || "";
|
||||
htmlInput.value = btn.dataset.html || "";
|
||||
qrImg.src = btn.dataset.qr || "";
|
||||
nameEl.textContent = btn.dataset.name || "";
|
||||
modal.hidden = false;
|
||||
document.body.classList.add("modal-open");
|
||||
});
|
||||
});
|
||||
|
||||
modal.querySelectorAll("[data-close-share]").forEach((el) => {
|
||||
el.addEventListener("click", closeShareModal);
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape" && !modal.hidden) {
|
||||
closeShareModal();
|
||||
}
|
||||
});
|
||||
|
||||
function closeShareModal() {
|
||||
modal.hidden = true;
|
||||
document.body.classList.remove("modal-open");
|
||||
}
|
||||
}
|
||||
|
||||
async function copyText(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
const input = document.createElement("input");
|
||||
input.value = text;
|
||||
document.body.appendChild(input);
|
||||
input.select();
|
||||
const ok = document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(message) {
|
||||
const existing = document.querySelector(".toast");
|
||||
|
||||
Reference in New Issue
Block a user