I know I can get a reference to the editor DOM using FCKeditorAPI.GetInstance('body').EditorDocument
But how could I apply HTML formatting to selected text in the editor? Any pointer or tips would be much appreciated.
But how could I apply HTML formatting to selected text in the editor? Any pointer or tips would be much appreciated.
RE: How to apply HTML code to selected text?
I dunno if there's a special function that does all the job. One ugly way to do, is to get the selected text, (look the api there's a method that does it), something like :
text = FCKAPI.getSelection();
then, you can apply a style to the selection by placing it between two html tags like :
formatted_text = "<span style='my_style'>"+text+"</span>"
And then, replace this new text in the editor area with FCK.SetHTML( value );
value must contain text_before_selection + formatted_text + text_after_selection; That means when you select the text, you must have two markers, a start marker and an end marker to save in two buffers the text that is before the selection and the text that is after it.
Y.Chaouche
RE: How to apply HTML code to selected text?
Ok thanks Yacine however it didn't work - I guess it's my fault for not explaining myself properly. I'm trying to rewrite what's being dragged and drop in the editor.
For example, highlight a link anywhere on your page OUTSIDE the editor and drop it insie the editor. It works (in both browsers), but that 'drop' event doesn't get picked up by 'onPaste'. Does anyone know how to intercept those drag and drop operation and how to manipulate what is being dragged and dropped?
RE: How to apply HTML code to selected text?
I looked into the wiki page of fckeditor and i found a more nice way to do what i described in the earlier post :
ofckeditorInstance.InserHtml(). This way you don't have to save the text before and after the selection to do a append (before + text + after).
Sorry for your issue, i don't know if the fck api have this kind of method (drag'n'drop). Maybe it is supported directly by the borwser ???
Y.Chaouche