Again through the API:
(Replace "FCKeditor" in the GetInstance method with the instanceName you picked for your editor)
// The selection object
FCKeditorAPI.GetInstance("FCKeditor").Selection
// properties
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType();
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetSelectedElement();
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement(); // Doesn't seem to be working in Fx when the selection is only one character
// methods
// select node, e.g. select the parent node
FCKeditorAPI.GetInstance("FCKeditor").Selection.SelectNode(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement());
// Move cursor position before (toStart = true, default) or after (toStart = false) the selection
FCKeditorAPI.GetInstance("FCKeditor").Selection.Collapse(toStart);
// Check if the selection has a specified ancestor node, returns true or false. The "nodeTagName" parameter must be Upper Case.
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.HasAncestorNode(nodeTagName));
// Move selection to ancestor node. The "nodeTagName" parameter must be Upper Case.
FCKeditorAPI.GetInstance("FCKeditor").Selection.MoveToAncestorNode(nodeTagName);
// Delete selection
FCKeditorAPI.GetInstance("FCKeditor").Selection.Delete();
// so to get the element that is selected, first check the type of the selection
// Doesn't seem to be working in Fx when the selection is only one character - This is due to some bug in the 'GetParentElement' method
if(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType() == 'Control')
{
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetSelectedElement());
}
else if(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType() == 'Text')
{
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement());
}
// Fetching the actual content of the selection can't be done through the 'Selection' Object...
if (document.all)
{
alert(FCKeditorAPI.GetInstance("FCKeditor").EditorDocument.selection.createRange().text);
}
else
{
alert(oSel = FCKeditorAPI.GetInstance("FCKeditor").EditorWindow.getSelection());
}
// To determining if something is selected in the editor, use the function of Alan Pinstein, see https://sourceforge.net/forum/message.p ... id=3531503
Mon, 10/30/2006 - 01:38
#1
RE: HOWTO - Work with the selection in the editor
FCKeditorAPI.GetInstance("FCKeditor").Selection ;
Could please tell me what it could be i have hooked up the function of Alan as well in editors FCKEditorAPI.js.
RE: HOWTO - Work with the selection in the ed
RE: HOWTO - Work with the selection in the ed
So what do u say??
alert(editorInstance.Selection);
alert(editorInstance.Selection.GetType());
alert(editorInstance.Selection.GetSelectedElement());
alert(editorInstance.Selection.GetParentElement());
alert(editorInstance.Selection.SelectNode(editorInstance.Selection.GetParentElement()));
alert(editorInstance.Selection.HasAncestorNode("MATH"));
RE: HOWTO - Work with the selection in the ed
RE: HOWTO - Work with the selection in the ed
Thanks,
Matt