// editor scripts var addingBjouAfterClosingEditor = false; // this flag holds the action for adding a bijou title, after closing the editor. this is necc. because the bijou title must have the same html and vorlagenbreite like the parent title // set global hashtable (hold template values) var templateTable; // create hashtables if page is ready! $(document).ready(function () { templateTable = new Hashtable(); }); // open editor var t_editorTitelID; var t_currentAcc; var t_templateDiv; var tt_accTab; // holds current accordion tab obj var realWidth; var t_templateText; function OpenEditor(institelid, silentAction) { // show overlay, preventig unhandled user actions while editor is opening ShowOverlay(); // first fill up hashtable with inserat values in table t_editorTitelID = institelid; $.get("../ajax/json.aspx?action=GetEditorDatas&id=" + institelid, function (jsonObj) { jsonObj = CreateJSONObject(jsonObj); $(jsonObj.aaDataFields).map(function () { // check if key exist if (!templateTable.containsKey(this.fTextelement)) { // insert with correct value templateTable.put(this.fTextelement, this.fText); } else { // replace with correct value templateTable.remove(this.fTextelement); templateTable.put(this.fTextelement, this.fText); } }); $.get("../ajax/json.aspx?action=GetTemplateFromUrl", { templateUrl: jsonObj.fVorlageUrl }, function (templateObj) { templateObj = CreateJSONObject(templateObj); // detroy accordion $("#dvTemplateItems").accordion('destroy'); $("#dvTemplateItems").html(""); // destroy ck editors for (instance in CKEDITOR.instances) { try { if (instance != "HiddenEditor" && instance != "textareaSammelInserat") { CKEDITOR.instances[instance].destroy(true); } } catch (ex) { // invalid ckeditor instance } } // add html $("#dvMainTemplate").html($(templateObj.Template).filter('#container').clone().wrap('
').parent().html()); // calc template width realWidth = Number($(templateObj.Template).filter('#container').width()); // now get every id element $('#dvMainTemplate #container div').each(function (index) { if ($(this).attr('id') != "" && $(this).attr('id') != "undefined" && $(this).attr('id') != null) { if ($(this).attr('class') != null) { $("#dvTemplateItems").append('

' + $(this).attr('title') + '

'); // check template hashtable and put key if (!templateTable.containsKey($(this).attr('id'))) { templateTable.put($(this).attr('id'), encodeURIComponent($(this).val().replace(/\+/g, 'THISISAPLUSSIGN'))); } else { } // append img upload or editor tab if ($(this).attr('class') == "bildupload") { // create bildupload //alert($(this).html()); //alert(templateTable.get($(this).attr('id'))); var imgUrl; var imgWidth; var imgHeight; var hasBildUpload = false; $("#DV_HiddenImgUpload").html(decodeURIComponent(templateTable.get($(this).attr('id'))).replace(/THISISAPLUSSIGN/g, '+')); $('#DV_HiddenImgUpload img').each(function (index) { imgUrl = $(this).attr('src'); imgWidth = $(this).width(); imgHeight = $(this).height(); hasBildUpload = true; }); // append tab if (hasBildUpload) { $("#dvTemplateItems").append('





Bild komplett aus Inseratevorlage entfernen - dies kann nicht mehr rückgängig gemacht werden.' + '

'); } else { $("#dvTemplateItems").append('

Bild wurde gelöscht

'); } } else { // prepare for ckeditor // check for vorschlagstexte var textvorschlagAvailable = false; var dividintemplate = $(this).attr('id').toLowerCase(); var selecthmtl = "

"; if (!textvorschlagAvailable) { // overwrite dropdown with empty selecthmtl = ""; } // add now element //alert(decodeURIComponent(templateTable.get($(this).attr('id'))).replace(/THISISAPLUSSIGN/g, '+')); $("#dvTemplateItems").append('

' + selecthmtl + '' + '

