Site Builder
Editing:
profile-dynamic.js
writable 0666
/* * Dynamic Profile – tag chips & add‑field * v2.0 (2025‑07‑13) * • CSV fallback when hidden value isn’t valid JSON * • Duplicate‑tag guard */ (() => { document.addEventListener('DOMContentLoaded', () => { const btn = document.getElementById('manage-social-links-btn'); const container = document.getElementById('social-links-container'); if (btn && container) { btn.addEventListener('click', () => { const showing = container.style.display === 'block'; container.style.display = showing ? 'none' : 'block'; btn.textContent = showing ? 'Manage Social Links' : 'Hide Social Links'; }); } }); /* ---------- TAG‑BOX BOOTSTRAP ---------- */ document.querySelectorAll('.bdo-tagbox').forEach(box => { /* hidden input = single source of truth */ const hidden = box.querySelector('input[type=hidden]'); /* normal = JSON array ; fallback = comma list */ let tags; try { tags = JSON.parse(hidden.value || '[]'); if (!Array.isArray(tags)) throw 'not array'; } catch { tags = hidden.value.split(/\s*,\s*/).filter(Boolean); hidden.value = JSON.stringify(tags); // normalise for next save } /* ------- render function ------- */ const input = document.createElement('input'); input.type = 'text'; input.placeholder = 'type & hit Enter'; const render = () => { box.querySelectorAll('.bdo-chip').forEach(e => e.remove()); tags.forEach(t => { const chip = document.createElement('span'); chip.className = 'bdo-chip'; chip.textContent = t + ' '; const btn = document.createElement('button'); btn.textContent = '✖'; btn.onclick = () => { tags = tags.filter(x => x !== t); hidden.value = JSON.stringify(tags); render(); }; chip.appendChild(btn); box.insertBefore(chip, input); }); }; /* ------- input handler ------- */ input.onkeydown = e => { if (e.key === 'Enter') { e.preventDefault(); const v = input.value.trim(); if (v && !tags.includes(v)) { tags.push(v); hidden.value = JSON.stringify(tags); render(); } input.value = ''; } }; box.appendChild(input); render(); }); /* ---------- “Add new field” helper ---------- */ document.getElementById('bdo-add-field')?.addEventListener('click', () => { const fld = prompt('New field name (letters, numbers, underscores):'); if (!fld || !/^[A-Za-z0-9_]+$/.test(fld)) return; const tbl = document.getElementById('bdo-prof-table'); if (tbl.querySelector(`tr[data-key="${fld}"]`)) { alert('Field exists already'); return; } const tr = document.createElement('tr'); tr.dataset.key = fld; tr.innerHTML = `<th>${fld}</th><td><input class="regular-text" name="${fld}"></td>`; tbl.appendChild(tr); }); })();
Save changes
Create folder
writable 0777
Create
Cancel