Try to use ResetIsDirty() before you make any changes in the editor. An example would be to use RestIsDirty() during the initial page load. Then try to test to see if isDirty() works correctly for you.
Thanks first. But I don't understand how this function work. My situation is : I have got a FCKeditor in a diary page.When I click on the calendar I replace the editor's content with the data saved in the server using ajax.And before this I want to judge if the editor have changed,so I can save the changed content to server. How should I do to make this work? Thanks a lot.
function createEditor() {
var oFCKeditor = null;
try {
oFCKeditor = FCKeditorAPI.GetInstance("editorTextArea");
} catch(e) {
}
if (!oFCKeditor) {
$("editorTextAreaCont").innerHTML = "";
oFCKeditor = new FCKeditor("editorTextArea", 570, 700);
oFCKeditor.BasePath = domain + "/FCKeditor/";
var sSkinPath = domain + "/FCKeditor/editor/skins/office2003/";
oFCKeditor.Config["SkinPath"] = sSkinPath;
oFCKeditor.Config["PreloadImages"] =
sSkinPath + "images/toolbar.start.gif" + ";" +
sSkinPath + "images/toolbar.end.gif" + ";" +
sSkinPath + "images/toolbar.bg.gif" + ";" +
sSkinPath + "images/toolbar.buttonarrow.gif";
oFCKeditor.ToolbarSet = "Custom";
oFCKeditor.Config["AutoDetectLanguage"] = false;
oFCKeditor.Config["DefaultLanguage"] = "zh-cn";
oFCKeditor.Config["FontNames"] = '宋体;新宋体;黑体;隶书;楷体;幼圆;Arial;Impact;Georgia;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana';
oFCKeditor.Config["FontSizes"] = '8px;10px;12px;14px;16px;18px;20px;24px;28px;32px;36px;56px';
oFCKeditor.Config["ImageBrowser"] = false;
oFCKeditor.Config["LinkBrowser"] = false;
oFCKeditor.Config["FlashBrowser"] = false;
oFCKeditor.Config["LinkUpload"] = false;
oFCKeditor.Config["ImageUpload"] = false;
oFCKeditor.Config["FlashUpload"] = false;
$("editorTextAreaCont").innerHTML = oFCKeditor.CreateHtml();
}
return oFCKeditor;
}
//use jsCalendar here a dateChanged event happend
function dateChanged(calendar) {
if (ifChange())
doSubmit();
if (calendar.dateClicked) {
// OK, a date was clicked
var y = calendar.date.getFullYear();
var m = calendar.date.getMonth(); // integer, 0..11
var d = calendar.date.getDate(); // integer, 1..31
//doSth...
//And then navigate Ext diary tree
navigateTree(y, m, d);
}
}
//Use Ext tree
function navigateTree(y, m, d) {
//first reset the editor
var oEditor ;
try {
oEditor = FCKeditorAPI.GetInstance("editorTextArea");
} catch(e) {
}
if (oEditor) {
oEditor.SetHTML("");
oEditor.ResetIsDirty();
}
//Find the date in the tree
var ynode = tree.getNodeById(y);
if (ynode) {
ynode.expand(false, true, function() {
var mnode = tree.getNodeById(y.toString() + (m + 1).toString());
if (mnode) {
mnode.expand(false, true, function() {
var dnode = tree.getNodeById(y.toString() + (m + 1).toString() + d.toString());
if (dnode) {
//Find it ,fire the click event on the node and that will call the getDiary function.
dnode.fireEvent("click", dnode, {saved:true});
}
});
}
});
}
}
function getDiary(node, options) {
if (node.isLeaf()) {
if (options && !options.saved) {
doSubmit();
}
var id = node.id;
//node.date store the date info
var date = node.date;
//show the date in the calender
cal.parseDate(date);
//retrive the diary from db with dwr
diary.getDiaryByDate(date, getDiaryReturn);
} else {
if (!node.isExpanded())
node.expand();
else node.collapse();
}
}
function getDiaryReturn(output) {
var result = output.parseJSON();
if (result.resultCode == 1) {
//doSth...
var oEditor = FCKeditorAPI.GetInstance("editorTextArea");
oEditor.SetHTML(result.additions.diary.content);
oEditor.ResetIsDirty();
} else if (result.resultCode == 0) {
//doSth...
var oEditor = FCKeditorAPI.GetInstance("editorTextArea");
oEditor.SetHTML("");
oEditor.ResetIsDirty();
} else {
alert("Error" + result.msg);
}
}
function ifChange() {
var oEditor = FCKeditorAPI.GetInstance("editorTextArea");
if ((oEditor.IsDirty()) {
return true;
}
return false;
}
This type of issue can be timeout related, and can occur when loading either large or content rich data into the editor.
Try the following code on the onload event of the offending markup. You may have to tweak it to get it working in your Implementation but the principle remains the same.
var editorInstanceName = '[your editor instance name]';
var resetCount = 0;
// reset changes to the editor area var resetEditorState = function () { if (editorInstanceName) { try { FCKeditorAPI.GetInstance(editorInstanceName).ResetIsDirty(); } catch (e) { resetCount++; if (resetCount < 5) { window.setTimeout('resetEditorState()',200); } else { // state is lost, abandon all hope and reload the window window.top.reload(); } } } }
Your permission denied error is more problematic. I'm guessing it is a low level javascript error. In which case it may (probably) be outside of FCKEditor's domain - insofar as you may be using problematic scripting such as showmodaldialog() (or whatever). In any event without being able to replicate it we would be just shooting in the dark and wasting your time.
Sorry vincentchan, havent been back here for a few days. What I mean by "outside of FCKEditor's domain" is simply that this type of error tends to occur from non-FCKEditor script impacting on the editor or non-FCKEditor script completely unrelated to the editor. By itself FCKEditor doesnt produce this kind of error. So, it could be a combination of things or something else entirely.
Be careful, this is why I said that without being able to replicate the error any suggestions will probably just waste your time. You could however try stripping all the editor script out of the page where the error occurs and see whether the permission denied error still occurs. If not then start stripping out pieces of your code with the editor intact until the error disappears. When you have pin-pointed the error location, going back to my earlier post, I suspect you will find that it is indeed a low level javascript error designed to trap potential browser security violations. There are usually non-invasive methods to get around this type of error, typically requiring a redesign of the methods that cause the permission denied errors.
Lastly, you might consider developing on Firefox so that you can use the Venkman JavaScript debugger. Its not a toy.
Don't know if this will help, but I found that if I paste a document from word with a colon in it, and save the content to a database and try to load the content, that will cause the problem. Try replacing all colons with : before saving.
Re: Why IsDirty() always return true
Try to use ResetIsDirty() before you make any changes in the editor.
An example would be to use RestIsDirty() during the initial page load. Then try to test to see if isDirty() works correctly for you.
-Drumsticks
Re: Why IsDirty() always return true
But I don't understand how this function work.
My situation is : I have got a FCKeditor in a diary page.When I click on the calendar I replace the editor's content with the data saved in the server using ajax.And before this I want to judge if the editor have changed,so I can save the changed content to server.
How should I do to make this work?
Thanks a lot.
Re: Why IsDirty() always return true
Another problem is the “permission denied” error.It happens frequently
Re: Why IsDirty() always return true
Re: Why IsDirty() always return true
Attachments:
Re: Why IsDirty() always return true
Re: Why IsDirty() always return true
Try the following code on the onload event of the offending markup. You may have to tweak it to get it working in your Implementation but the principle remains the same.
var editorInstanceName = '[your editor instance name]';
var resetCount = 0;
// reset changes to the editor area
var resetEditorState = function ()
{
if (editorInstanceName)
{
try
{
FCKeditorAPI.GetInstance(editorInstanceName).ResetIsDirty();
}
catch (e)
{
resetCount++;
if (resetCount < 5)
{
window.setTimeout('resetEditorState()',200);
} else {
// state is lost, abandon all hope and reload the window
window.top.reload();
}
}
}
}
Re: Why IsDirty() always return true
And could anybody give me some advice for the permission denied error
Re: Why IsDirty() always return true
Re: Why IsDirty() always return true
Re: Why IsDirty() always return true
Be careful, this is why I said that without being able to replicate the error any suggestions will probably just waste your time. You could however try stripping all the editor script out of the page where the error occurs and see whether the permission denied error still occurs. If not then start stripping out pieces of your code with the editor intact until the error disappears. When you have pin-pointed the error location, going back to my earlier post, I suspect you will find that it is indeed a low level javascript error designed to trap potential browser security violations. There are usually non-invasive methods to get around this type of error, typically requiring a redesign of the methods that cause the permission denied errors.
Lastly, you might consider developing on Firefox so that you can use the Venkman JavaScript debugger. Its not a toy.
Re: Why IsDirty() always return true