'); // always put text tem t_templateText += templateTable.get($(this).attr('id')) + "#breakPlaceholder# "; } // set template text $(this).html(decodeURIComponent(templateTable.get($(this).attr('id'))).replace(/THISISAPLUSSIGN/g, '+')); } } }); // check / set preview font class for (i = 0; i < templateTable.size(); i++) { // check now if it's empty div element //$('#dvMainTemplate #container #' + templateTable.keys()[i]).css("font-family", "Impact"); } // add accordion $("#dvTemplateItems").accordion({ collapsible: true, active: false, autoHeight: false, navigation: false }); $('#dvTemplateItems').bind('accordionchangestart', function (event, ui) { // remove div visualizer, update temp acctab obj and create ediotr for (i = 0; i < templateTable.size(); i++) { $('#dvMainTemplate #container #' + templateTable.keys()[i]).removeClass("DivVisualiszerActive"); } tt_accTab = ui.newContent; createEditor(ui.newContent); }); // now hashtable is ready, so open editor, if it's not a silent action if (!silentAction) { $("#dialog_Editor").dialog("option", "width", 900); $("#dialog_Editor").dialog("option", "height", 600); $("#dialog_Editor").dialog("open"); $("#dialog_Editor").bind("dialogbeforeclose", function (event, ui) { closeEditor(); }); } else { // its a slient action, so just "close" editor. means: call close actions closeEditor(); } // close overlay if (!silentAction) { HideOverlay(); ReloadImgPreview(); } // and tooltip $(".tooltip").tipTip(); }); }); } // create editor in tab function createEditor(uicontentobj) { try { // set main ids var currentEditorID = $(uicontentobj).find('textarea').attr('id'); var curentTemplateDiv = currentEditorID.split('_')[1]; var currentEditorDivID = "dv_" + currentEditorID; // create toolbar var theClass = $('#dvMainTemplate #container #' + curentTemplateDiv).attr('class'); if (theClass != null && theClass != "") { if (theClass == "bildupload") { // img upload } else { // editor --> create fck editor with toolbar from classes var toolbar = "[[" // always add undo toolbar += "'Undo','Redo', "; //toolbar += "'Source', "; if (t_testauftrag) { // always add source function toolbar += "'Source', "; } $.each($('#dvMainTemplate #container #' + curentTemplateDiv).attr('class').split(' '), function (index, value) { switch (value) { case "bold": toolbar += "'Bold', "; break; case "italic": toolbar += "'Italic', "; break; case "underline": toolbar += "'Underline', "; break; case "font": toolbar += "'Font', "; break; case "size": toolbar += "'FontSize', "; break; case "list": toolbar += "'BulletedList', "; break; case "numlist": toolbar += "'NumberedList', "; break; case "indent": toolbar += "'Indent', "; break; case "outdent": toolbar += "'Outdent', "; break; case "char": toolbar += "'SpecialChar', "; break; case "bg": toolbar += "'BGColor', "; break; case "color": toolbar += "'TextColor', "; break; case "upper": toolbar += "'Subscript', "; break; case "lower": toolbar += "'Superscript', "; break; default: toolbar += "'" + value + "', "; break; } }); if (toolbar.length > 2) { toolbar = toolbar.substring(0, toolbar.length - 2); } toolbar += "]]"; // create config var config = { height: 200, width: 350, toolbar: eval(toolbar), allowedContent: true, // disable filtering html and css tags! forcePasteAsPlainText: true }; // create editor $(uicontentobj).find('textarea').ckeditor(config); // add events CKEDITOR.instances[currentEditorID].on("instanceReady", function () { this.document.on("keyup", function (event) { // update value in template updateEditor(uicontentobj, curentTemplateDiv); recognizeInputBreak(); }); this.document.on("click", function (event) { // update value in template updateEditor(uicontentobj, curentTemplateDiv); }); this.document.on("change", function (event) { // update value in template updateEditor(uicontentobj, curentTemplateDiv); recognizeInputBreak(); }); // hide editor, if its a only imageselect if (theClass == "imageselect") { // hide no possible at the time } }) } } else { // create nothing } } catch (ex) { //alert("fehler " + ex + ". current edito id: " + currentEditorID); } } // close editor function closeEditor() { ShowOverlay(); // save editor fields var insdata = ""; // save fields in datatable for (i = 0; i < templateTable.size(); i++) { insdata += templateTable.keys()[i] + "|" + escape(templateTable.get(templateTable.keys()[i])) + "¦"; } var data = { id: t_editorTitelID, action: "saveEditorField", VorlagenBreite: realWidth, insdata: insdata }; $.post("../ajax/rest.aspx", data, function (jsonObj) { if (jsonObj == "true") { // copy html to temp render (do not make changes in dvmaintemplate div!) and set to temp var $('#DV_HiddenEditor_TempRender').html($('#dvMainTemplate').html()); // hide divs with no content and set template text t_templateText = ""; for (i = 0; i < templateTable.size(); i++) { // check now if it's empty div element if ($('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).html() == "") { // hide $('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).css("display", "none"); } // set template text t_templateText += $('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).html() + "#breakPlaceholder# "; // check4update sujet try { if ($('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).attr('class').indexOf("sujet") >= 0) { // update sujet $.get("../ajax/rest.aspx?action=changeSujet&id=" + t_editorTitelID, { sujet: $('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).html() }, function (restObj) { }); } } catch (ex) { // no class defined } } // set template html var to hidden ck editor (preventing special chars errors) var vhtml = $('#DV_HiddenEditor_TempRender').html(); $('#HiddenEditor').val(vhtml); // save html with timeout, the timeout is used for give browser time to encode hiddenditor datas correct setTimeout(function () { vhtml = $('#HiddenEditor').val(); // replace the "+" sign, beacuse javascript doesn't escape this sign.. vhtml = vhtml.replace(/\+/g, 'THISISAPLUSSIGN'); var data = { fInseratTitelID: t_editorTitelID, action: "createVorlagenHTML", VorlagenBreite: realWidth, vhtml: escape(vhtml), t_templateText: t_templateText }; $.post("../ajax/rest.aspx", data, function (jsonObj) { // finally, check 4 add a bijou title ShowOverlay(); if (addingBjouAfterClosingEditor) { addingBjouAfterClosingEditor = false; __SetTitel2Inserat(ttt_title, ttt_titlebez, ttt_KVariante, true, ttt_bijouSprachcode, true, ttt_fInseratTitelID, false); } else if (t_homegateFakeProgress) { // go back to object ShowPage("objektverwaltung.aspx", false); } else { // just relaod the auftragsmappe ReloadAuftragsmappe(false); $("#dialog_Editor").unbind("dialogbeforeclose"); } }); }, 500); } else { // error alert("Fehler beim Speichern / Laden. Der Text wurde nicht gespeichert. Bitte untenstehende Meldung an Support weiterleiten und anschliessend die Seite neu laden:\n\n" + jsonObj); } }); } function TestEditor() { // test editor function for direct pdf vhtml = $('#HiddenEditor').val(); var data = { fInseratTitelID: t_editorTitelID, action: "createVorlagenHTML", VorlagenBreite: realWidth, vhtml: escape(vhtml) }; $.post("../ajax/rest.aspx", data, function (jsonObj) { // finally reload ShowOverlay(); ReloadAuftragsmappe(false, false); $("#dialog_Editor").unbind("dialogbeforeclose"); }); } // update edior live function updateEditor(accTab, templateDiv) { // first remov visual border class in all elements for (i = 0; i < templateTable.size(); i++) { $('#dvMainTemplate #container #' + templateTable.keys()[i]).removeClass("DivVisualiszerActive"); } // now set class $('#dvMainTemplate #container #' + templateDiv).addClass("DivVisualiszerActive"); // set temp var t_currentAcc = accTab; $('#dvMainTemplate #container #' + templateDiv).html($(accTab).find('textarea').val()); //alert($(accTab).find('textarea').val()); // update hashtable templateTable.remove(templateDiv); templateTable.put(templateDiv, encodeURIComponent($(accTab).find('textarea').val().replace(/\+/g, 'THISISAPLUSSIGN'))); } var timer; function recognizeInputBreak() { if (timer) window.clearTimeout(timer); timer = window.setTimeout(function () { // reload img preview ReloadImgPreview(); }, 750); } function ReloadImgPreview() { $('#IMG_MainPreview').fadeOut(100, function() { $('#IMG_MainPreviewLoading').fadeIn(500); }); // save editor fields var insdata = ""; // save fields in datatable for (i = 0; i < templateTable.size(); i++) { insdata += templateTable.keys()[i] + "|" + escape(templateTable.get(templateTable.keys()[i])) + "¦"; } var data = { id: t_editorTitelID, action: "saveEditorField", VorlagenBreite: realWidth, insdata: insdata }; $.post("../ajax/rest.aspx", data, function (jsonObj) { if (jsonObj == "true") { // copy html to temp render (do not make changes in dvmaintemplate div!) and set to temp var $('#DV_HiddenEditor_TempRender').html($('#dvMainTemplate').html()); // hide divs with no content for (i = 0; i < templateTable.size(); i++) { // check now if it's empty div element if ($('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).html() == "") { // hide $('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).css("display", "none"); } } // set template html var to hidden ck editor (preventing special chars errors) var vhtml = $('#DV_HiddenEditor_TempRender').html(); // alert("asdf"); // alert(vhtml); $('#HiddenEditor').val(vhtml); // save html with timeout, the timeout is used for give browser time to encode hiddenditor datas correct setTimeout(function () { vhtml = $('#HiddenEditor').val(); // alert("nochmals"); // alert(vhtml); // replace the "+" sign, beacuse javascript doesn't escape this sign.. vhtml = vhtml.replace(/\+/g, 'THISISAPLUSSIGN'); var data = { fInseratTitelID: t_editorTitelID, action: "createVorlagenHTML", VorlagenBreite: realWidth, vhtml: escape(vhtml), createPreviewImage: true, height: $('#dvMainTemplate').height() }; $.post("../ajax/rest.aspx", data, function (restObj) { // now fade image in var date = new Date() var ticks = date.getTime() $("#IMG_MainPreview").attr("src","../temp/" + restObj.split('|')[1] + ".ashx?trim.threshold=80&ticks=" + ticks).bind('onreadystatechange load', function(){ if (this.complete) { $('#IMG_MainPreviewLoading').fadeOut(100); $(this).fadeIn(500); } }); }); }, 300); } else { // error! alert("Fehler beim Speichern / Laden. Der Text wurde nicht gespeichert. Bitte untenstehende Meldung an Support weiterleiten und anschliessend die Seite neu laden:\n\n" + jsonObj); } }); } function UpdateTextvorschlag(textvorschlag, ckeditorid, templateDiv) { if (textvorschlag != "") { // first destory current editor var currentEditorID = $(tt_accTab).find('textarea').attr('id'); CKEDITOR.instances[currentEditorID].destroy(true); // replace ' back for prevent syntax error textvorschlag = textvorschlag.replace(/###/g, "'") // now add value $(tt_accTab).find('textarea').val(decodeURIComponent(textvorschlag).replace(/THISISAPLUSSIGN/g, '+')); // and update template $('#dvMainTemplate #container #' + templateDiv).html(decodeURIComponent(textvorschlag).replace(/THISISAPLUSSIGN/g, '+')); // update hashtable templateTable.remove(templateDiv); templateTable.put(templateDiv, encodeURIComponent(decodeURIComponent(textvorschlag).replace(/THISISAPLUSSIGN/g, '+').replace(/\+/g, 'THISISAPLUSSIGN'))); // recreate ditor createEditor(tt_accTab); ReloadImgPreview(); } } // cropper functions function openImgCropper(divID, imgUrl, imgWidth, imgHeight) { t_templateDiv = divID; var openWin = "../imgCropper.aspx?width=" + Math.round(imgWidth) + "&height=" + Math.round(imgHeight) + "&imgUrl=" + imgUrl; CropperWin = window.open(openWin, 'CropperWin', 'width=500,height=600,resizable=no,scrollbars=yes') CropperWin.focus() } function _openImgCropper(imgUrl) { // update img in preview $('#dvMainTemplate #container #' + t_templateDiv + ' img').each(function (index) { $(this).attr('src', imgUrl); }); // update hashtable, use DV_HiddenImgUpload for temporary save $("#DV_HiddenImgUpload").html(decodeURIComponent(templateTable.get(t_templateDiv)).replace(/THISISAPLUSSIGN/g, '+')); // update src $('#DV_HiddenImgUpload img').each(function (index) { $(this).attr('src', imgUrl); }); templateTable.remove(t_templateDiv); templateTable.put(t_templateDiv, encodeURIComponent($("#DV_HiddenImgUpload").html().replace(/\+/g, 'THISISAPLUSSIGN'))); ReloadImgPreview(); } // delete image function DeleteImageInTemplate(divID) { t_templateDiv = divID; // update div and hashtable $('#dvMainTemplate #container #' + t_templateDiv).html(""); templateTable.remove(t_templateDiv); templateTable.put(t_templateDiv, ""); // now close editor and so reload auftragsmappe $("#dialog_Editor").dialog("close"); } // open sammelinserat editor function OpenSammelinseratEditor(institelid) { t_editorTitelID = institelid; ShowOverlay(); $.get("../ajax/json.aspx?action=GetEditorDatasSammelInserat&id=" + institelid, function (jsonObj) { jsonObj = CreateJSONObject(jsonObj); // get html $('#textareaSammelInserat').val(jsonObj.SammelHTML); $("#dialog_SammelEditor").dialog("option", "width", 1100); $("#dialog_SammelEditor").dialog("option", "height", 750); $("#dialog_SammelEditor").dialog("open"); HideOverlay(); }); } function CloseSammelEditor() { ShowOverlay(); setTimeout(function () { var vhtml = $('#textareaSammelInserat').val(); // replace the "+" sign, beacuse javascript doesn't escape this sign.. vhtml = vhtml.replace(/\+/g, 'THISISAPLUSSIGN'); var data = { fInseratTitelID: t_editorTitelID, action: "createVorlagenHTML", VorlagenBreite: 0, vhtml: escape(vhtml) }; $.post("../ajax/rest.aspx", data, function (jsonObj) { // relaod the auftragsmappe ReloadAuftragsmappe(false); $("#dialog_SammelEditor").dialog("close"); }); }, 500); } // bild vorschau frome ditor function ShowPDFImage() { // save editor fields var insdata = ""; // save fields in datatable for (i = 0; i < templateTable.size(); i++) { insdata += templateTable.keys()[i] + "|" + escape(templateTable.get(templateTable.keys()[i])) + "¦"; } var data = { id: t_editorTitelID, action: "saveEditorField", VorlagenBreite: realWidth, insdata: insdata }; $.post("../ajax/rest.aspx", data, function (jsonObj) { if (jsonObj == "true") { // copy html to temp render (do not make changes in dvmaintemplate div!) and set to temp var $('#DV_HiddenEditor_TempRender').html($('#dvMainTemplate').html()); // hide divs with no content for (i = 0; i < templateTable.size(); i++) { // check now if it's empty div element if ($('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).html() == "") { // hide $('#DV_HiddenEditor_TempRender #container #' + templateTable.keys()[i]).css("display", "none"); } } // set template html var to hidden ck editor (preventing special chars errors) var vhtml = $('#DV_HiddenEditor_TempRender').html(); $('#HiddenEditor').val(vhtml); // save html with timeout, the timeout is used for give browser time to encode hiddenditor datas correct setTimeout(function () { vhtml = $('#HiddenEditor').val(); // replace the "+" sign, beacuse javascript doesn't escape this sign.. vhtml = vhtml.replace(/\+/g, 'THISISAPLUSSIGN'); var data = { fInseratTitelID: t_editorTitelID, action: "createVorlagenHTML", VorlagenBreite: realWidth, vhtml: escape(vhtml), createPreviewImage: true, height: $('#dvMainTemplate').height() }; $.post("../ajax/rest.aspx", data, function (restObj) { // now call iframe image var date = new Date() var ticks = date.getTime() ShowImage("../temp/" + restObj.split('|')[1] + ".ashx?&trim.threshold=80&ticks=" + ticks); }); }, 300); } else { // error alert("Fehler beim Speichern / Laden. Der Text wurde nicht gespeichert. Bitte untenstehende Meldung an Support weiterleiten und anschliessend die Seite neu laden:\n\n" + jsonObj); } }); }