HTML EDITOR
טקסט
קישורים ותמונות
אלמנטים ורכיבים
רשימות
טבלאות
טפסים ושדות קלט
לוח קוד HTML
תצוגה מקדימה אמיתית
`); } /* תגיות רגילות */ function insertTag(tag, selfClosing = false) { if (selfClosing) { addCode(`<${tag}>`); } else { addCode(`<${tag}> `); } } /* טקסט */ function insertText(tag) { currentAction = { type: "text", tag: tag }; showModal("הכנסת טקסט", [ {id: "text", placeholder: "הכנס טקסט"} ]); } /* קישור */ function insertLink() { currentAction = {type: "link"}; showModal("יצירת קישור", [ {id: "url", placeholder: "כתובת הקישור"}, {id: "text", placeholder: "טקסט הקישור"} ], true); } /* תמונה */ function insertImage() { currentAction = {type: "image"}; showModal("הוספת תמונה", [ {id: "url", placeholder: "כתובת התמונה"}, {id: "alt", placeholder: "תיאור התמונה"} ]); } /* וידאו */ function insertVideo() { currentAction = {type: "video"}; showModal("הוספת סרטון", [ {id: "url", placeholder: "כתובת הסרטון"} ]); } /* אודיו */ function insertAudio() { currentAction = {type: "audio"}; showModal("הוספת אודיו", [ {id: "url", placeholder: "כתובת קובץ האודיו"} ]); } /* שדות קלט */ function insertInput(type) { addCode(``); } /* חלונית קלט */ function showModal(title, fields, target = false) { document.getElementById("modalTitle").textContent = title; const container = document.getElementById("modalFields"); container.innerHTML = ""; fields.forEach(field => { const input = document.createElement("input"); input.id = "field_" + field.id; input.type = "text"; input.placeholder = field.placeholder; container.appendChild(input); }); if (target) { const label = document.createElement("label"); label.innerHTML = ` פתיחה בלשונית חדשה `; container.appendChild(label); } document.getElementById("modal").style.display = "flex"; } /* אישור */ function confirmModal() { if (!currentAction) return; let code = ""; const get = id => { return document.getElementById("field_" + id)?.value || ""; }; if (currentAction.type === "text") { const tag = currentAction.tag; code = `<${tag}>${escapeHTML(get("text"))}`; } if (currentAction.type === "link") { const url = escapeHTML(get("url")); const text = escapeHTML(get("text")); const newTab = document.getElementById("newTab").checked; code = `${text}`; } if (currentAction.type === "image") { code = `${escapeHTML(get(`; } if (currentAction.type === "video") { code = ``; } if (currentAction.type === "audio") { code = ``; } addCode(code); closeModal(); } /* סגירת חלונית */ function closeModal() { document.getElementById("modal").style.display = "none"; currentAction = null; } /* הגנה על טקסט */ function escapeHTML(text) { return text.replace(/[&<>"']/g, char => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]); } /* ניקוי */ function clearEditor() { if (confirm("האם למחוק את כל הקוד?")) { editor.value = ""; updatePreview(); } } /* הורדה */ function downloadHTML() { const blob = new Blob( [editor.value], {type: "text/html;charset=utf-8"} ); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "my-website.html"; link.click(); URL.revokeObjectURL(url); } /* תצוגה ראשונית */ updatePreview();