3 Answers, 1 is accepted
0
Hi,
Here is how you can modify the "EnterNewLine" command to prevent inserting formatting from the source element.
I have handled RadEditor's OnClientCommandExecuted event and for "EnterNewLine" command while the selection is in inline element without content, I am removing the parent element of the selected one.
Regards,
Nikolay
Telerik
Here is how you can modify the "EnterNewLine" command to prevent inserting formatting from the source element.
<telerik:RadEditor ID="radEditor1" runat="server" OnClientCommandExecuted="OnClientCommandExecuted"></telerik:RadEditor><script type="text/javascript"> function OnClientCommandExecuted(editor, args) { if (args.get_commandName() == "EnterNewLine") { var $Editor = Telerik.Web.UI.Editor; var range = $Editor.DomRange.toDomRange(editor.getSelection().getRange(true)); var commonAncestorContainer = range.commonAncestorContainer; if (isCursorPlaceHolder(commonAncestorContainer) && $Editor.Utils.isSingleChild(commonAncestorContainer)) { var node = commonAncestorContainer.parentNode; while ($Editor.Utils.isSingleChild(node) && !$Editor.Utils.isBlockElement(node)) { var current = node; node = node.parentNode; if (shouldRemoveNode(current)) { $Editor.Utils.removeNode(current); } } range.select(); } } } function isCursorPlaceHolder(element) { return element.nodeType == 3 && /^[\u200b]+$/.test(element.nodeValue); } function shouldRemoveNode(node) { //You can modify this function according to the scenario return node.nodeName == "SPAN" || node.nodeName == "FONT"; //return true; }</script>I have handled RadEditor's OnClientCommandExecuted event and for "EnterNewLine" command while the selection is in inline element without content, I am removing the parent element of the selected one.
Regards,
Nikolay
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Elena
Top achievements
Rank 1
answered on 07 Aug 2015, 10:37 AM
Hello,
Thank you for the reply. I tried to use the provided code.Unfortunately, I got the following error:
"Uncaught TypeError: Cannot read property 'toDomRange' of undefined"
on the line
var range = $Editor.DomRange.toDomRange(editor.getSelection().getRange(true));.
The Telerik version is 2012.2.607.35.
Can you help?
Best regards,
Elena
0
Elena
Top achievements
Rank 1
answered on 10 Aug 2015, 10:14 AM
Hello,
I have tested the code with the new Telerik version 2015.2.729.45. It works correctly.
Thank you for help.
Best regards,
Elena