Hello Everyone,
I'm in need of a little help here. I need to determine whenever the content of the FCK editor changes. I know about the AttachToOnSelectionChange but that only fires when the selection has changed and is not good for detecting content change.
Does anyone have any idea how I can go about doing this?
I'm in need of a little help here. I need to determine whenever the content of the FCK editor changes. I know about the AttachToOnSelectionChange but that only fires when the selection has changed and is not good for detecting content change.
Does anyone have any idea how I can go about doing this?
RE: Detecting changed content
I've had some success by adding event handlers to the EditorDocument ymmv.
// FCKeditor_OnComplete is a special function that is called when an editor
// instance is loaded and available to the API. It must be named exactly in
// this way.
var rteEditorLoaded = false;
var listenToEditor = true;
function FCKeditor_OnComplete(editorInstance){
if(editorInstance.Name == kArticleRTE){
rteEditorLoaded = true;
if(listenToEditor){
//Add event listener for document changes.
var edDoc = editorInstance.EditorDocument;
if(edDoc){
if (edDoc.addEventListener){
//DOM Level 2 Event Model
edDoc.addEventListener(
"keyup",
deferredChangedContent,
true);
edDoc.addEventListener(
"change",
deferredChangedContent,
true);
}else if (edDoc.attachEvent){
//IE 5+ Event Model
//In the IE event model, we can't capture events,
//so this handler is triggered only if the event
//bubbles up to it. This assumes that there
//aren't any intervening elements that handle
//the event and stop it from bubbling.
edDoc.attachEvent(
"onchange",
deferredChangedContent);
}
}
}
}
}
//Call the real changeContent() function in a timeout
//otherwise changeContent() seems to get executed
//in a wierd scope, specifically for me when I tried
//to use an XMLHttpRequest to load a relative URL
//the url wound up relative to the fckeditor page, not the
//window where the function was declared.
function deferredChangedContent(){
setTimeout("changedContent();", 5);
}
Note that this will NOT detect style changes (i.e. select some text and then click the Bold button), but from what I can tell the OnSelectionChange DOES fire in that case.
RE: Detecting changed content