Hi everyone,
I am new here. I have been using this editor for quite some time and have made quite a few of my own additions, being an AJAX programmer myself. Recently, I have implemented a streaming uploader with PERL, that works quite well on all languages (no matter which one you are using for the editor itself), given you have PERL installed as well on your server.
My question is, as it is driving me mad, how do I find and replace what is pasted into the editor? In other words, say I copy and paste a document from MS Word, and I wanted to filter out all the swears automatically when I click CTRL+V or when I click the PASTE icon and have it automatically replace with $@&#). Don't need a word list, only the ability to do it by lines of code only. There is so much JavaScript code, that the onPaste handler is in quite a few locations and it is hard to tell where I can do this. I plan to use this for my uploader, for uploading images automatically onPaste opposed to using the image uploader.
Any ideas? Thanks for any help you can provide.
Kind regards,
Sean
I am new here. I have been using this editor for quite some time and have made quite a few of my own additions, being an AJAX programmer myself. Recently, I have implemented a streaming uploader with PERL, that works quite well on all languages (no matter which one you are using for the editor itself), given you have PERL installed as well on your server.
My question is, as it is driving me mad, how do I find and replace what is pasted into the editor? In other words, say I copy and paste a document from MS Word, and I wanted to filter out all the swears automatically when I click CTRL+V or when I click the PASTE icon and have it automatically replace with $@&#). Don't need a word list, only the ability to do it by lines of code only. There is so much JavaScript code, that the onPaste handler is in quite a few locations and it is hard to tell where I can do this. I plan to use this for my uploader, for uploading images automatically onPaste opposed to using the image uploader.
Any ideas? Thanks for any help you can provide.
Kind regards,
Sean
RE: onPaste Find and Replace... images!
The technique I have used is to replace the FCK paste command with my own function. In the example below, my function creates a DIV as a container for the pasted text, pastes in the clipboard contents, grabs the contents of the DIV and strips out all tags, then replaces the entire DIV with the processed text. The one downside is that midas sees this as two operations and so the undo buffer contains both original paste plus the replacement paste. This code was written specifically for FCK 2.3.2 and Firefox, and may need to be modified for IE.
//called during editor initialization
function FCKeditor_OnComplete(fckEditor) {
fckEditor.Commands.GetCommand('Paste').Execute = myPasteCommand;
}
function myPasteCommand () {
var fckEditor = FCKeditorAPI.GetInstance('myTextField');
var selection = fckEditor.EditorWindow.getSelection();
var range = selection.getRangeAt(0);
var charSelected = (selection.toString().length > 0) ? true : false;
if (charSelected) fckEditor.ExecuteNamedCommand('Cut');
//create container for paste contents, so we can find afterward
var div = fckEditor.EditorDocument.createElement("div");
div.setAttribute("style", "display:inline");
range.insertNode(div);
range.setEnd(div, 0);
range.setStart(div, 0);
fckEditor.ExecuteNamedCommand("Paste");
//get pasted text and remove all tags
var newText = div.innerHTML;
newText = newText.replace(/(<([^>]+)>)/ig,"");
//Select div node we created and replace with processed text
//The fckEditor.InsertHtml(newText) function causes problems for the midas undo
//feature so call midas insert html function directly
fckEditor.Selection.SelectNode(div);
fckEditor.EditorDocument.execCommand("inserthtml", false, newText);
}