zmiany w ux

This commit is contained in:
Mateusz Gruszczyński
2025-09-24 10:55:04 +02:00
parent 8b6fb41a68
commit 4515a1b391
6 changed files with 294 additions and 130 deletions

View File

@@ -1,38 +1,66 @@
(function () {
const ibanEl = document.getElementById('ibanDisplay');
// --- Formatowanie IBAN ---
const ibanEl = document.getElementById('ibanInput') || document.getElementById('ibanDisplay');
if (ibanEl) {
const digits = (ibanEl.textContent || '').replace(/\s+/g, '').replace(/^PL/i, '').replace(/\D/g, '').slice(0, 26);
if (digits) ibanEl.textContent = 'PL ' + digits.replace(/(.{4})/g, '$1 ').trim();
}
const blikEl = document.getElementById('blikDisplay');
if (blikEl) {
const d = (blikEl.textContent || '').replace(/\D/g, '').slice(0, 9);
const parts = [d.slice(0, 3), d.slice(3, 6), d.slice(6, 9)].filter(Boolean).join(' ');
if (parts) blikEl.textContent = parts;
const raw = (('value' in ibanEl ? ibanEl.value : ibanEl.textContent) || '')
.toString().replace(/\s+/g, '').toUpperCase();
const digits = raw.replace(/^PL/, '').replace(/\D/g, '').slice(0, 26);
if (digits) {
const pretty = 'PL ' + digits.replace(/(.{4})/g, '$1 ').trim();
if ('value' in ibanEl) ibanEl.value = pretty; else ibanEl.textContent = pretty;
}
}
document.querySelectorAll('[data-copy-target]').forEach(btn => {
// --- Formatowanie BLIK ---
const blikEl = document.getElementById('blikInput') || document.getElementById('blikDisplay');
if (blikEl) {
const raw = (('value' in blikEl ? blikEl.value : blikEl.textContent) || '')
.toString().replace(/\D/g, '').slice(0, 9);
if (raw) {
const pretty = [raw.slice(0, 3), raw.slice(3, 6), raw.slice(6, 9)]
.filter(Boolean).join(' ');
if ('value' in blikEl) blikEl.value = pretty; else blikEl.textContent = pretty;
}
}
// --- Kopiowanie: wspiera data-copy-input i data-copy-target ---
const buttons = document.querySelectorAll('[data-copy-input], [data-copy-target]');
buttons.forEach(btn => {
btn.addEventListener('click', async () => {
const sel = btn.getAttribute('data-copy-target');
const sel = btn.getAttribute('data-copy-input') || btn.getAttribute('data-copy-target');
const el = sel ? document.querySelector(sel) : null;
if (!el) return;
const raw = el.textContent.replace(/\u00A0/g, ' ').trim();
try {
await navigator.clipboard.writeText(raw);
const original = btn.textContent;
const textRaw = ('value' in el ? el.value : el.textContent || '')
.toString().replace(/\u00A0/g, ' ').trim();
const copyWithFallback = async (text) => {
try {
await navigator.clipboard.writeText(text);
return true;
} catch {
// Fallback: tymczasowy textarea
const ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.top = '-1000px';
ta.setAttribute('readonly', '');
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); } catch { /* ignore */ }
document.body.removeChild(ta);
return true;
}
};
const original = btn.textContent;
const ok = await copyWithFallback(textRaw);
if (ok) {
btn.textContent = 'Skopiowano!';
btn.disabled = true;
setTimeout(() => { btn.textContent = original; btn.disabled = false; }, 1200);
} catch {
// fallback
const r = document.createRange();
r.selectNodeContents(el);
const selObj = window.getSelection();
selObj.removeAllRanges();
selObj.addRange(r);
try { document.execCommand('copy'); } catch { }
selObj.removeAllRanges();
}
});
});
})();
})();