Update editor.js
This commit is contained in:
+12
-11
@@ -1,16 +1,13 @@
|
||||
console.log("Die JavaScript-Datei wurde erfolgreich geladen!");
|
||||
/**
|
||||
* Editor-Steuerung für dynamische Inhaltsblöcke
|
||||
*/
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
function initEditor() {
|
||||
const form = document.getElementById("editor-form");
|
||||
|
||||
// Falls das Formular auf der aktuellen Seite nicht existiert, Skript abbrechen
|
||||
if (!form) {
|
||||
console.error("Skript abgebrochen: Formular nicht gefunden!");
|
||||
return;
|
||||
} else {
|
||||
console.log("Formular gefunden:", form);
|
||||
console.log("Formular gefunden und Editor initialisiert:", form);
|
||||
}
|
||||
|
||||
const container = document.getElementById("block-container");
|
||||
@@ -63,7 +60,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
imgPreview.style.display = "block";
|
||||
imgPreview.style.marginTop = "10px";
|
||||
|
||||
// Falls bereits ein Bildpfad existiert (z.B. nach einem Reload bei Validierungsfehlern)
|
||||
if (value && typeof value === 'string' && value.startsWith('uploads/')) {
|
||||
imgPreview.src = value;
|
||||
blockDiv.setAttribute("data-value", value);
|
||||
@@ -74,7 +70,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
imgPreview.src = e.target.result;
|
||||
// Temporäre Speicherung des Base64-Strings im HTML-Attribut
|
||||
blockDiv.setAttribute("data-value", e.target.result);
|
||||
}
|
||||
reader.readAsDataURL(this.files[0]);
|
||||
@@ -104,7 +99,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
blocks.push({ type: type, value: value });
|
||||
});
|
||||
|
||||
// JSON-Daten in das unsichtbare Formularfeld schreiben
|
||||
hiddenContentInput.value = JSON.stringify(blocks);
|
||||
});
|
||||
|
||||
@@ -115,9 +109,16 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
initialBlocks.forEach(b => addBlockElement(b.type, b.value));
|
||||
}
|
||||
} catch(e) {
|
||||
// Fallback für alten Reintext aus Altbeständen
|
||||
if (hiddenContentInput.value.trim() !== "") {
|
||||
addBlockElement("text", hiddenContentInput.value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// SICHERER START: Prüft, ob das HTML bereits bereit ist
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", initEditor);
|
||||
} else {
|
||||
// Falls das DOM schon fertig geladen ist, führen wir es direkt aus
|
||||
initEditor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user