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,4 +1,4 @@
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;
@@ -12,28 +12,19 @@ function DVEditor(where,body,oHiddenInput,height,mode)
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 _header = $dce("head");// head.cloneNode(true);
{ for (var i=0;i<head.childNodes.length;i++) {
var doc=iframe.contentDocument; try {
}
var _header=$dce("head");// head.cloneNode(true);
for(var i=0;i<head.childNodes.length;i++) {
try{
if ((head.childNodes[i].tagName==='LINK')&& if ((head.childNodes[i].tagName==='LINK')&&
(head.childNodes[i].type="text/css")) (head.childNodes[i].type="text/css")) {
{
_header.appendChild(head.childNodes[i].cloneNode(true)); _header.appendChild(head.childNodes[i].cloneNode(true));
} }
else } catch (e) {
{
}
}
catch(e)
{
} }
} }
header=_header.innerHTML; header=_header.innerHTML;
@@ -42,57 +33,71 @@ function DVEditor(where,body,oHiddenInput,height,mode)
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.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.close();
doc.designMode="on"; doc.designMode="on";
if(mode=="edit"){ if (mode=="edit") {
doc.contentEditable=true; doc.contentEditable=true;
}else{ } else {
doc.contentEditable=false; doc.contentEditable=false;
} }
this.doc=doc; this.doc=doc;
me.insertHTML=function (html)
me.insertHTML = function (html)
{ {
var cmd = 'inserthtml'; var cmd = 'inserthtml';
var bool = false; var bool = false;
var value = html; var value = html;
try try {
{
doc.execCommand(cmd,bool,value); doc.execCommand(cmd,bool,value);
} catch (e) { } catch (e) {
} }
return false; return false;
}; };
me.command=function()
me.command = function()
{ {
var cmd = this.getAttribute('name'); var cmd = this.getAttribute('name');
var bool = false; var bool = false;
var value = this.getAttribute('cmdValue') || null; var value = this.getAttribute('cmdValue') || null;
if (value == 'promptUser') if (value == 'promptUser') {
value = prompt( value = prompt(
(typeof(G_STRINGS[this.getAttribute('promptText')])!=='undefined')? (typeof(G_STRINGS[this.getAttribute('promptText')])!=='undefined')?
G_STRINGS[this.getAttribute('promptText')]: G_STRINGS[this.getAttribute('promptText')]:
this.getAttribute('promptText') this.getAttribute('promptText')
); );
try }
{ try {
if (editorId) {
if (window.ActiveXObject && cmd == 'hilitecolor') {
doc.selection.createRange().pasteHTML('<span style ="background-color:' + value + '">' +doc.selection.createRange().text +'</span>');
} else {
eval("window._editor" +editorId+".doc.execCommand(cmd,bool,value);");
}
} else {
doc.execCommand(cmd,bool,value); doc.execCommand(cmd,bool,value);
}
} catch (e) { } catch (e) {
} }
return false; return false;
} };
me.loadToolBar=function(uri)
me.loadToolBar = function(uri)
{ {
var tb=WebResource(uri); var tb=WebResource(uri);
if(editorId){ // for multi-edhtmleditor
tb.innerHTML = tb.innerHTML.replace(/DVEditorMap/g, "DVEditorMap" + editorId);
}
iframe.parentNode.insertBefore(tb,iframe); iframe.parentNode.insertBefore(tb,iframe);
me.setToolBar(tb); me.setToolBar(tb);
} };
me.setToolBar=function(toolbar)
me.setToolBar = function(toolbar)
{ {
var buttons=toolbar.getElementsByTagName('area'); var buttons=toolbar.getElementsByTagName('area');
for(var b=0;b<buttons.length;b++) for (var b=0;b<buttons.length;b++) {
{
buttons[b].onclick=me.command; buttons[b].onclick=me.command;
} }
} };
me.getHTML=function()
me.getHTML = function()
{ {
var body=''; var body='';
try { try {
@@ -101,8 +106,8 @@ function DVEditor(where,body,oHiddenInput,height,mode)
} catch (e) { } catch (e) {
} }
return body; return body;
} };
me.setHTML=function(html) me.setHTML = function(html)
{ {
try { try {
body=doc.getElementsByTagName('body')[0]; body=doc.getElementsByTagName('body')[0];
@@ -110,8 +115,9 @@ function DVEditor(where,body,oHiddenInput,height,mode)
} catch (e) { } catch (e) {
} }
return body; return body;
} };
me.refreshHidden=function()
me.refreshHidden = function()
{ {
if(hiddenInput) if(hiddenInput)
{ {
@@ -120,10 +126,11 @@ function DVEditor(where,body,oHiddenInput,height,mode)
hiddenInput.value=html; hiddenInput.value=html;
if (raiseOnChange && hiddenInput.onchange) hiddenInput.onchange(); if (raiseOnChange && hiddenInput.onchange) hiddenInput.onchange();
} }
} };
me.syncHidden=function(name)
me.syncHidden = function(name)
{ {
me.refreshHidden(); me.refreshHidden();
setTimeout(name+".syncHidden('"+name+"')",500); setTimeout(name+".syncHidden('"+name+"')",500);
} };
} }