function EditHtml (id)
{
var self = this;
var id = id;
var value = "";
var getSaveValue = false;
var setOldValue = true;
var setPath = 0;
var localImageWarning = false;
// var showImageWarning = true
var link, image;
this.onload = function ()
{
setTimeout (self.onresize, 0);
this.setValue (this.getValue ());
var editor = tinyMCE.get ("value["+id+"]").getBody ().parentNode;
if (editor) {
editor.addEventListener("click", function () {selectElement (id);}, false);
}
}
this.setValue = function (value)
{
if (settings[id]["encode_mailto"]) {
value = value.replace (/]*>[^<]*(\[|%5B)at(\]|%5D)[^<]*<\/a>/g, "$1@$4.$7");
value = value.replace (/]*>/g, "");
}
tinyMCE.get("value["+id+"]").setContent (value);
this.oldValue = this.getValue ();
}
this.getValue = function ()
{
var value = "";
if (getSaveValue) {
// langsam aber gefiltert
getSaveValue = false;
value = tinyMCE.get("value["+id+"]").getContent ();
if (settings[id]["encode_mailto"]) {
value = value.replace (/[^<]*@[^<]*<\/a>/g, "$1[at]$2[dot]$3");
value = value.replace (//g, "");
}
value = value.replace (//g, "");
} else {
// schnell aber ungefiltert
value = tinyMCE.get ("value["+id+"]").getBody ().innerHTML;
value = value.replace (/
1) {
path = path.replace (/tinymce/g, "if(parent.cms_content.tinyMCE)parent.cms_content.tinymce");
top.setStatus ("Path: "+path+"");
}
setPath++;
}
this.execCommand = function (editor_id, elm, command, user_interface, value) {
switch (command) {
case "mceLink":
var editor = tinyMCE.get (editor_id);
var linkElm = editor.selection.getNode ();
if (linkElm) {
link = {href : editor.dom.getAttrib (linkElm, "href").replace(new RegExp("^"+parent.location.pathname+"edit/"), ""), target : editor.dom.getAttrib (linkElm, "target")};
var group_id = link.href.replace (/.*[?&]cms_id=(\d+).*|.*./g, "$1");
window.open ("index.php?tpl=edit&name=link&parent_name="+id+"&group_id="+group_id, "cms_link", "width=100, height=50, left=0, top=0, status=no, toolbar=no, location=no, scrollbars=no, resizable=yes, dependent=yes");
}
return true;
case "mceImage":
var editor = tinyMCE.get (editor_id);
var imageElm = editor.selection.getNode ();
if (imageElm) {
var margin = editor.dom.getAttrib (imageElm, "style").indexOf ("relative") >= 0 ? 1 : 0;
image = {src : editor.dom.getAttrib (imageElm, "src"), border : editor.dom.getAttrib (imageElm, "border")*1, align : editor.dom.getAttrib (imageElm, "align"), margin : margin};
var group_id = image.src.replace (/.*[?&]cms_id=(\d+).*|.*/g, "$1");
if (group_id && (erg = self.getValue ().match (RegExp ("cms_id="+group_id, "g"))) && erg.length > 2) {
// das selbe Bild ist mehrmals im Text eingesetzt. Beim ändern soll ein neues erstellt werden
group_id = "";
}
window.open ("index.php?tpl=edit&name=image&parent_name="+id+"&group_id="+group_id, "cms_image", "width=100, height=50, left=0, top=0, status=no, toolbar=no, location=no, scrollbars=no, resizable=yes, dependent=yes");
}
return true;
case "mceInsertContent":
self.updateText ();
return false;
}
if (command!="mceRepaint") {
self.updateText ();
}
return false;
}
var updateLink = function (href, target)
{
var ed = tinyMCE.get ("value["+id+"]"), e, b;
e = ed.dom.getParent(ed.selection.getNode(), 'A');
// Remove element if there is no href
if (!href) {
if (e) {
ed.execCommand("mceBeginUndoLevel");
b = ed.selection.getBookmark();
ed.dom.remove(e, 1);
ed.selection.moveToBookmark(b);
ed.execCommand("mceEndUndoLevel");
return;
}
}
ed.execCommand("mceBeginUndoLevel");
// Create new link elements
if (e == null) {
ed.getDoc().execCommand("unlink", false, null);
ed.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
tinymce.each(ed.dom.select("a"), function(n) {
if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
e = n;
ed.dom.setAttribs(e, {
href : href,
title : "",
target : target ? target : null,
'class' : null
});
}
});
} else {
ed.dom.setAttribs(e, {
href : href,
title : "",
target : target ? target : null,
'class' : null
});
}
// Don't move caret if selection was image
if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
ed.focus();
ed.selection.select(e);
ed.selection.collapse(0);
}
ed.execCommand("mceEndUndoLevel");
}
var updateImage = function (src, border, width, height, align, margin)
{
var ed = tinyMCE.get ("value["+id+"]"), args = {}, el, style="";
if (margin) {
align = align ? align : (settings[id].image_align!="0" ? settings[id].image_align : "");
style = "position:relative;" + settings[id].image_margin.replace (new RegExp("^"+align+" *<(.*?)>.*|.*", "gm"), "$1");
}
if (settings[id].image_width && settings[id].image_width.match(/^\d+%?$/)) {
width = settings[id].image_width;
height = "";
}
if (settings[id].image_height && settings[id].image_height.match(/^\d+%?$/)) {
width = height ? width : "";
height = settings[id].image_height;
}
if (src === '') {
if (ed.selection.getNode().nodeName == 'IMG') {
ed.dom.remove(ed.selection.getNode());
ed.execCommand('mceRepaint');
}
return;
}
args = {
src : src,
alt : "",
width : width,
height : height,
border : border,
align : align,
style : style
}
el = ed.selection.getNode();
if (el && el.nodeName == 'IMG') {
ed.dom.setAttribs(el, args);
} else {
ed.execCommand('mceInsertContent', false, '
', {skip_undo : 1});
ed.dom.setAttribs('__mce_tmp', args);
ed.dom.setAttrib('__mce_tmp', 'id', '');
ed.undoManager.add();
}
}
}