BUG-17427 HTML Editor available for multiple Textarea controls in Dynaforms

This commit is contained in:
Brayan Pereyra
2015-06-10 11:18:22 -04:00
parent 7b8f7b3792
commit 69abc612b4

View File

@@ -1,129 +1,136 @@
function DVEditor(where,body,oHiddenInput,height,mode) function DVEditor(where,body,oHiddenInput,height,mode,editorId)
{ {
var me=this; var me=this;
var hiddenInput=oHiddenInput; var hiddenInput=oHiddenInput;
var iframe=$dce("iframe"); var iframe=$dce("iframe");
//NOTE: className no funciona en FIREFOX //NOTE: className no funciona en FIREFOX
iframe.style.width="100%"; iframe.style.width="100%";
iframe.style.height=height; iframe.style.height=height;
iframe.style.margin="0px"; iframe.style.margin="0px";
iframe.style.padding="0px"; iframe.style.padding="0px";
iframe.style.border="none"; iframe.style.border="none";
where.appendChild(iframe); where.appendChild(iframe);
var head=document.childNodes[0].childNodes[0]; var head=document.childNodes[0].childNodes[0];
var header=''; var header='';
if (iframe.contentWindow) if (iframe.contentWindow) {
{ var doc = iframe.contentWindow.document;
var doc=iframe.contentWindow.document; } else {
} var doc = iframe.contentDocument;
else
{
var doc=iframe.contentDocument;
}
var _header=$dce("head");// head.cloneNode(true);
for(var i=0;i<head.childNodes.length;i++) {
try{
if ((head.childNodes[i].tagName==='LINK')&&
(head.childNodes[i].type="text/css"))
{
_header.appendChild(head.childNodes[i].cloneNode(true));
}
else
{
}
} }
catch(e) var _header = $dce("head");// head.cloneNode(true);
for (var i=0;i<head.childNodes.length;i++) {
try {
if ((head.childNodes[i].tagName==='LINK')&&
(head.childNodes[i].type="text/css")) {
_header.appendChild(head.childNodes[i].cloneNode(true));
}
} catch (e) {
}
}
header=_header.innerHTML;
//alert(header);
doc.open();
doc.write('<html><head>'+header+'</head><body style="height:100%;padding:0px;margin:0px;border:none;background-color:ThreeDHighlight;cursor:text;">'+body+'</body></html>');
doc.close();
doc.designMode="on";
if (mode=="edit") {
doc.contentEditable=true;
} else {
doc.contentEditable=false;
}
this.doc=doc;
me.insertHTML = function (html)
{ {
} var cmd = 'inserthtml';
} var bool = false;
header=_header.innerHTML; var value = html;
//alert(header); try {
doc.open(); doc.execCommand(cmd,bool,value);
doc.write('<html><head>'+header+'</head><body style="height:100%;padding:0px;margin:0px;border:none;background-color:ThreeDHighlight;cursor:text;">'+body+'</body></html>'); } catch (e) {
doc.close(); }
doc.designMode="on"; return false;
if(mode=="edit"){ };
doc.contentEditable=true;
}else{ me.command = function()
doc.contentEditable=false;
}
this.doc=doc;
me.insertHTML=function (html)
{
var cmd = 'inserthtml';
var bool = false;
var value = html;
try
{ {
doc.execCommand(cmd,bool,value); var cmd = this.getAttribute('name');
} catch (e) { var bool = false;
} var value = this.getAttribute('cmdValue') || null;
return false; if (value == 'promptUser') {
}; value = prompt(
me.command=function() (typeof(G_STRINGS[this.getAttribute('promptText')])!=='undefined')?
{ G_STRINGS[this.getAttribute('promptText')]:
var cmd = this.getAttribute('name'); this.getAttribute('promptText')
var bool = false; );
var value = this.getAttribute('cmdValue') || null; }
if (value == 'promptUser') try {
value = prompt( if (editorId) {
(typeof(G_STRINGS[this.getAttribute('promptText')])!=='undefined')? if (window.ActiveXObject && cmd == 'hilitecolor') {
G_STRINGS[this.getAttribute('promptText')]: doc.selection.createRange().pasteHTML('<span style ="background-color:' + value + '">' +doc.selection.createRange().text +'</span>');
this.getAttribute('promptText') } else {
); eval("window._editor" +editorId+".doc.execCommand(cmd,bool,value);");
try }
} else {
doc.execCommand(cmd,bool,value);
}
} catch (e) {
}
return false;
};
me.loadToolBar = function(uri)
{ {
doc.execCommand(cmd,bool,value); var tb=WebResource(uri);
} catch (e) { if(editorId){ // for multi-edhtmleditor
} tb.innerHTML = tb.innerHTML.replace(/DVEditorMap/g, "DVEditorMap" + editorId);
return false; }
} iframe.parentNode.insertBefore(tb,iframe);
me.loadToolBar=function(uri) me.setToolBar(tb);
{ };
var tb=WebResource(uri);
iframe.parentNode.insertBefore(tb,iframe); me.setToolBar = function(toolbar)
me.setToolBar(tb);
}
me.setToolBar=function(toolbar)
{
var buttons=toolbar.getElementsByTagName('area');
for(var b=0;b<buttons.length;b++)
{ {
buttons[b].onclick=me.command; var buttons=toolbar.getElementsByTagName('area');
} for (var b=0;b<buttons.length;b++) {
} buttons[b].onclick=me.command;
me.getHTML=function() }
{ };
var body='';
try { me.getHTML = function()
body=doc.getElementsByTagName('body')[0]; {
body=body.innerHTML; var body='';
} catch (e) { try {
} body=doc.getElementsByTagName('body')[0];
return body; body=body.innerHTML;
} } catch (e) {
me.setHTML=function(html) }
{ return body;
try { };
body=doc.getElementsByTagName('body')[0]; me.setHTML = function(html)
body.innerHTML=html; {
} catch (e) { try {
} body=doc.getElementsByTagName('body')[0];
return body; body.innerHTML=html;
} } catch (e) {
me.refreshHidden=function() }
{ return body;
if(hiddenInput) };
{
var html=me.getHTML(); me.refreshHidden = function()
var raiseOnChange=hiddenInput.value!==html; {
hiddenInput.value=html; if(hiddenInput)
if (raiseOnChange && hiddenInput.onchange) hiddenInput.onchange(); {
} var html=me.getHTML();
} var raiseOnChange=hiddenInput.value!==html;
me.syncHidden=function(name) hiddenInput.value=html;
{ if (raiseOnChange && hiddenInput.onchange) hiddenInput.onchange();
me.refreshHidden(); }
setTimeout(name+".syncHidden('"+name+"')",500); };
}
me.syncHidden = function(name)
{
me.refreshHidden();
setTimeout(name+".syncHidden('"+name+"')",500);
};
} }