7 Answers, 1 is accepted
0
0
Hi Henrick,
You can get the current caret position by using browser-specific methods. In fact the editor can assist you nicely here, because you can use another of its cross-browser methods:
var range = editor.getSelection().getRange();
This range object is specific for each browser, and its API will differ greatly, so from this point on you will need to write browser-specific code.
You can also see the following articles which provide useful information about caret position, moving and locating the carer position:
Mouse Cursor Position
How to set/get caret position of a textfield in IE?
Working with the Cursor Position.
http://www.wrox.com/WileyCDA/Section/JavaScript-DOM-Ranges-Page-2.id-292302.html
http://www.quirksmode.org/dom/range_intro.html
http://msdn.microsoft.com/en-us/library/ms535872%28VS.85%29.aspx
To obtain a reference to the editor document use editor.get_document().
All the best,
Rumen
the Telerik team
You can get the current caret position by using browser-specific methods. In fact the editor can assist you nicely here, because you can use another of its cross-browser methods:
var range = editor.getSelection().getRange();
This range object is specific for each browser, and its API will differ greatly, so from this point on you will need to write browser-specific code.
You can also see the following articles which provide useful information about caret position, moving and locating the carer position:
Mouse Cursor Position
How to set/get caret position of a textfield in IE?
Working with the Cursor Position.
http://www.wrox.com/WileyCDA/Section/JavaScript-DOM-Ranges-Page-2.id-292302.html
http://www.quirksmode.org/dom/range_intro.html
http://msdn.microsoft.com/en-us/library/ms535872%28VS.85%29.aspx
To obtain a reference to the editor document use editor.get_document().
All the best,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Henrik
Top achievements
Rank 1
answered on 23 May 2011, 10:43 AM
Does the method "getSelection" also work if no selection is made?
0
Hi Henrik,
If the selection is empty then the getSelection method will return an empty selection.
Regards,
Rumen
the Telerik team
If the selection is empty then the getSelection method will return an empty selection.
Regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Henrik
Top achievements
Rank 1
answered on 25 May 2011, 11:26 AM
Yeah. I guess this is not what I want to have... I want to program the behavior like the align buttons. They work like this:
I also implented such functionality but it is not very comfortable. You have to double click the paragraph... I only want to get the cursor position in the content area maybe like this:
If this text is inside the content area:
"THIS IS SAMPLE TEXT"
and the cursor is behind the M then I want to start a method called getCursorPosition that returns in this case 11. But I guess this is not possible but essential.
- set the cursor in the paragraph
- click any align button
- the whole paragraph changes its align
- set the cursor in the paragraph
- click any line distance button (the method searches itself for the nearest <p> elements and sets a css class)
- the whole paragraph changes its line distance
I also implented such functionality but it is not very comfortable. You have to double click the paragraph... I only want to get the cursor position in the content area maybe like this:
If this text is inside the content area:
"THIS IS SAMPLE TEXT"
and the cursor is behind the M then I want to start a method called getCursorPosition that returns in this case 11. But I guess this is not possible but essential.
0
Henrik
Top achievements
Rank 1
answered on 17 Jun 2011, 10:15 AM
Any ideas?
0
Accepted
Hi Henrik,
You can check whether the cursor is placed inside a <p> tag using the
if (editor.getSelectedElement().tagName == "P")
{
}
and if it is to apply the desired CSS inline attribute to the selected P tag.
Note that the FixEnclosingP filter of RadEditor removes a parent paragraph tag if the whole content is inside it. This is because IE automatically wraps the empty content area in a <p> tag which misleads the validators that the editor is not empty. In such scenarios you should check whether the getSelectedElement() element is the <body> tag and if it is to create a <p> tag and put the body's content in it using the DOM methods.
Best regards,
Rumen
the Telerik team
You can check whether the cursor is placed inside a <p> tag using the
if (editor.getSelectedElement().tagName == "P")
{
}
and if it is to apply the desired CSS inline attribute to the selected P tag.
Note that the FixEnclosingP filter of RadEditor removes a parent paragraph tag if the whole content is inside it. This is because IE automatically wraps the empty content area in a <p> tag which misleads the validators that the editor is not empty. In such scenarios you should check whether the getSelectedElement() element is the <body> tag and if it is to create a <p> tag and put the body's content in it using the DOM methods.
Best regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.