This is a migrated thread and some comments may be shown as answers.

Prevous sibling node when i press enter on the H! tag data

1 Answer 17 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Neha
Top achievements
Rank 1
Neha asked on 16 Aug 2014, 09:52 AM
Hello ,

I have to find the previous sibling of the element when I press enter of the text .

 For example
<h1>Telerik editor Text</h1>

when i press enter in the H1 tag in between the this text "Telerik editor Text" then the editor we create two H1 tag either of adding br tag in between so for that I want the element before the cursor position.

For example : in between in this I have a cursor at this text "Telerik editor Text" at the "tele |"cursor position" so i want the "tele" element .
I have used the getselectionhtml but it return null value

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 20 Aug 2014, 12:42 PM
Hi,

You can set the RadEditor's NewLineMode property to"Br" to insert BR elements instead of adding new block elements.

If you need to add BR elements only in headings, you can change the NewLIneMode only for headings.  See the code below.
<telerik:RadEditor ID="RadEditor1" runat="server" NewLineMode="P"
    OnClientCommandExecuted="OnClientCommandExecuted"
    OnClientCommandExecuting="OnClientCommandExecuting">
    <Content>
        <h1>Some heading</h1>
        <p>some paragraph</p>
    </Content>
</telerik:RadEditor>
 
<script>
    function OnClientCommandExecuting(editor, args) {
        if (args.get_commandName() == "EnterNewLine") {
            var selectedElement = editor.getSelectedElement();
            if (Telerik.Web.UI.Editor.Utils.getElementParentByRegExpTagName(selectedElement, /^H[1-6]$/i)) {
                editor.set_newLineMode(Telerik.Web.UI.EditorNewLineModes.Br);
            }
        }
    }
 
    function OnClientCommandExecuted(editor, args) {
        if (args.get_commandName() == "EnterNewLine") {
            editor.set_newLineMode(Telerik.Web.UI.EditorNewLineModes.P);
        }
    }
</script>


Here is how you can get the previous element by handling OnClientCommandExecuted event.
<script>
    function OnClientCommandExecuted(editor, args) {
        if (args.get_commandName() == "EnterNewLine") {
            var selectedElement = editor.getSelectedElement();
            var selectedHeading = Telerik.Web.UI.Editor.Utils.getElementParentByRegExpTagName(selectedElement, /^H[1-6]$/i);
            if (selectedHeading) {
                var previous = $telerik.$(selectedHeading).prev().get(0);
            }
        }
    }
</script>

If this does not help, could you explain in more details what you are trying to achieve?

Regards,
Nikolay
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Editor
Asked by
Neha
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or