Dear Fred,
He are a few bugs I encountered on IE6 and Firefox 1.0 on Win XP, and the solutions I brought to the code to (try to !) solve them.
Congrats again and again for your great piece of work.
---------------------------------
1/ When adding an input-hidden alone in the source code, it disappears:
--> in FCKXHtml._AppendNode
# if (FCKBrowserInfo.IsGecko&&htmlNode.hasAttribute('_moz_editor_bogus_node')) return;
lacks a return value
==> return 1; corrects the pb on Firefox
---------------------------------
2/ Focus does not work on source textarea on IE6:
--> FCK.Focus focus on 'eSource' instead of 'eSourceField'
==>
FCK.Focus=function()
{
try
{if (FCK.EditMode==FCK_EDITMODE_WYSIWYG) FCK.EditorDocument.body.focus();
// else document.getElementById('eSource').focus();
else document.getElementById('eSourceField').focus();
}catch(e) {};
};
---------------------------------
3/ Scripts and styles are lost when going back and forth from source to editor.
Moreover <script> are executed in editor.
--> innerHtml / EditorDocument.write(html) in FCK.SetHTML
do not keep <script> and <style> in certain case, notably where the source contains only one <script>
==> Here is my code:
FCK.SetHTML=function(html,forceWYSIWYG)
{
if (forceWYSIWYG||FCK.EditMode==FCK_EDITMODE_WYSIWYG)
{
this.EditorDocument.body.innerHTML='';
//if (html&&html.length>0) this.EditorDocument.write(html);
if (html&&html.length>0) // Eric Modif
this.EditorDocument.body.innerHTML = this._EricSaveStyleAndScripts( html );
}
else document.getElementById('eSourceField').value=html;
};
with
FCK.GetXHTML=function()
{var bSource=(FCK.EditMode==FCK_EDITMODE_SOURCE);
if (bSource) this.SwitchEditMode();
var sXHTML=FCKXHtml.GetXHTML(this.EditorDocument.body);
// === Eric's additions ===
sXHTML = this._EricCustomStoreStyleAndScripts + sXHTML;
// ======================
if (bSource) this.SwitchEditMode();
return sXHTML;
};
and
// ===== Eric HACK
FCK._EricCustomStoreStyleAndScripts = "";
FCK._EricSaveStyleAndScripts=function(text)
{
if (!text) return "";
if (text.length < 10) // <style></style> au min !
return text;
text=text.replace(/\<SCRIPT/g,"<script");
text=text.replace(/\<\/SCRIPT/g,"</script");
text=text.replace(/\<STYLE/g,"<style");
text=text.replace(/\<\/STYLE/g,"</style");
// Inits
this._EricCustomStoreStyleAndScripts = "";
var res=this._EricSaveStyleAndScripts_RemovePart(text, "<script", "</script>");
return this._EricSaveStyleAndScripts_RemovePart(res, "<style", "</style>");
};
// Internal method for previous code
FCK._EricSaveStyleAndScripts_RemovePart=function(text, partBegin, partEnd)
{
if (!text) return "";
if (text.length < partBegin.length+partEnd.length) // <style></style> au min !
return text;
var res="";
var idxof, idxof2;
// Remove parts
for (var pos=0; pos < text.length; pos = idxof2 + partEnd.length)
{
idxof = text.indexOf(partBegin, pos);
if (idxof < 0)
{ res += text.substring(pos,text.length); break; }
idxof2 = text.indexOf(partEnd, idxof + partBegin.length);
if (idxof2 < 0)
{ res += text.substring(pos,text.length); break; }
this._EricCustomStoreStyleAndScripts += text.substring(idxof,idxof2)+partEnd+"\n";
res += text.substring(pos,idxof);
}
return res;
}
// ===========
This solution allows to keep <style> and <script> intact and prevent the <script>
from being executed in the Editor's IFrame.
---------------------------------
4/ Before writing point-3 code, I noticed the <script> code got HTML-encoded for <, >, &,...
with caused the javascript to bug [note that you don't need this if you implement 3]
--> in FCKXHtml._AppendNode, the case "script" has to be changed into:
==>
case "script":
if (!oNode.attributes.getNamedItem('type'))
this._AppendAttribute(oNode,'type','text/javascript');
// oNode.appendChild( this.XML.createTextNode('\n'+htmlNode.text.trim()+'\n') );
oNode.appendChild(this.XML.createComment( this._HTMLEricUncomment( htmlNode.text.trim() ))); // Eric HACK
bProcessChild=false;
break;
with
// Eric HACK
FCKXHtml._HTMLEricUncomment=function(text)
{
if (!text) return "\n";
if (text.indexOf("<!--") < 0)
return "\n"+text+"\n";
text=text.replace(/\<\!\-\-/g,"");
text=text.replace(/\-\-\>/g,"");
return text;
};
---------------------------------
Please give me your comments and tell me if I'm right or if I missed something!
Take care,
--Eric
He are a few bugs I encountered on IE6 and Firefox 1.0 on Win XP, and the solutions I brought to the code to (try to !) solve them.
Congrats again and again for your great piece of work.
---------------------------------
1/ When adding an input-hidden alone in the source code, it disappears:
--> in FCKXHtml._AppendNode
# if (FCKBrowserInfo.IsGecko&&htmlNode.hasAttribute('_moz_editor_bogus_node')) return;
lacks a return value
==> return 1; corrects the pb on Firefox
---------------------------------
2/ Focus does not work on source textarea on IE6:
--> FCK.Focus focus on 'eSource' instead of 'eSourceField'
==>
FCK.Focus=function()
{
try
{if (FCK.EditMode==FCK_EDITMODE_WYSIWYG) FCK.EditorDocument.body.focus();
// else document.getElementById('eSource').focus();
else document.getElementById('eSourceField').focus();
}catch(e) {};
};
---------------------------------
3/ Scripts and styles are lost when going back and forth from source to editor.
Moreover <script> are executed in editor.
--> innerHtml / EditorDocument.write(html) in FCK.SetHTML
do not keep <script> and <style> in certain case, notably where the source contains only one <script>
==> Here is my code:
FCK.SetHTML=function(html,forceWYSIWYG)
{
if (forceWYSIWYG||FCK.EditMode==FCK_EDITMODE_WYSIWYG)
{
this.EditorDocument.body.innerHTML='';
//if (html&&html.length>0) this.EditorDocument.write(html);
if (html&&html.length>0) // Eric Modif
this.EditorDocument.body.innerHTML = this._EricSaveStyleAndScripts( html );
}
else document.getElementById('eSourceField').value=html;
};
with
FCK.GetXHTML=function()
{var bSource=(FCK.EditMode==FCK_EDITMODE_SOURCE);
if (bSource) this.SwitchEditMode();
var sXHTML=FCKXHtml.GetXHTML(this.EditorDocument.body);
// === Eric's additions ===
sXHTML = this._EricCustomStoreStyleAndScripts + sXHTML;
// ======================
if (bSource) this.SwitchEditMode();
return sXHTML;
};
and
// ===== Eric HACK
FCK._EricCustomStoreStyleAndScripts = "";
FCK._EricSaveStyleAndScripts=function(text)
{
if (!text) return "";
if (text.length < 10) // <style></style> au min !
return text;
text=text.replace(/\<SCRIPT/g,"<script");
text=text.replace(/\<\/SCRIPT/g,"</script");
text=text.replace(/\<STYLE/g,"<style");
text=text.replace(/\<\/STYLE/g,"</style");
// Inits
this._EricCustomStoreStyleAndScripts = "";
var res=this._EricSaveStyleAndScripts_RemovePart(text, "<script", "</script>");
return this._EricSaveStyleAndScripts_RemovePart(res, "<style", "</style>");
};
// Internal method for previous code
FCK._EricSaveStyleAndScripts_RemovePart=function(text, partBegin, partEnd)
{
if (!text) return "";
if (text.length < partBegin.length+partEnd.length) // <style></style> au min !
return text;
var res="";
var idxof, idxof2;
// Remove parts
for (var pos=0; pos < text.length; pos = idxof2 + partEnd.length)
{
idxof = text.indexOf(partBegin, pos);
if (idxof < 0)
{ res += text.substring(pos,text.length); break; }
idxof2 = text.indexOf(partEnd, idxof + partBegin.length);
if (idxof2 < 0)
{ res += text.substring(pos,text.length); break; }
this._EricCustomStoreStyleAndScripts += text.substring(idxof,idxof2)+partEnd+"\n";
res += text.substring(pos,idxof);
}
return res;
}
// ===========
This solution allows to keep <style> and <script> intact and prevent the <script>
from being executed in the Editor's IFrame.
---------------------------------
4/ Before writing point-3 code, I noticed the <script> code got HTML-encoded for <, >, &,...
with caused the javascript to bug [note that you don't need this if you implement 3]
--> in FCKXHtml._AppendNode, the case "script" has to be changed into:
==>
case "script":
if (!oNode.attributes.getNamedItem('type'))
this._AppendAttribute(oNode,'type','text/javascript');
// oNode.appendChild( this.XML.createTextNode('\n'+htmlNode.text.trim()+'\n') );
oNode.appendChild(this.XML.createComment( this._HTMLEricUncomment( htmlNode.text.trim() ))); // Eric HACK
bProcessChild=false;
break;
with
// Eric HACK
FCKXHtml._HTMLEricUncomment=function(text)
{
if (!text) return "\n";
if (text.indexOf("<!--") < 0)
return "\n"+text+"\n";
text=text.replace(/\<\!\-\-/g,"");
text=text.replace(/\-\-\>/g,"");
return text;
};
---------------------------------
Please give me your comments and tell me if I'm right or if I missed something!
Take care,
--Eric
RE: RC2 Bugs and correction proposals
Thanks a lot for your suggestions. Some things have already been corrected for version RC3 (to be published by the end of the month).
You "RemovePart" code is nice. I have something a little bit different in mind that will solve the problems with server side scripts (PHP, ASP, etc...) and custom tags. I think it will not be available on RC3 but I'll work on it.
In any case, SCRIPT and STYLE tags will be working ok on version RC3.
I'll take a closer look on your message and implement the missing things.
Thanks again,
FredCK
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn
RE: RC2 Bugs and correction proposals
Wow, that sounds great, we look forward to using it !!
--Eric