document.addEventListener('click',function(e){const a=e.target.closest('[data-confirm]');if(a&&!confirm(a.dataset.confirm||'Jeste li sigurni?'))e.preventDefault();}); document.addEventListener('DOMContentLoaded',function(){ document.querySelectorAll('textarea.wysiwyg').forEach(function(textarea, index){ textarea.style.display='none'; const toolbar=document.createElement('div'); toolbar.className='editor-toolbar'; const editor=document.createElement('div'); editor.className='rich-editor'; editor.contentEditable='true'; editor.innerHTML=textarea.value || ''; const buttons=[['bold','B'],['italic','I'],['underline','U'],['insertUnorderedList','Lista'],['insertOrderedList','Brojevi'],['formatBlock','H2','
'],['createLink','Link']]; buttons.forEach(function(b){const btn=document.createElement('button');btn.type='button';btn.textContent=b[1];btn.addEventListener('click',function(){ if(b[0]==='createLink'){const url=prompt('Unesi link:','https://'); if(url) document.execCommand('createLink',false,url);} else {document.execCommand(b[0],false,b[2]||null);} editor.focus(); textarea.value=editor.innerHTML;}); toolbar.appendChild(btn);}); textarea.parentNode.insertBefore(toolbar, textarea.nextSibling); textarea.parentNode.insertBefore(editor, toolbar.nextSibling); const sync=()=>textarea.value=editor.innerHTML; editor.addEventListener('input',sync); textarea.form&&textarea.form.addEventListener('submit',sync); }); }); document.addEventListener('change', function(e){ const input = e.target; if(input && input.matches('input[type="file"][data-preview]') && input.files && input.files[0]){ const img = document.getElementById(input.dataset.preview); if(img){ img.src = URL.createObjectURL(input.files[0]); img.style.display = 'block'; } } }); document.addEventListener('change', function(e){ const radio = e.target; if(radio && radio.matches('.upload-item input[type="radio"]')){ document.querySelectorAll('input[name="'+radio.name+'"]').forEach(function(r){ r.closest('.upload-item')?.classList.remove('selected'); }); radio.closest('.upload-item')?.classList.add('selected'); } });