Donate form: custom-amount label, visible minimum, fee-cover info icon; hard 1.00 floor; purge abandoned checkouts; drop refund filters; soften personal-account wording
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a259c0b0a1
commit
e22675f54b
13 files changed
+177
-15
No files matched your search
@@ -11,3 +11,9 @@
|
||||
.sg-donate .sg-msg.sg-error{color:#b32d2e}
|
||||
.sg-donate .sg-msg.sg-ok{color:#1a7f37}
|
||||
.sg-donate .sg-buttons[data-disabled=true]{opacity:.45;pointer-events:none}
|
||||
.sg-donate label.sg-sub{font-weight:400;margin:.2rem 0 .25rem}
|
||||
.sg-donate .sg-hint{font-size:.85em;opacity:.75;margin-top:.25rem}
|
||||
.sg-donate .sg-cover{display:flex;align-items:center;gap:.5rem}
|
||||
.sg-donate .sg-info{flex:none;width:1.4rem;height:1.4rem;padding:0;border-radius:50%;border:1.5px solid currentColor;background:transparent;color:inherit;font:italic 700 .85rem/1 Georgia,serif;cursor:pointer;display:inline-flex;align-items:center;justify-content:center}
|
||||
.sg-donate .sg-info:focus-visible{outline:2px solid currentColor;outline-offset:2px}
|
||||
.sg-donate .sg-tip{margin-top:.4rem;padding:.6rem .75rem;border:1px solid rgba(128,128,128,.5);border-radius:.4rem;font-size:.9em;line-height:1.4}
|
||||
+27
-6
@@ -54,10 +54,12 @@
|
||||
try { return new Intl.NumberFormat(undefined, { style: 'currency', currency: cur }).format(v); }
|
||||
catch (e) { return v.toFixed(exp) + ' ' + cur; }
|
||||
}
|
||||
// Preset buttons, minus any below the minimum donation (values are whole currency units, or minor units for zero-decimal).
|
||||
function presets(exp) {
|
||||
var base = exp === 0 ? [500, 1000, 2500, 5000] : [5, 10, 25, 50];
|
||||
return base;
|
||||
return base.filter(function (p) { return (exp === 0 ? p : p * 100) >= (C.minMinor || 0); });
|
||||
}
|
||||
function sprintf1(tpl, v) { return String(tpl || '%s').replace('%s', v); }
|
||||
|
||||
function init(root) {
|
||||
var pinned = parseInt(root.getAttribute('data-goal'), 10) || 0;
|
||||
@@ -68,7 +70,8 @@
|
||||
|
||||
var goalSel = el('select', { id: uid + '-goal' });
|
||||
goals.forEach(function (g) { goalSel.appendChild(el('option', { value: g.id, text: g.title + ' (' + g.currency + ')' })); });
|
||||
var amount = el('input', { type: 'text', inputmode: 'decimal', id: uid + '-amt', autocomplete: 'off', 'aria-describedby': uid + '-total' });
|
||||
var amount = el('input', { type: 'text', inputmode: 'decimal', id: uid + '-amt', autocomplete: 'off', placeholder: T.customPlaceholder || 'Other amount', 'aria-describedby': uid + '-hint ' + uid + '-total' });
|
||||
var hint = el('div', { 'class': 'sg-hint', id: uid + '-hint' });
|
||||
var presetBox = el('div', { 'class': 'sg-presets' });
|
||||
var name = el('input', { type: 'text', id: uid + '-name', maxlength: '100', autocomplete: 'nickname' });
|
||||
var anon = el('input', { type: 'checkbox', id: uid + '-anon' });
|
||||
@@ -79,7 +82,7 @@
|
||||
var buttons = el('div', { 'class': 'sg-buttons' });
|
||||
|
||||
if (goals.length > 1) { root.appendChild(row([el('label', { 'for': uid + '-goal', text: T.goal }), goalSel])); }
|
||||
root.appendChild(row([el('label', { 'for': uid + '-amt', text: T.amount }), presetBox, amount]));
|
||||
root.appendChild(row([el('label', { text: T.amount }), presetBox, el('label', { 'class': 'sg-sub', 'for': uid + '-amt', text: T.customAmount || 'Or enter your own amount' }), amount, hint]));
|
||||
var nameRow = row([el('label', { 'for': uid + '-name', text: T.name }), name]);
|
||||
var anonRow = row([el('label', { 'class': 'sg-inline', 'for': uid + '-anon' }, [anon, document.createTextNode(T.anonymous)])]);
|
||||
if (C.policy === 'force_anonymous') { anon.checked = true; anon.disabled = true; nameRow.hidden = true; }
|
||||
@@ -87,7 +90,20 @@
|
||||
root.appendChild(nameRow);
|
||||
root.appendChild(anonRow);
|
||||
root.appendChild(row([el('label', { 'for': uid + '-msg', text: T.message }), msg]));
|
||||
root.appendChild(row([el('label', { 'class': 'sg-inline', 'for': uid + '-cover' }, [cover, document.createTextNode(T.coverFees)])]));
|
||||
var tip = el('div', { 'class': 'sg-tip', id: uid + '-tip', role: 'note', text: T.coverInfo || '' });
|
||||
tip.hidden = true;
|
||||
var info = el('button', { type: 'button', 'class': 'sg-info', 'aria-label': T.coverInfoLabel || 'What does this mean?', 'aria-expanded': 'false', 'aria-controls': uid + '-tip', text: 'i' });
|
||||
var pinnedOpen = false;
|
||||
function showTip(open) { tip.hidden = !open; info.setAttribute('aria-expanded', String(open)); }
|
||||
info.addEventListener('click', function () { pinnedOpen = tip.hidden; showTip(pinnedOpen); });
|
||||
info.addEventListener('mouseenter', function () { showTip(true); });
|
||||
info.addEventListener('mouseleave', function () { if (!pinnedOpen) { showTip(false); } });
|
||||
info.addEventListener('blur', function () { pinnedOpen = false; showTip(false); });
|
||||
info.addEventListener('keydown', function (e) { if (e.key === 'Escape') { pinnedOpen = false; showTip(false); } });
|
||||
root.appendChild(row([
|
||||
el('div', { 'class': 'sg-cover' }, [el('label', { 'class': 'sg-inline', 'for': uid + '-cover' }, [cover, document.createTextNode(T.coverFees)]), info]),
|
||||
tip
|
||||
]));
|
||||
root.appendChild(row([total]));
|
||||
root.appendChild(buttons);
|
||||
root.appendChild(status);
|
||||
@@ -99,6 +115,7 @@
|
||||
|
||||
function buildPresets() {
|
||||
presetBox.textContent = '';
|
||||
hint.textContent = sprintf1(T.minHint, fmt(C.minMinor || 0, state.goal.exp, state.goal.currency));
|
||||
presets(state.goal.exp).forEach(function (p) {
|
||||
var b = el('button', { type: 'button', 'aria-pressed': 'false', text: fmt(state.goal.exp === 0 ? p : p * 100, state.goal.exp, state.goal.currency) });
|
||||
b.addEventListener('click', function () { amount.value = String(p); refresh(); });
|
||||
@@ -119,7 +136,11 @@
|
||||
state.quote = null;
|
||||
buttons.setAttribute('data-disabled', 'true');
|
||||
clearTimeout(timer);
|
||||
if (!amountStr()) { total.textContent = ''; return; }
|
||||
if (!amountStr()) { total.textContent = ''; say(''); return; }
|
||||
var typed = parseFloat(amountStr());
|
||||
if (isFinite(typed) && Math.round(typed * Math.pow(10, state.goal.exp)) < (C.minMinor || 0)) {
|
||||
total.textContent = ''; say(sprintf1(T.belowMin, fmt(C.minMinor, state.goal.exp, state.goal.currency)), 'sg-error'); return;
|
||||
}
|
||||
var mine = ++seq;
|
||||
timer = setTimeout(function () {
|
||||
var qs = 'goal_id=' + state.goal.id + '&amount=' + encodeURIComponent(amountStr()) + '&cover_fees=' + (cover.checked ? '1' : '0');
|
||||
@@ -149,7 +170,7 @@
|
||||
if (token !== state.renderToken) { return; }
|
||||
paypal.Buttons({
|
||||
onClick: function (d, actions) {
|
||||
if (!state.quote || (C.policy === 'require_name' && !name.value.trim())) { say(T.fixForm, 'sg-error'); return actions.reject(); }
|
||||
if (!state.quote || (C.policy === 'require_name' && !name.value.trim())) { if (!status.textContent) { say(T.fixForm, 'sg-error'); } return actions.reject(); }
|
||||
say('');
|
||||
},
|
||||
createOrder: function () {
|
||||
|
||||
Reference in new issue
Block a user