[file the-file filetypes:pdf|doc|docx|txt class:file-input]
ה-JS מזריק את ה-UI אוטומטית לתוך ה-wpcf7-form-control-wrap שCF7 מייצר.
.upload-container { position: relative; z-index: 1; display: inline-block; } .upload-btn-wrap { background-color: rgba(255, 255, 255, 0.03); display: inline-flex; width: 300px; max-width: 100%; align-items: center; gap: 12px; padding: 12px 24px; border: 2px dashed rgba(255, 255, 255, 0.15); border-radius: 12px; cursor: pointer; transition: all 0.3s ease; backdrop-filter: blur(8px); position: relative; z-index: 6; pointer-events: none; } .file-input:hover ~ .upload-btn-wrap, .upload-btn-wrap:hover { border-color: #71F494; background-color: rgba(255, 255, 255, 0.06); } .upload-btn-wrap.active { border-style: solid; border-color: #71F494; background-color: rgba(113, 244, 148, 0.1); box-shadow: 0 0 15px rgba(113, 244, 148, 0.15); } .wpcf7-not-valid .upload-btn-wrap, .upload-btn-wrap.error { border-color: #ef4444; background-color: rgba(239, 68, 68, 0.1); } .file-input-val-text { font-size: 15px; color: #f8fafc; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .upload-icon { width: 20px; height: 20px; flex-shrink: 0; stroke: #94a3b8; transition: stroke 0.3s ease; } .file-input:hover ~ .upload-btn-wrap .upload-icon path, .upload-btn-wrap:hover .upload-icon path, .upload-btn-wrap.active .upload-icon path { stroke: #71F494; } .delete-file { display: inline-flex; background: rgba(239, 68, 68, 0.15); color: #ef4444; border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 18px; line-height: 1; cursor: pointer; align-items: center; justify-content: center; margin-right: auto; position: relative; z-index: 10; transition: all 0.2s; pointer-events: auto; } .delete-file:hover { background: #ef4444; color: #fff; } .upload-container:not(.active) .delete-file { display: none; } .file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; z-index: 5; } .file-input:focus-visible + .upload-btn-wrap { outline: 2px solid #71F494; } .error-tip { color: #ef4444; font-size: 13px; margin-top: 8px; display: block; }
// Upload File (() => { const DEFAULT_TEXT = 'בחר קובץ להעלאה...'; const UPLOAD_SVG = '<svg class="upload-icon" width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 16V2M12 2L15 5M12 2L9 5M20 16V18C20 19.1046 19.1046 20 18 20H6C4.89543 20 4 19.1046 4 18V16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>'; // CF7 מוציא רק את ה-input — מזריק את ה-UI הנדרש ומוסיף upload-container לעטיפה function buildUploadUI(fileInput) { const wrap = fileInput.parentElement; if (!wrap || wrap.querySelector('.upload-btn-wrap')) return; wrap.classList.add('upload-container'); const btnWrap = document.createElement('span'); btnWrap.className = 'upload-btn-wrap'; btnWrap.innerHTML = UPLOAD_SVG + '<span class="file-input-val-text" data-default-text="' + DEFAULT_TEXT + '">' + DEFAULT_TEXT + '</span>' + '<button type="button" class="delete-file" title="מחק קובץ">×</button>'; fileInput.after(btnWrap); } function resetUploadUI(wrapper) { const fileInput = wrapper.querySelector('.file-input'); const textDisplay = wrapper.querySelector('.file-input-val-text'); if (!textDisplay) return; if (fileInput) fileInput.value = ''; textDisplay.textContent = textDisplay.getAttribute('data-default-text'); wrapper.classList.remove('active', 'error'); } function initUploadWrapper(wrapper) { const fileInput = wrapper.querySelector('.file-input'); const textDisplay = wrapper.querySelector('.file-input-val-text'); const deleteBtn = wrapper.querySelector('.delete-file'); if (!fileInput || !textDisplay || !deleteBtn) return; fileInput.addEventListener('change', (e) => { if (e.target.files[0]) { textDisplay.textContent = e.target.files[0].name; wrapper.classList.add('active'); wrapper.classList.remove('error'); } else { resetUploadUI(wrapper); } }); deleteBtn.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); resetUploadUI(wrapper); }); } // CF7 inputs: בונה UI ואז מאתחל document.querySelectorAll('.wpcf7-file').forEach(fileInput => { buildUploadUI(fileInput); }); // כל העטיפות (CF7 + שימוש רגיל) document.querySelectorAll('.upload-container').forEach(wrapper => { initUploadWrapper(wrapper); }); // איפוס אחרי שליחת CF7 מוצלחת document.addEventListener('wpcf7mailsent', () => { document.querySelectorAll('.upload-container').forEach(resetUploadUI); }, false); })();